Example #1
0
 def get_result_from_eset(self, eset):
     # compose result dictionary
     item_score = {}
     ranking = []
     for e in eset:
         package = e.term.lstrip("XP")
         item_score[package] = e.weight
         ranking.append(package)
     return recommender.RecommendationResult(item_score, ranking)
Example #2
0
    def run(self, rec, user, rec_size):
        terms_name, debtags_name = self.load_terms_and_debtags()

        pkgs, pkgs_score = self.get_pkgs_and_scores(rec, user)

        pkgs_classifications = self.get_pkgs_classifications(pkgs, terms_name,
                                                             debtags_name)

        item_score = self.get_item_score(pkgs_score, pkgs_classifications)
        result = recommender.RecommendationResult(item_score, limit=rec_size)

        return result
Example #3
0
 def run(self, rec, user, recommendation_size):
     """
     Perform recommendation strategy.
     """
     neighborhood = self.get_neighborhood(user, rec)
     weights = data.tfidf_plus(rec.users_repository, neighborhood,
                               PkgExpandDecider(user.items()))
     item_score = {}
     ranking = []
     for pkg in weights[:recommendation_size]:
         package = pkg[0].lstrip("XP")
         item_score[package] = pkg[1]
         ranking.append(package)
     result = recommender.RecommendationResult(item_score, ranking)
     return result
Example #4
0
    def get_sugestion_from_profile(self, rec, user, profile,
                                   recommendation_size):
        query = xapian.Query(xapian.Query.OP_OR, profile)
        enquire = xapian.Enquire(rec.items_repository)
        enquire.set_weighting_scheme(rec.weight)
        enquire.set_query(query)
        # Retrieve matching packages
        try:
            mset = enquire.get_mset(0, recommendation_size, None,
                                    PkgMatchDecider(user.installed_pkgs))
        except xapian.DatabaseError as error:
            logging.critical("Content-based strategy: " + error.get_msg())

        # Compose result dictionary
        item_score = {}
        ranking = []
        for m in mset:
            item_score[m.document.get_data()] = m.weight
            ranking.append(m.document.get_data())

        result = recommender.RecommendationResult(item_score, ranking)
        return result