예제 #1
0
    def test_2(self, mock_get_app_config):
        patch_get_app_config(mock_get_app_config)
        items = {
            'strict': True,
            'cases': {
                'лосось': [
                    'хорошая рыба'
                ],
                'килька': [
                    'консервы'
                ]
            }
        }
        text_preprocessing_result = PicklableMock()
        text_preprocessing_result.tokenized_elements_list_pymorphy = [
            {'lemma': 'весь'},
            {'lemma': 'хороший'},
            {'lemma': 'и'},
            {'lemma': 'спасибо'},
            {'lemma': 'за'},
            {'lemma': 'рыба'},
        ]

        filler = IntersectionFieldFiller(items)
        result = filler.extract(text_preprocessing_result, None)

        self.assertIsNone(result)
예제 #2
0
    def test_5(self, mock_get_app_config):
        patch_get_app_config(mock_get_app_config)
        expected = 'дефолтный тунец'
        items = {
            'cases': {
                'лосось': [
                    'хорошая рыба'
                ],
                'килька': [
                    'консервы'
                ]
            },
            'default': 'дефолтный тунец'
        }
        text_preprocessing_result = PicklableMock()
        text_preprocessing_result.tokenized_elements_list_pymorphy = [
            {'lemma': 'мой'},
            {'lemma': 'дядя'},
            {'lemma': 'самый'},
            {'lemma': 'честный'},
            {'lemma': 'правило'},
        ]

        filler = IntersectionFieldFiller(items)
        result = filler.extract(text_preprocessing_result, None)

        self.assertEqual(expected, result)
    def test_1(self, mock_get_app_config):
        patch_get_app_config(mock_get_app_config)
        expected = 'лосось'
        items = {'cases': {'лосось': ['хорошая рыба'], 'килька': ['консервы']}}
        text_preprocessing_result = Mock()
        text_preprocessing_result.tokenized_elements_list = [
            {
                'lemma': 'весь'
            },
            {
                'lemma': 'хороший'
            },
            {
                'lemma': 'и'
            },
            {
                'lemma': 'спасибо'
            },
            {
                'lemma': 'за'
            },
            {
                'lemma': 'рыба'
            },
        ]

        filler = IntersectionFieldFiller(items)
        result = filler.extract(text_preprocessing_result, None)

        self.assertEqual(expected, result)
예제 #4
0
    def test_4(self, mock_get_app_config):
        patch_get_app_config(mock_get_app_config)
        items = {}
        text_preprocessing_result = PicklableMock()
        text_preprocessing_result.tokenized_elements_list_pymorphy = []

        filler = IntersectionFieldFiller(items)
        result = filler.extract(text_preprocessing_result, None)

        self.assertIsNone(result)
예제 #5
0
 def __init__(self,
              items: Dict[str, Any],
              id: Optional[str] = None) -> None:
     super().__init__(items, id)
     self.filler = IntersectionFieldFiller(
         {
             'cases': {
                 True: items.get('phrases', []),
             },
             'default': False,
         },
         id,
     )
예제 #6
0
class IntersectionRequirement(Requirement):
    phrases: Optional[List]

    def __init__(self,
                 items: Dict[str, Any],
                 id: Optional[str] = None) -> None:
        super().__init__(items, id)
        self.filler = IntersectionFieldFiller(
            {
                'cases': {
                    True: items.get('phrases', []),
                },
                'default': False,
            },
            id,
        )

    def check(self,
              text_preprocessing_result: TextPreprocessingResult,
              user: User,
              params: Dict[str, Any] = None) -> bool:
        result = bool(
            self.filler.extract(text_preprocessing_result, user, params), )
        return result