Remove unused recommenders when recommending and allow keeping topLists

via args
This commit is contained in:
Dominik Moritz Roth 2021-09-06 16:17:54 +02:00
parent 255502cdd2
commit 60067ed263

View File

@ -265,8 +265,18 @@ def removeRestOfSeries(G):
if adjNode['series_index'] > seriesState + 1.0001:
G.remove_node(adj)
def removeUnusedRecommenders(G):
for n in list(G.nodes):
node = G.nodes[n]
if node['t'] == 'recommender':
for adj in G.adj[n]:
adjNode = G.nodes[adj]
if adjNode['t']=='book' and 'score' in adjNode:
break
else: # No unrated recommendation
G.remove_node(n)
def scoreOpinions(G, globMu, globStd, errorFac=0.7):
def scoreOpinions(G, globMu, globStd, errorFac=0.5):
for n in list(G.nodes):
node = G.nodes[n]
feedbacks = []
@ -498,7 +508,7 @@ def genScores(G, books):
return globMu, globStd
def recommendNBooks(G, mu, std, n):
def recommendNBooks(G, mu, std, n, removeTopListsB=True):
removeRestOfSeries(G)
removeBad(G, mu-std-1.5)
removeKeepBest(G, int(n*2) + 5, maxDistForRead=1.5)
@ -510,20 +520,23 @@ def recommendNBooks(G, mu, std, n):
pruneTags(G, 4.25)
pruneRecommenderCons(G, int(n/7)+1)
pruneAuthorCons(G, int(n/15))
if removeTopListsB:
removeTopLists(G)
removeDangling(G, alsoBooks=True)
removeKeepBest(G, n, maxDistForRead=0.75)
removeEdge(G)
removeDangling(G, alsoBooks=True)
removeUnusedRecommenders(G)
scaleBooksByRating(G)
scaleOpinionsByRating(G)
addScoreToLabels(G)
def fullGraph(G):
def fullGraph(G, removeTopLists=True):
removeEdge(G)
removeHighSpanTags(G, 7)
removeDangling(G, alsoBooks=False)
if removeTopLists:
removeTopLists(G)
pruneTags(G, 3)
removeDangling(G, alsoBooks=True)
@ -533,13 +546,14 @@ def fullGraph(G):
addScoreToLabels(G)
def readBooksAnalysis(G, minRating=0, showAllTags=True, removeUnconnected=False):
def readBooksAnalysis(G, minRating=0, showAllTags=True, removeUnconnected=False, removeTopListsB=True):
removeUnread(G)
removeBad(G, minRating)
if not showAllTags:
removeEdge(G)
removeHighSpanTags(G, 15)
removeDangling(G, alsoBooks=removeUnconnected)
if removeTopListsB:
removeTopLists(G)
pruneTags(G, 8)
@ -634,6 +648,7 @@ def cliInterface():
parser.add_argument('--no-web', action="store_true")
parser.add_argument('--no-list', action="store_true")
parser.add_argument('--remove-edge', action="store_true")
parser.add_argument('--keep-top-lists', action="store_true")
cmds = parser.add_subparsers(required=True, dest='cmd')
p_rec = cmds.add_parser('recommend', description="TODO", aliases=['rec'])
@ -663,13 +678,13 @@ def cliInterface():
removeUnread(G)
if args.cmd=="recommend":
recommendNBooks(G, mu, std, args.n)
recommendNBooks(G, mu, std, args.n, not args.keep_top_lists)
elif args.cmd=="read":
readBooksAnalysis(G, args.min_rating, args.all_tags, args.only_connected)
readBooksAnalysis(G, args.min_rating, args.all_tags, args.only_connected, not args.keep_top_lists)
elif args.cmd=="analyze":
analyze(G, args.type, args.name, args.d)
elif args.cmd=="full":
fullGraph(G)
fullGraph(G, not args.keep_top_lists)
else:
raise Exception("Bad")