コード例 #1
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)
コード例 #2
0
    def test_04(self):
        config = {HenriqueEntity.Config.Field.LOCALE: "ko-KR"}
        hyp = TradegoodEntity.text2entity_list("육메클", config=config)

        ref = [
            {
                'span': (0, 1),
                'text': '육',
                'type': TradegoodEntity.entity_type(),
                'value': 'Nutmeg'
            },
            {
                'span': (1, 2),
                'text': '메',
                'type': TradegoodEntity.entity_type(),
                'value': 'Mace'
            },
            {
                'span': (2, 3),
                'text': '클',
                'type': TradegoodEntity.entity_type(),
                'value': 'Cloves'
            },
        ]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #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_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)
コード例 #5
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)
コード例 #6
0
    def test_02(self):
        entities_list = [
            [{
                'span': (6, 10),
                'text': '이베리아',
                'value': 'Iberia',
                'type': CultureEntity.entity_type()
            }],
            [{
                'span': (11, 14),
                'text': '육두구',
                'value': 'Nutmeg',
                'type': TradegoodEntity.entity_type()
            }],
        ]
        hyp = PriceSkillClique.entities_list2clique(entities_list)
        ref = {
            'ports': [
                'Las Palmas', 'Faro', 'Casablanca', 'Gijon', 'Palma',
                'Madeira', 'Vianna do Castelo', 'Lisbon', 'Sagres', 'Bilbao',
                'Seville', 'Barcelona', 'Porto', 'Malaga', 'Ceuta',
                'Montpellier', 'Valencia'
            ],
            'tradegoods': ['Nutmeg']
        }

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #7
0
    def test_06(self):
        entity_list = [{
            'span': (0, 1),
            'text': '육',
            'value': 'Nutmeg',
            'type': TradegoodEntity.entity_type()
        }, {
            'span': (1, 2),
            'text': '메',
            'value': 'Mace',
            'type': TradegoodEntity.entity_type()
        }]
        hyp = list(PriceSkillClique.entity_list2group_spans("육메", entity_list))
        ref = [(0, 2)]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #8
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)
コード例 #9
0
    def test_01(self):
        config = {HenriqueEntity.Config.Field.LOCALE: "ko-KR"}
        hyp = TradegoodEntity.text2entity_list("육두구 메이스 크로브", config=config)

        ref = [{
            'span': (0, 3),
            'text': '육두구',
            'type': TradegoodEntity.entity_type(),
            'value': 'Nutmeg'
        }, {
            'span': (4, 7),
            'text': '메이스',
            'type': TradegoodEntity.entity_type(),
            'value': 'Mace'
        }, {
            'span': (8, 11),
            'text': '크로브',
            'type': TradegoodEntity.entity_type(),
            'value': 'Cloves'
        }]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
コード例 #10
0
    def respond(cls, packet):
        from henrique.main.document.tradegood.subaction.tradegood_subactions import TradegoodTradegoodSubaction

        text = KhalaPacket.packet2text(packet)

        tradegood_entity_list = TradegoodEntity.text2entity_list(text)

        str_list = lmap(
            lambda p: TradegoodTradegoodSubaction.tradegood_entity2response(
                p, packet), tradegood_entity_list)

        str_out = "\n\n".join(str_list)

        return KhalaResponse.Builder.str2j_response(str_out)
コード例 #11
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
コード例 #12
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)
コード例 #13
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)
コード例 #14
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)
コード例 #15
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)
コード例 #16
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)