Пример #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 entity_lang2response_block(cls, entity, lang):
        entity_type = FoxylibEntity.entity2type(entity)
        codename = FoxylibEntity.entity2value(entity)

        from henrique.main.skill.tradegood.tradegood_port.tradegood_port_response import TradegoodPortResponse
        from henrique.main.skill.tradegood.tradegood_tradegood.tradegood_tradegood_response import TradegoodTradegoodResponse
        from henrique.main.skill.tradegood.tradegood_culture.tradegood_culture_response import TradegoodCultureResponse

        h_type2func = {
            PortEntity.entity_type():
            partial(TradegoodPortResponse.codename_lang2text, lang=lang),
            TradegoodEntity.entity_type():
            partial(TradegoodTradegoodResponse.codename_lang2text, lang=lang),
            CultureEntity.entity_type():
            partial(TradegoodCultureResponse.codename_lang2text, lang=lang),
        }

        assert_equals(
            set(h_type2func.keys()),
            smap(lambda c: c.entity_type(), cls.target_entity_classes()))

        codename2response = h_type2func.get(entity_type)
        if not codename2response:
            raise NotImplementedError(
                "Invalid entity_type: {}".format(entity_type))

        text_out = codename2response(codename)
        return Rowsblock.text2norm(text_out)
Пример #3
0
    def test_05(self):
        entities_list = [
            [{
                'span': (7, 8),
                'text': '육',
                'value': 'Nutmeg',
                'type': TradegoodEntity.entity_type()
            }, {
                'span': (8, 9),
                'text': '메',
                'value': 'Mace',
                'type': TradegoodEntity.entity_type()
            }],
            [{
                'span': (16, 17),
                'text': '리스본',
                'value': 'Lisbon',
                'type': PortEntity.entity_type()
            }],
        ]
        hyp = PriceSkillClique.entities_list2clique(entities_list)
        ref = {'ports': ['Lisbon'], 'tradegoods': ['Nutmeg', 'Mace']}

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Пример #4
0
    def test_07(self):
        entity_list = [
            {
                'span': (7, 10),
                'text': '리스본',
                'value': 'Lisbon',
                'type': PortEntity.entity_type()
            },
            {
                'span': (11, 12),
                'text': '육',
                'value': 'Nutmeg',
                'type': TradegoodEntity.entity_type()
            },
            {
                'span': (12, 13),
                'text': '메',
                'value': 'Mace',
                'type': TradegoodEntity.entity_type()
            },
        ]
        hyp = PriceSkillClique.text_entity_list2clique_list(
            "?price 리스본 육메", entity_list)
        ref = [{'ports': ['Lisbon'], 'tradegoods': ['Nutmeg', 'Mace']}]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Пример #5
0
        def j2valid_trend(j):
            nonlocal entities_list

            if j < 3:
                return False

            j_tuple = j_param_types2j_latest(j, Param.Type.list())
            if any(map(is_none, j_tuple)):
                return False

            entities_tuple = [
                entities_list[j] if j is not None else None for j in j_tuple
            ]
            if any(map(lambda x: len(x) != 1, entities_tuple)):
                return False

            j_portlike, j_tradegood, j_rate, j_trend = j_tuple
            assert_equal(j_trend, j)
            if j_rate != j - 1:
                return False

            if j - 2 not in {j_portlike, j_tradegood}:
                return False

            entity_portlike, entity_tradegood, entity_rate, entity_trend = map(
                l_singleton2obj, entities_tuple)

            if FoxylibEntity.entity2type(
                    entity_portlike) != PortEntity.entity_type(
                    ):  # not culture
                return False

            entity_latter = max([entity_portlike, entity_tradegood],
                                key=FoxylibEntity.entity2span)

            span_latter, span_rate, span_trend = lmap(
                FoxylibEntity.entity2span,
                [entity_latter, entity_rate, entity_trend])

            span_latter_rate = SpanTool.span_pair2between(
                span_latter, span_rate)
            str_between_latter_rate = StringTool.str_span2substr(
                text, span_latter_rate)

            if not RegexTool.pattern_str2match_full(
                    RegexTool.pattern_blank_or_nullstr(),
                    str_between_latter_rate):
                return False

            span_rate_trend = SpanTool.span_pair2between(span_rate, span_trend)
            str_between_rate_trend = StringTool.str_span2substr(
                text, span_rate_trend)
            if not RegexTool.pattern_str2match_full(
                    RegexTool.pattern_blank_or_nullstr(),
                    str_between_rate_trend):
                return False

            return True
Пример #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 entity_portlike2port_codenames(cls, entity_portlike):
        entity_type = FoxylibEntity.entity2type(entity_portlike)
        if entity_type == PortEntity.entity_type():
            return [FoxylibEntity.entity2value(entity_portlike)]

        if entity_type == CultureEntity.entity_type():
            culture_codename = FoxylibEntity.entity2value(entity_portlike)
            port_list = Port.culture2ports(culture_codename)
            return lmap(Port.port2codename, port_list)

        raise RuntimeError({"entity_type": entity_type})
Пример #8
0
    def packet2skip_response(cls, packet):
        return False

        skill_code = HenriqueCommand.packet2skill_code(packet)

        if skill_code == HenriqueSkill.Codename.PRICE:
            return True

        text_in = KhalaPacket.packet2text(packet)
        config = HenriqueEntity.Config.packet2config(packet)

        if skill_code == HenriqueSkill.Codename.PORT:
            entity_list_port = PortEntity.text2entity_list(text_in, config=config)
            return bool(entity_list_port)

        if skill_code == HenriqueSkill.Codename.TRADEGOOD:
            entity_list_tradegood = TradegoodEntity.text2entity_list(text_in, config=config)
            return bool(entity_list_tradegood)

        return False
Пример #9
0
    def test_01(self):
        entities_list = [
            [{
                'span': (7, 10),
                'text': '리스본',
                'value': 'Lisbon',
                'type': PortEntity.entity_type()
            }],
            [{
                'span': (11, 14),
                'text': '육두구',
                'value': 'Nutmeg',
                'type': TradegoodEntity.entity_type()
            }],
        ]
        hyp = PriceSkillClique.entities_list2clique(entities_list)
        ref = {'ports': ['Lisbon'], 'tradegoods': ['Nutmeg']}

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Пример #10
0
    def test_03(self):
        entities_list = [
            [{
                'span': (7, 10),
                'text': '리스본',
                'value': 'Lisbon',
                'type': PortEntity.entity_type()
            }],
            [{
                'span': (11, 14),
                'text': '육두구',
                'value': 'Nutmeg',
                'type': TradegoodEntity.entity_type()
            }],
        ]
        hyp = PriceSkillClique.text_entities_list2indexes_list(
            "?price 리스본 육두구", entities_list)
        ref = [[0, 1]]

        pprint(hyp)
        self.assertEqual(hyp, ref)
Пример #11
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)
Пример #12
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)
Пример #13
0
    def entity2response_block(
        cls,
        packet,
        entity,
    ):
        chatroom = Chatroom.codename2chatroom(
            KhalaPacket.packet2chatroom(packet))
        locale = Chatroom.chatroom2locale(chatroom)
        lang = LocaleTool.locale2lang(locale)

        entity_type = FoxylibEntity.entity2type(entity)

        h_type2func = {
            PortEntity.entity_type():
            partial(PortSkill.entity_lang2response_block, lang=lang),
            TradegoodEntity.entity_type():
            partial(TradegoodSkill.entity_lang2response_block, lang=lang),
            CultureEntity.entity_type():
            partial(CultureSkill.entity_lang2response_block, lang=lang),
            ChatroomuserEntity.entity_type():
            partial(
                WhoSkill.entity2response_block,
                packet=packet,
            ),
        }

        assert_equals(
            set(h_type2func.keys()),
            smap(lambda c: c.entity_type(), cls.target_entity_classes()))

        entity2response = h_type2func.get(entity_type)
        if not entity2response:
            raise NotImplementedError(
                "Invalid entity_type: {}".format(entity_type))

        return entity2response(entity)
Пример #14
0
    def test_01(self):
        entity_list = PortEntity.text2entity_list(
            "?시세 초롱 : 말세80ㅎ; 사사리75ㅎ; 시라130ㅅ;")

        hyp = entity_list
        ref = [{
            'span': (9, 11),
            'text': '말세',
            'type': 'henrique.main.document.port.port_entity.PortEntity',
            'value': 'Marseilles'
        }, {
            'span': (16, 19),
            'text': '사사리',
            'type': 'henrique.main.document.port.port_entity.PortEntity',
            'value': 'Sassari'
        }, {
            'span': (24, 26),
            'text': '시라',
            'type': 'henrique.main.document.port.port_entity.PortEntity',
            'value': 'Syracuse'
        }]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Пример #15
0
 def entity_types(cls):
     return {PortEntity.entity_type(), CultureEntity.entity_type()}