def test_01(self): hyp = Rowsblock.text2norm(CultureTradegoodResponse.codename_lang2text("Tanegashima Rifle", "ko")) ref = """[문화권] 타네가시마 총 우대 문화권 - 이베리아, 서아시아, 터키, 아랍""" # pprint(hyp) self.assertEqual(hyp, ref)
def port2text(cls, port_codename, tradegood_codename_list, marketprice_dict, lang): n = len(tradegood_codename_list) port = Port.codename2port(port_codename) str_title = cls.port_lang2title(port, lang) def tradegood2price(tradegood_codename): price = MarketpriceDict.lookup(marketprice_dict, port_codename, tradegood_codename) if price: return price price_fake = MarketpriceDoc.price_tradegood2doc_fake( port_codename, tradegood_codename) return price_fake price_list = lmap(tradegood2price, tradegood_codename_list) i_list_sorted = sorted( range(n), key=lambda i: MarketpriceDoc.key_default(price_list[i])) rows_body = [ cls._price_lang2text(price_list[i], tradegood_codename_list[i], lang) for i in i_list_sorted ] return Rowsblock.rows2text(chain([str_title], rows_body))
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)
def test_01(self): hyp = Rowsblock.text2norm( CulturePortResponse.codename_lang2text("Lisbon", "ko")) ref = "[문화권] 리스본: 이베리아 문화권" # pprint(hyp) self.assertEqual(hyp, ref)
def test_01(self): hyp = Rowsblock.text2norm( CultureCultureResponse.codename_lang2text("Iberia", "ko")) ref = '[문화권] 이베리아' # pprint(hyp) self.assertEqual(hyp, ref)
def packet2response(cls, packet): chatroom = Chatroom.codename2chatroom( KhalaPacket.packet2chatroom(packet)) locale = Chatroom.chatroom2locale(chatroom) lang = LocaleTool.locale2lang(locale) text_in = KhalaPacket.packet2text(packet) config = {HenriqueEntity.Config.Field.LOCALE: locale} def entity2is_valid(entity): if FoxylibEntity.entity2value( entity) != HenriqueSkill.Codename.HELP: return True span = FoxylibEntity.entity2span(entity) if len(str2strip(text_in[:span[0]])) > 1: return True entity_list_skill = lfilter( entity2is_valid, SkillEntity.text2entity_list(text_in, config=config)) def entity_list2codename_list(entity_list): codename_list = luniq( map(SkillEntity.entity2skill_codename, entity_list)) if codename_list: return codename_list return [HenriqueSkill.Codename.HELP] codename_list = entity_list2codename_list(entity_list_skill) clazz_list = lmap(HenriqueSkill.codename2class, codename_list) blocks = [clazz.lang2description(lang) for clazz in clazz_list] return Rowsblock.blocks2text(blocks)
def tradegood2text(cls, tradegood_codename, port_codename_list, price_dict, lang): n = len(port_codename_list) tradegood = Tradegood.codename2tradegood(tradegood_codename) str_title = cls.tradegood_lang2title(tradegood, lang) def port2price(port_codename): price = MarketpriceDict.lookup(price_dict, port_codename, tradegood_codename) if price: return price price_fake = MarketpriceDoc.price_tradegood2doc_fake( port_codename, tradegood_codename) return price_fake price_list = lmap(port2price, port_codename_list) i_list_sorted = sorted( range(n), key=lambda i: MarketpriceDoc.key_default(price_list[i])) # price_list = sorted(price_list_raw, key=MarketpriceDoc.key_default) rows_body = [ cls._price_lang2text(price_list[i], port_codename_list[i], lang) for i in i_list_sorted ] return Rowsblock.rows2text(chain( [str_title], rows_body, ))
def test_01(self): hyp = Rowsblock.text2norm( TradegoodTradegoodResponse.codename_lang2text("Wheat", "ko")) ref = """[교역품] 밀 - 종류: [☆1] 식료품 - 판매항: 타코마, 샌프란시스코, 오데사, 잔지바르, 시라쿠사, 코친, 낭트, 케이프타운, 마사와, 세바스토폴, 앤트워프, 튀니스, 코토르, 시에라리온, 아조레스, 파마구스타, 사그레스, 트리폴리, 세비야, 알렉산드리아, 포르투, 카파, 제다, 브레멘, 뤼베크, 소팔라, 발렌시아, 라구사""" # pprint(hyp) self.assertEqual(hyp, ref)
def test_01(self): hyp = Rowsblock.text2norm( PortPortResponse.codename_lang2text("Lisbon", "ko")) ref = """[항구] 리스본 - 문화권: 이베리아 - 내성: 식료품, 가축, 조미료, 주류, 기호품, 광석, 무기류, 공예품, 총포류""" # pprint(hyp) self.assertEqual(hyp, ref)
def test_02(self): hyp = Rowsblock.text2norm( PortPortResponse.codename_lang2text("Seville", "ko")) ref = """[항구] 세비야 - 문화권: 이베리아 - 내성: 식료품, 의약품, 주류, 공업품, 공예품, 직물, 총포류 - 한줄평: 대항온 글섭의 수도!""" # pprint(hyp) self.assertEqual(hyp, ref)
def packet2response(cls, packet): chatroom = Chatroom.codename2chatroom(KhalaPacket.packet2chatroom(packet)) locale = Chatroom.chatroom2locale(chatroom) lang = LocaleTool.locale2lang(locale) entity_classes = cls.target_entity_classes() text_in = KhalaPacket.packet2text(packet) config = {HenriqueEntity.Config.Field.LOCALE: locale} entity_list = HenriqueEntity.text_classes2entity_list(text_in, entity_classes, config=config) blocks = [cls.entity_lang2response_block(entity, lang) for entity in entity_list] return Rowsblock.blocks2text(blocks)
def test_01(self): hyp = Rowsblock.text2norm(TradegoodPortResponse.codename_lang2text("Lisbon", "ko")) ref = """[교역품] 리스본 교역소 - 햄 - 아몬드유 - 닭 - 서양 서적 - 브랜디 - 동광석 - 아몬드 - 도자기 - 단검 - 포탄""" # pprint(hyp) self.assertEqual(hyp, ref)
def packet2response(cls, packet): chatroom = Chatroom.codename2chatroom( KhalaPacket.packet2chatroom(packet)) locale = Chatroom.chatroom2locale(chatroom) entity_classes = cls.target_entity_classes() text_in = KhalaPacket.packet2text(packet) config = {HenriqueEntity.Config.Field.LOCALE: locale} entity_list_raw = lchain(*[ c.text2entity_list(text_in, config=config) for c in entity_classes ]) entity_list = sorted(entity_list_raw, key=FoxylibEntity.entity2span) blocks = [ cls.entity2response_block(packet, entity) for entity in entity_list ] return Rowsblock.blocks2text(blocks)
def packet2response(cls, packet): logger = HenriqueLogger.func_level2logger(cls.packet2response, logging.DEBUG) logger.debug({"packet":packet}) chatroom = Chatroom.codename2chatroom(KhalaPacket.packet2chatroom(packet)) if Chatroom.chatroom2codename(chatroom) != ChatroomKakaotalk.codename(): return text_in = KhalaPacket.packet2text(packet) # config = {HenriqueEntity.Config.Field.LOCALE: locale} # config = {HenriqueEntity.Config.Field.LOCALE: locale} # entity_list_raw = lchain(*[c.text2entity_list(text_in, config=config) for c in entity_classes]) # entity_list_chatroomuser = sorted(ChatroomuserEntity.text2entity_list(text_in), key=FoxylibEntity.entity2span) blocks = [cls.entity2response_block(entity, packet,) for entity in entity_list_chatroomuser] return Rowsblock.blocks2text(blocks)
def test_01(self): hyp = Rowsblock.text2norm( TradegoodCultureResponse.codename_lang2text("Iberia", "ko")) ref = """[교역품] 이베리아 문화권 우대품 - 타네가시마 총 - 대만 목각 - 유자 - 일본서적 - 사마 은 - 스타아니스 - 호필 - 두반장 - 가는 끈 - 산초 - 진달래 - 진과스 금 - 청룡도 - 사슴 가죽 - 한지 - 자근 - 사다장""" # pprint(hyp) self.assertEqual(hyp, ref)
def codename_lang2text(cls, culture_codename, lang): filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) data = cls.codename_lang2json(culture_codename, lang) text_out = HenriqueJinja2.textfile2text(filepath, data) return Rowsblock.text2norm(text_out)
def packet2response(cls, packet): blocks = cls.packet2rowsblocks(packet) return Rowsblock.blocks2text(blocks)