예제 #1
0
    def test_12(self):
        text = "?price 리스본 사탕무 120 ㅅ"
        entity_list = [
            {
                'span': (7, 10),
                'text': '리스본',
                'value': 'Lisbon',
                'type': PortEntity.entity_type()
            },
            {
                'span': (11, 14),
                'text': '사탕무',
                'value': 'Sugar Beet',
                'type': TradegoodEntity.entity_type()
            },
            {
                'span': (15, 18),
                'text': '120',
                'value': 120,
                'type': RateEntity.entity_type()
            },
            {
                'span': (19, 20),
                'text': 'ㅅ',
                'value': "rise",
                'type': TrendEntity.entity_type()
            },
        ]
        hyp = PriceSkillClique.entity_list2entities_list_grouped(
            text, entity_list)
        ref = [
            [{
                'span': (7, 10),
                'text': '리스본',
                'value': 'Lisbon',
                'type': PortEntity.entity_type()
            }],
            [{
                'span': (11, 14),
                'text': '사탕무',
                'value': 'Sugar Beet',
                'type': TradegoodEntity.entity_type()
            }],
            [{
                'span': (15, 18),
                'text': '120',
                'value': 120,
                'type': RateEntity.entity_type()
            }],
            [{
                'span': (19, 20),
                'text': 'ㅅ',
                'value': "rise",
                'type': TrendEntity.entity_type()
            }],
        ]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
예제 #2
0
    def test_05(self):
        logger = HenriqueLogger.func_level2logger(self.test_03, logging.DEBUG)

        config = {HenriqueEntity.Config.Field.LOCALE: "en-US"}
        hyp = TrendEntity.text2entity_list("95 down", config=config)
        ref = [{
            'span': (3, 7),
            'text': 'down',
            'type': TrendEntity.entity_type(),
            'value': 'down'
        }]

        # pprint({"hyp":hyp})

        self.assertEqual(hyp, ref)
예제 #3
0
    def test_01(self):
        logger = HenriqueLogger.func_level2logger(self.test_01, logging.DEBUG)

        config = {HenriqueEntity.Config.Field.LOCALE: "ko-KR"}
        hyp = TrendEntity.text2entity_list("120ㅅ", config=config)
        ref = [{
            'span': (3, 4),
            'text': 'ㅅ',
            'type': TrendEntity.entity_type(),
            'value': 'rise'
        }]

        # pprint({"hyp":hyp})

        self.assertEqual(hyp, ref)
예제 #4
0
    def lang2pattern(cls, lang):
        from henrique.main.document.price.trend.trend_entity import TrendEntity
        logger = HenriqueLogger.func_level2logger(cls.lang2pattern,
                                                  logging.DEBUG)

        # rstr_suffix = format_str("{}?",
        #                          RegexTool.rstr2wrapped(TrendEntity.lang2rstr(lang)),
        #                          )

        ### may be concatenated with port/tradegood name
        # rstr_prefixed = RegexTool.rstr2rstr_words_prefixed(cls.rstr())
        # raise Exception({"rstr_suffix":rstr_suffix})

        rstr_trend = TrendEntity.lang2rstr(lang)

        # bound_right_list_raw = RegexTool.right_wordbounds()

        right_bounds = lchain(
            RegexTool.bounds2prefixed(RegexTool.right_wordbounds(),
                                      rstr_trend),
            RegexTool.right_wordbounds(),
        )
        rstr_rightbound = RegexTool.rstr2right_bounded(cls.rstr(),
                                                       right_bounds)

        logger.debug({#"rstr_trend":rstr_trend,
                      #"right_bounds":right_bounds,
                      "rstr_rightbound":rstr_rightbound,
                      })
        # rstr_suffixed = RegexTool.rstr2rstr_words_suffixed(cls.rstr(), rstr_suffix=rstr_suffix)

        # raise Exception({"rstr_trend": rstr_trend, "rstr_suffixed": rstr_suffixed})
        # return re.compile(RegexTool.rstr2wordbounded(cls.rstr()))
        return re.compile(rstr_rightbound, re.I)
예제 #5
0
    def test_06(self):
        logger = HenriqueLogger.func_level2logger(self.test_03, logging.DEBUG)

        config = {HenriqueEntity.Config.Field.LOCALE: "en-US"}
        hyp = TrendEntity.text2entity_list("95 하", config=config)
        ref = []

        # pprint({"hyp":hyp})

        self.assertEqual(hyp, ref)
예제 #6
0
        def entity_type2parameter_type(cls, entity_type):
            h = {
                PortEntity.entity_type(): cls.PORTLIKE,
                CultureEntity.entity_type(): cls.PORTLIKE,
                TradegoodEntity.entity_type(): cls.TRADEGOOD,
                RateEntity.entity_type(): cls.RATE,
                TrendEntity.entity_type(): cls.TREND,
            }

            return h.get(entity_type)
예제 #7
0
    def test_13(self):
        text = "?price 리스본 밀가루 120ㅅ"
        entity_list = [
            {
                'span': (7, 10),
                'text': '리스본',
                'value': 'Lisbon',
                'type': PortEntity.entity_type()
            },
            {
                'span': (11, 14),
                'text': '사탕무',
                'value': 'Sugar Beet',
                'type': TradegoodEntity.entity_type()
            },
            {
                'span': (15, 18),
                'text': '120',
                'value': 120,
                'type': RateEntity.entity_type()
            },
            {
                'span': (18, 19),
                'text': 'ㅅ',
                'value': "rise",
                'type': TrendEntity.entity_type()
            },
        ]
        hyp = PriceSkillClique.text_entity_list2clique_list(text, entity_list)
        ref = [{
            'ports': ['Lisbon'],
            'rate': 120,
            'tradegoods': ['Sugar Beet'],
            'trend': 'rise'
        }]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
예제 #8
0
    def test_11(self):
        entities_list = [
            [{
                'span': (7, 10),
                'text': '리스본',
                'value': 'Lisbon',
                'type': PortEntity.entity_type()
            }],
            [{
                'span': (11, 14),
                'text': '육두구',
                'value': 'Nutmeg',
                'type': TradegoodEntity.entity_type()
            }],
            [{
                'span': (15, 18),
                'text': '120',
                'value': 120,
                'type': RateEntity.entity_type()
            }],
            [{
                'span': (19, 20),
                'text': 'ㅅ',
                'value': "rise",
                'type': TrendEntity.entity_type()
            }],
        ]
        hyp = PriceSkillClique.entities_list2clique(entities_list)
        ref = {
            'ports': ['Lisbon'],
            'rate': 120,
            'tradegoods': ['Nutmeg'],
            'trend': 'rise'
        }

        # pprint(hyp)
        self.assertEqual(hyp, ref)