Remove unused recommenders when recommending and allow keeping topLists
via args
This commit is contained in:
parent
255502cdd2
commit
60067ed263
29
caliGraph.py
29
caliGraph.py
@ -265,8 +265,18 @@ def removeRestOfSeries(G):
|
|||||||
if adjNode['series_index'] > seriesState + 1.0001:
|
if adjNode['series_index'] > seriesState + 1.0001:
|
||||||
G.remove_node(adj)
|
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):
|
for n in list(G.nodes):
|
||||||
node = G.nodes[n]
|
node = G.nodes[n]
|
||||||
feedbacks = []
|
feedbacks = []
|
||||||
@ -498,7 +508,7 @@ def genScores(G, books):
|
|||||||
return globMu, globStd
|
return globMu, globStd
|
||||||
|
|
||||||
|
|
||||||
def recommendNBooks(G, mu, std, n):
|
def recommendNBooks(G, mu, std, n, removeTopListsB=True):
|
||||||
removeRestOfSeries(G)
|
removeRestOfSeries(G)
|
||||||
removeBad(G, mu-std-1.5)
|
removeBad(G, mu-std-1.5)
|
||||||
removeKeepBest(G, int(n*2) + 5, maxDistForRead=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)
|
pruneTags(G, 4.25)
|
||||||
pruneRecommenderCons(G, int(n/7)+1)
|
pruneRecommenderCons(G, int(n/7)+1)
|
||||||
pruneAuthorCons(G, int(n/15))
|
pruneAuthorCons(G, int(n/15))
|
||||||
|
if removeTopListsB:
|
||||||
removeTopLists(G)
|
removeTopLists(G)
|
||||||
removeDangling(G, alsoBooks=True)
|
removeDangling(G, alsoBooks=True)
|
||||||
removeKeepBest(G, n, maxDistForRead=0.75)
|
removeKeepBest(G, n, maxDistForRead=0.75)
|
||||||
removeEdge(G)
|
removeEdge(G)
|
||||||
removeDangling(G, alsoBooks=True)
|
removeDangling(G, alsoBooks=True)
|
||||||
|
removeUnusedRecommenders(G)
|
||||||
|
|
||||||
scaleBooksByRating(G)
|
scaleBooksByRating(G)
|
||||||
scaleOpinionsByRating(G)
|
scaleOpinionsByRating(G)
|
||||||
addScoreToLabels(G)
|
addScoreToLabels(G)
|
||||||
|
|
||||||
def fullGraph(G):
|
def fullGraph(G, removeTopLists=True):
|
||||||
removeEdge(G)
|
removeEdge(G)
|
||||||
removeHighSpanTags(G, 7)
|
removeHighSpanTags(G, 7)
|
||||||
removeDangling(G, alsoBooks=False)
|
removeDangling(G, alsoBooks=False)
|
||||||
|
if removeTopLists:
|
||||||
removeTopLists(G)
|
removeTopLists(G)
|
||||||
pruneTags(G, 3)
|
pruneTags(G, 3)
|
||||||
removeDangling(G, alsoBooks=True)
|
removeDangling(G, alsoBooks=True)
|
||||||
@ -533,13 +546,14 @@ def fullGraph(G):
|
|||||||
addScoreToLabels(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)
|
removeUnread(G)
|
||||||
removeBad(G, minRating)
|
removeBad(G, minRating)
|
||||||
if not showAllTags:
|
if not showAllTags:
|
||||||
removeEdge(G)
|
removeEdge(G)
|
||||||
removeHighSpanTags(G, 15)
|
removeHighSpanTags(G, 15)
|
||||||
removeDangling(G, alsoBooks=removeUnconnected)
|
removeDangling(G, alsoBooks=removeUnconnected)
|
||||||
|
if removeTopListsB:
|
||||||
removeTopLists(G)
|
removeTopLists(G)
|
||||||
pruneTags(G, 8)
|
pruneTags(G, 8)
|
||||||
|
|
||||||
@ -634,6 +648,7 @@ def cliInterface():
|
|||||||
parser.add_argument('--no-web', action="store_true")
|
parser.add_argument('--no-web', action="store_true")
|
||||||
parser.add_argument('--no-list', action="store_true")
|
parser.add_argument('--no-list', action="store_true")
|
||||||
parser.add_argument('--remove-edge', 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')
|
cmds = parser.add_subparsers(required=True, dest='cmd')
|
||||||
|
|
||||||
p_rec = cmds.add_parser('recommend', description="TODO", aliases=['rec'])
|
p_rec = cmds.add_parser('recommend', description="TODO", aliases=['rec'])
|
||||||
@ -663,13 +678,13 @@ def cliInterface():
|
|||||||
removeUnread(G)
|
removeUnread(G)
|
||||||
|
|
||||||
if args.cmd=="recommend":
|
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":
|
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":
|
elif args.cmd=="analyze":
|
||||||
analyze(G, args.type, args.name, args.d)
|
analyze(G, args.type, args.name, args.d)
|
||||||
elif args.cmd=="full":
|
elif args.cmd=="full":
|
||||||
fullGraph(G)
|
fullGraph(G, not args.keep_top_lists)
|
||||||
else:
|
else:
|
||||||
raise Exception("Bad")
|
raise Exception("Bad")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user