Exemplo n.º 1
0
 def test_real_string(self):
     splitted = split_ingredients(
         u'Обезжиренное молоко, наполнитель ягодный - малина со злаками (овес), цельное молоко, сухое обезжиренное молоко, с использованием йогуртовой закваски. '
     )
     self.assertEqual(splitted, [
         u'обезжиренное молоко',
         u'наполнитель ягодный - малина со злаками (овес)',
         u'цельное молоко', u'сухое обезжиренное молоко',
         u'с использованием йогуртовой закваски'
     ])
Exemplo n.º 2
0
 def process_item(self, good_item, spider):
     if 'ingredients' in good_item:
         ingredients_as_string = good_item['ingredients']
         ingredients_as_string = string_processor.remove_substring_in_paranthesis(
             ingredients_as_string)
         ingredients_fragments = string_processor.split_ingredients(ingredients_as_string)
         #log.msg("ingredients after splitting: {0}".format(ingredients_fragments))
         for fragment in ingredients_fragments:
             if not string_processor.parse_e_additives(fragment):
                 fragment = string_processor.remove_weight(fragment)
                 fragment = string_processor.remove_percents(fragment)
                 agrovoc_match = self.agrovoc_graph.find_ingredient_by_name(fragment.strip())
                 if agrovoc_match:
                     #log.msg('found ingredient {0}'.format(agrovoc_match))
                     good_item['agrovoc_ingredients'] = (
                         good_item.get('agrovoc_ingredients', []) + [agrovoc_match])
                 else:
                     self.not_parsed_fragments[fragment] = (
                         self.not_parsed_fragments.get(fragment, 0) + 1)
     return good_item
Exemplo n.º 3
0
 def process_item(self, good_item, spider):
     if 'ingredients' in good_item:
         ingredients_as_string = good_item['ingredients']
         ingredients_as_string = string_processor.remove_substring_in_paranthesis(
             ingredients_as_string)
         ingredients_fragments = string_processor.split_ingredients(
             ingredients_as_string)
         #log.msg("ingredients after splitting: {0}".format(ingredients_fragments))
         for fragment in ingredients_fragments:
             if not string_processor.parse_e_additives(fragment):
                 fragment = string_processor.remove_weight(fragment)
                 fragment = string_processor.remove_percents(fragment)
                 agrovoc_match = self.agrovoc_graph.find_ingredient_by_name(
                     fragment.strip())
                 if agrovoc_match:
                     #log.msg('found ingredient {0}'.format(agrovoc_match))
                     good_item['agrovoc_ingredients'] = (
                         good_item.get('agrovoc_ingredients', []) +
                         [agrovoc_match])
                 else:
                     self.not_parsed_fragments[fragment] = (
                         self.not_parsed_fragments.get(fragment, 0) + 1)
     return good_item
Exemplo n.º 4
0
 def test_two_comma_separated_elements_with_space(self):
     splitted = split_ingredients(u'сахар, мука')
     self.assertEqual(splitted, [u'сахар', u'мука'])
Exemplo n.º 5
0
 def test_one_element(self):
     splitted = split_ingredients(u'сахар')
     self.assertEqual(splitted, [u'сахар'])
Exemplo n.º 6
0
 def test_double_word_fragments(self):
     splitted = split_ingredients(u'пшеничная мука')
     self.assertEqual(splitted, [u'пшеничная мука'])
Exemplo n.º 7
0
 def test_tralinging_space(self):
     splitted = split_ingredients(u'соль, пшеничная мука ')
     self.assertEqual(splitted, [u'соль', u'пшеничная мука'])
Exemplo n.º 8
0
 def test_empty_string(self):
     splitted = split_ingredients(u'')
     self.assertEqual(splitted, [])
Exemplo n.º 9
0
 def test_splitted_by_dot(self):
     splitted = split_ingredients(u'Сахар. Мука')
     self.assertEqual(splitted, [u'сахар', u'мука'])
Exemplo n.º 10
0
 def test_two_comma_separated_elements_with_space(self):
     splitted = split_ingredients(u'сахар, мука')
     self.assertEqual(splitted, [u'сахар', u'мука'])
Exemplo n.º 11
0
 def test_lowercase(self):
     splitted = split_ingredients(u'Сахар, мука')
     self.assertEqual(splitted, [u'сахар', u'мука'])
Exemplo n.º 12
0
 def test_real_string(self):
     splitted = split_ingredients(u'Обезжиренное молоко, наполнитель ягодный - малина со злаками (овес), цельное молоко, сухое обезжиренное молоко, с использованием йогуртовой закваски. ')
     self.assertEqual(splitted, [u'обезжиренное молоко', u'наполнитель ягодный - малина со злаками (овес)', u'цельное молоко', u'сухое обезжиренное молоко', u'с использованием йогуртовой закваски'])
Exemplo n.º 13
0
 def test_one_element(self):
     splitted = split_ingredients(u'сахар')
     self.assertEqual(splitted, [u'сахар'])
Exemplo n.º 14
0
 def test_tralinging_space(self):
     splitted = split_ingredients(u'соль, пшеничная мука ')
     self.assertEqual(splitted, [u'соль', u'пшеничная мука'])
Exemplo n.º 15
0
 def test_double_word_fragments(self):
     splitted = split_ingredients(u'пшеничная мука')
     self.assertEqual(splitted, [u'пшеничная мука'])
Exemplo n.º 16
0
 def test_splitted_by_dot(self):
     splitted = split_ingredients(u'Сахар. Мука')
     self.assertEqual(splitted, [u'сахар', u'мука'])
Exemplo n.º 17
0
 def test_empty_string(self):
     splitted = split_ingredients(u'')
     self.assertEqual(splitted, [])
Exemplo n.º 18
0
 def test_lowercase(self):
     splitted = split_ingredients(u'Сахар, мука')
     self.assertEqual(splitted, [u'сахар', u'мука'])