From 4fa3a57cc7a08b99b5089207d4ffd209c09283e9 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Wed, 8 Sep 2021 22:54:49 +0200 Subject: [PATCH] Remove 'useless' read books from recommendation-graph (far away from all unread books) --- caliGraph.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/caliGraph.py b/caliGraph.py index b95f08b..fbd39d3 100755 --- a/caliGraph.py +++ b/caliGraph.py @@ -276,6 +276,24 @@ def removeUnusedRecommenders(G): else: # No unrated recommendation G.remove_node(n) +def removeUselessReadBooks(G): + for n in list(G.nodes): + node = G.nodes[n] + if node['t'] == 'book': + for adj in G.adj[n]: + foundUnread = True + adjNode = G.nodes[adj] + for cousin in G.adj[adj]: + cousinNode = G.nodes[cousin] + if cousinNode['t']=='book' and 'score' in cousinNode: + break + else: # No unrated book here + foundUnread = False + if foundUnread: + break + else: # No unrated book in cousins + G.remove_node(n) + def scoreOpinions(G, globMu, globStd, errorFac=0.5): for n in list(G.nodes): node = G.nodes[n] @@ -517,6 +535,7 @@ def recommendNBooks(G, mu, std, n, removeTopListsB=True, removeUselessRecommende removeDangling(G, alsoBooks=False) pruneTags(G, 6) removeBad(G, mu, groups=['book']) + removeUselessReadBooks(G) pruneTags(G, 4.25) pruneRecommenderCons(G, int(n/7)+1) pruneAuthorCons(G, int(n/15))