示例#1
0
    def recommend(self,
                  recommendations,
                  minimum_rating,
                  include=AnonymousTraversal.__(),
                  recommender=Recommender.SMALL_SAMPLE):
        """A simple recommendation algorithm.

        Starts from a "user" and examines movies the user has seen filtered by the minimum_rating which removes
        movies that hold a rating lower than the value specified. It then samples the actors in the movies the
        user has seen and uses that to find other movies those actors have been in that the user has not yet
        seen. Those movies are grouped, counted and sorted based on that count to produce the recommendation.
        """

        if recommendations <= 0:
            raise ValueError('recommendations must be greater than zero')
        if not isinstance(recommender, Recommender):
            raise ValueError(
                'recommender argument must be of type Recommender')

        return (self.rated(minimum_rating, 0).aggregate("seen").local(
            recommender.traversal).unfold().in_(EDGE_ACTOR).where(
                P.without(
                    ["seen"])).where(include).groupCount().order(local).by(
                        values,
                        decr).limit(local,
                                    recommendations).select(keys).unfold())
示例#2
0
 def test_anonymous_traversal(self):
     bytecode = __.__(1).bytecode
     assert 0 == len(bytecode.bindings.keys())
     assert 0 == len(bytecode.source_instructions)
     assert 1 == len(bytecode.step_instructions)
     assert "inject" == bytecode.step_instructions[0][0]
     assert 1 == bytecode.step_instructions[0][1]
     ##
     bytecode = __.start().bytecode
     assert 0 == len(bytecode.bindings.keys())
     assert 0 == len(bytecode.source_instructions)
     assert 0 == len(bytecode.step_instructions)
示例#3
0
 def test_anonymous_traversal(self):
     bytecode = __.__(1).bytecode
     assert 0 == len(bytecode.bindings.keys())
     assert 0 == len(bytecode.source_instructions)
     assert 1 == len(bytecode.step_instructions)
     assert "inject" == bytecode.step_instructions[0][0]
     assert 1 == bytecode.step_instructions[0][1]
     ##
     bytecode = __.start().bytecode
     assert 0 == len(bytecode.bindings.keys())
     assert 0 == len(bytecode.source_instructions)
     assert 0 == len(bytecode.step_instructions)