Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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})
Esempio n. 5
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)
Esempio n. 6
0
 def entity_types(cls):
     return {PortEntity.entity_type(), CultureEntity.entity_type()}