From 60067ed263183c303511f88c84111fe646db8bed Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Mon, 6 Sep 2021 16:17:54 +0200 Subject: [PATCH] Remove unused recommenders when recommending and allow keeping topLists via args --- caliGraph.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/caliGraph.py b/caliGraph.py index 4c3f036..df7ba65 100755 --- a/caliGraph.py +++ b/caliGraph.py @@ -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,21 +520,24 @@ def recommendNBooks(G, mu, std, n): pruneTags(G, 4.25) pruneRecommenderCons(G, int(n/7)+1) pruneAuthorCons(G, int(n/15)) - removeTopLists(G) + 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) - removeTopLists(G) + if removeTopLists: + removeTopLists(G) pruneTags(G, 3) removeDangling(G, alsoBooks=True) @@ -533,14 +546,15 @@ 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) - removeTopLists(G) + if removeTopListsB: + removeTopLists(G) pruneTags(G, 8) scaleBooksByRating(G) @@ -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")