def hiragana(ctx, app_id, sentence_file, json_flag, sentence, output_type, request_id): # type: (Context, unicode, Optional[IO], bool, unicode, unicode, unicode) -> None # NOQA """ Convert the Japanese to Hiragana or Katakana. """ app_id = clean_app_id(app_id) sentence = clean_sentence(sentence, sentence_file) api = GoolabsAPI(app_id) ret = api.hiragana(sentence=sentence, output_type=output_type, request_id=request_id) if json_flag: click.echo(format_json(api.response.json())) return click.echo(ret['converted'])
マッチした文字列の元であるkeyを返す ''' for key in adict.keys(): if re.search(key, text): return key def one_xlat(match): return adict[dedictkey(match.group(0))] return rx.sub(one_xlat, text) original_text = '大変だ!抽選10回もできるぞ!(基本5回、ツイートで5回)' # csvファイルから辞書データを作成 with open('dict.csv', 'r') as f: csvdata = csv.reader(f) data = [x for x in csvdata] datadic = dict(data) APPID = sys.argv[1] api = GoolabsAPI(APPID) req = api.hiragana(sentence=original_text, output_type='hiragana') after = multiple_replace(req['converted'], datadic) print('Before:\t' + original_text) print('After:\t' + after)