Commit aacad0f4707feb108f28258489710d3b0060f6f2
1 parent
fb71f2a3
Exists in
master
and in
1 other branch
Fixed popcon_index bug. It is not instanciated unless the recommender strategy is set to 'col'.
Showing
1 changed file
with
6 additions
and
4 deletions
Show diff stats
src/recommender.py
| ... | ... | @@ -45,13 +45,15 @@ class RecommendationResult: |
| 45 | 45 | str += "%2d: %s\n" % (i,result[i][0]) |
| 46 | 46 | return str |
| 47 | 47 | |
| 48 | - def get_prediction(self,limit=20): | |
| 48 | + def get_prediction(self,limit=0): | |
| 49 | 49 | """ |
| 50 | 50 | Return prediction based on recommendation size (number of items). |
| 51 | 51 | """ |
| 52 | - if limit > self.size: limit = self.size | |
| 53 | 52 | sorted_result = sorted(self.item_score.items(), |
| 54 | 53 | key=operator.itemgetter(1)) |
| 54 | + if not limit or limit > self.size: | |
| 55 | + limit = self.size | |
| 56 | + | |
| 55 | 57 | return list(reversed(sorted_result[-limit:])) |
| 56 | 58 | |
| 57 | 59 | class Recommender: |
| ... | ... | @@ -63,13 +65,12 @@ class Recommender: |
| 63 | 65 | Set initial parameters. |
| 64 | 66 | """ |
| 65 | 67 | self.items_repository = xapian.Database(cfg.axi) |
| 66 | - self.users_repository = data.PopconXapianIndex(cfg) | |
| 67 | - #self.clustered_users_repository = data.PopconXapianIndex(cfg) | |
| 68 | 68 | self.set_strategy(cfg.strategy) |
| 69 | 69 | if cfg.weight == "bm25": |
| 70 | 70 | self.weight = xapian.BM25Weight() |
| 71 | 71 | else: |
| 72 | 72 | self.weight = xapian.TradWeight() |
| 73 | + self.cfg = cfg | |
| 73 | 74 | |
| 74 | 75 | def set_strategy(self,strategy_str): |
| 75 | 76 | """ |
| ... | ... | @@ -83,6 +84,7 @@ class Recommender: |
| 83 | 84 | self.strategy = strategy.ContentBasedStrategy("desc") |
| 84 | 85 | if strategy_str == "col": |
| 85 | 86 | self.strategy = strategy.CollaborativeStrategy(20) |
| 87 | + self.users_repository = data.PopconXapianIndex(self.cfg) | |
| 86 | 88 | |
| 87 | 89 | def get_recommendation(self,user,result_size=20): |
| 88 | 90 | """ | ... | ... |