Exemplo n.º 1
0
 def test_occurence_index_user_to_item(self):
     #Not the best of names, but we attribute this to fields
     #which have no impact on the test.
     no_impact = 1
     
     a1 = data_parser.to_json(1, 1, no_impact, no_impact)
     a2 = data_parser.to_json(1, 2, no_impact, no_impact)
     a3 = data_parser.to_json(1, 1, no_impact, no_impact)
     a4 = data_parser.to_json(2, 2, no_impact, no_impact)
     a5 = data_parser.to_json(2, 3, no_impact, no_impact)
 
     index = create_occurrence_index([a1, a2, a3, a4, a5], 'user', 'item')
     self.assertEqual(index[1], set([1, 2, 1]))
     self.assertEqual(index[2], set([2, 3]))
Exemplo n.º 2
0
    def test_occurence_index_user_to_item(self):
        #Not the best of names, but we attribute this to fields
        #which have no impact on the test.
        no_impact = 1

        a1 = data_parser.to_json(1, 1, no_impact, no_impact)
        a2 = data_parser.to_json(1, 2, no_impact, no_impact)
        a3 = data_parser.to_json(1, 1, no_impact, no_impact)
        a4 = data_parser.to_json(2, 2, no_impact, no_impact)
        a5 = data_parser.to_json(2, 3, no_impact, no_impact)

        index = create_occurrence_index([a1, a2, a3, a4, a5], 'user', 'item')
        self.assertEqual(index[1], set([1, 2, 1]))
        self.assertEqual(index[2], set([2, 3]))
Exemplo n.º 3
0
 def _base_metrics(self, use_user):
     '''Creates and counts the popularity of random tags. The
     test will compare this with the result of the indices.'''
     
     #Generating some random annotations
     any_date = time.time()
     tag_pop = defaultdict(int)
     post_tag_pop = defaultdict(lambda: defaultdict(int))
     
     annotations = []
     for i in xrange(32):
         user = random.randint(0, 4)
         tag = random.randint(0, 4)
         item = random.randint(0, 4)
         annotations.append(data_parser.to_json(user, item, tag, any_date))
         
         post = user if use_user else item
         
         tag_pop[tag] += 1
         post_tag_pop[post][tag] += 1
     
     if use_user:
         index = create_metrics_index(annotations, 'user', 'tag')
     else:
         index = create_metrics_index(annotations, 'item', 'tag')
         
     self.assertEquals(post_tag_pop, index[0])
     self.assertEquals(tag_pop, index[2])
Exemplo n.º 4
0
    def _base_metrics(self, use_user):
        '''Creates and counts the popularity of random tags. The
        test will compare this with the result of the indices.'''

        #Generating some random annotations
        any_date = time.time()
        tag_pop = defaultdict(int)
        post_tag_pop = defaultdict(lambda: defaultdict(int))

        annotations = []
        for i in xrange(32):
            user = random.randint(0, 4)
            tag = random.randint(0, 4)
            item = random.randint(0, 4)
            annotations.append(data_parser.to_json(user, item, tag, any_date))

            post = user if use_user else item

            tag_pop[tag] += 1
            post_tag_pop[post][tag] += 1

        if use_user:
            index = create_metrics_index(annotations, 'user', 'tag')
        else:
            index = create_metrics_index(annotations, 'item', 'tag')

        self.assertEquals(post_tag_pop, index[0])
        self.assertEquals(tag_pop, index[2])
Exemplo n.º 5
0
 def test_double_occurrence_index(self):
     no_impact = 1
     
     a1 = data_parser.to_json(1, no_impact, 1, no_impact)
     a2 = data_parser.to_json(1, no_impact, 2, no_impact)
     a3 = data_parser.to_json(1, no_impact, 1, no_impact)
     a4 = data_parser.to_json(2, no_impact, 2, no_impact)
     a5 = data_parser.to_json(2, no_impact, 3, no_impact)
 
     from_to, inv = create_double_occurrence_index([a1, a2, a3, a4, a5], 
                                                   'user', 'tag')
     self.assertEqual(from_to[1], set([1, 2, 1]))
     self.assertEqual(from_to[2], set([2, 3]))
     
     self.assertEqual(inv[1], set([1]))
     self.assertEqual(inv[2], set([1, 2]))
     self.assertEqual(inv[3], set([2]))
Exemplo n.º 6
0
    def test_double_occurrence_index(self):
        no_impact = 1

        a1 = data_parser.to_json(1, no_impact, 1, no_impact)
        a2 = data_parser.to_json(1, no_impact, 2, no_impact)
        a3 = data_parser.to_json(1, no_impact, 1, no_impact)
        a4 = data_parser.to_json(2, no_impact, 2, no_impact)
        a5 = data_parser.to_json(2, no_impact, 3, no_impact)

        from_to, inv = create_double_occurrence_index([a1, a2, a3, a4, a5],
                                                      'user', 'tag')
        self.assertEqual(from_to[1], set([1, 2, 1]))
        self.assertEqual(from_to[2], set([2, 3]))

        self.assertEqual(inv[1], set([1]))
        self.assertEqual(inv[2], set([1, 2]))
        self.assertEqual(inv[3], set([2]))