Added pruning of connections from authors above theshold and tweaked

some params
This commit is contained in:
Dominik Moritz Roth 2021-06-15 14:23:49 +02:00
parent ad38e3e2a2
commit 612d8f2967

27
main.py
View File

@ -195,6 +195,30 @@ def pruneRecommenderCons(G, maxCons=5):
if foundCon < 2: if foundCon < 2:
G.remove_node(m) G.remove_node(m)
def pruneAuthorCons(G, maxCons=3):
for n in list(G.nodes):
node = G.nodes[n]
if node['t'] == 'author':
if len(G.adj[n]) > maxCons:
bestlist = []
for m in list(G.adj[n]):
book = G.nodes[m]
if book['t'] == 'book':
if 'score' in book and book['score'] != None:
bestlist.append(book)
bestlist.sort(key=lambda node: node['score'], reverse=True)
bestlist = bestlist[:maxCons]
for m in list(G.adj[n]):
book = G.nodes[m]
if book['t'] == 'book' and book not in bestlist or 'score' in book and book['score'] == None:
if not 'rating' in book or book['rating'] == None:
foundCon = 0
for con in G.adj[m]:
if G.nodes[con]['t'] not in ['topList']:
foundCon += 1
if foundCon < 2:
G.remove_node(m)
def removeHighSpanTags(G, maxCons=5): def removeHighSpanTags(G, maxCons=5):
for n in list(G.nodes): for n in list(G.nodes):
@ -465,7 +489,8 @@ def recommendNBooks(n):
pruneTags(G, 4) pruneTags(G, 4)
removeBad(G, mu, groups=['book']) removeBad(G, mu, groups=['book'])
pruneTags(G, 3) pruneTags(G, 3)
pruneRecommenderCons(G, 5) pruneRecommenderCons(G, int(n/7)+1)
pruneAuthorCons(G, int(n/15))
removeTopLists(G) removeTopLists(G)
removeDangling(G, alsoBooks=True) removeDangling(G, alsoBooks=True)
removeKeepBest(G, n, maxDistForRead=0.75) removeKeepBest(G, n, maxDistForRead=0.75)