def emit_ifandor(code, doc, results, pre=('または、', 'or')): vpos, base, prefix = detect_vpos(doc) mode = verb.否定形 if doc.endswith('ない') else 0 if vpos == 'NA' or random.random() < 0.5 : results.append((alt(pre[0]) + doc + alt('ならば|とき|場合'), f'{pre[1]} {code} :')) if vpos != 'NA' and random.random() < 0.5: doc2 = prefix + verb.emit_base(base, vpos, verb.仮定形|mode) + 'ば' results.append((alt(pre[0]) + doc2, f'{pre[1]} {code} :')) if vpos != 'NA' and random.random() < 0.5: doc2 = prefix + verb.emit_base(base, vpos, verb.過去形|mode) + alt('ならば|なら|ら|とき|場合') results.append((alt(pre[0]) + doc2, f'{pre[1]} {code} :'))
def emit_let_self(code, docs, results, options): name = code.split('.')[0] emit_let(code, docs, results, options, name) for doc in docs: mcode, doc = check_modified_code(code, doc) vpos, base, prefix = verb.detect_last_vpos(doc) if vpos.startswith('V'): #動詞 random_factor = tokibi.randomize() suffix = tokibi.alt('置き換える|再代入する') if random_factor < 0.5: suffix = verb.emit_base(base, vpos, verb.連用形)+'、' + suffix else: suffix = verb.emit_base(base, vpos, verb.接続形)+'、' + suffix results.append((prefix+suffix, f'{name} = {mcode}')) return False
def emit_dot(code, docs, results, options): if not tokibi.OPTION['--partial']: return False for doc in docs: mcode, doc = check_modified_code(code, doc) vpos, base, prefix = verb.detect_last_vpos(doc) random_factor = tokibi.randomize() if vpos.startswith('V'): #動詞 if random_factor < 0.5: suffix = verb.emit_base(base, vpos, verb.連用形)+'、' else: suffix = verb.emit_base(base, vpos, verb.接続形)+'、' else: suffix = base+f'の' results.append((prefix+suffix, f'{code}.')) return False
def emit_let(code, docs, results, options, name=None): # print('@@', options) if name == None: name = 'newname' if options[0] == '' else options[0] for doc in docs: mcode, doc = check_modified_code(code, doc) vpos, base, prefix = verb.detect_last_vpos(doc) random_factor = tokibi.randomize() suffix = name + tokibi.alt('とする@4|にする@2|に代入する') if vpos.startswith('V'): #動詞 if random_factor < 0.5: suffix = verb.emit_base(base, vpos, verb.連用形)+'、' + suffix else: suffix = verb.emit_base(base, vpos, verb.接続形)+'、' + suffix else: suffix = base+f'を'+suffix results.append((prefix+suffix, f'{name} = {mcode}')) return False
def emit_if(code, docs, results, options): for doc in docs: mcode, doc = check_modified_code(code, doc) doc = remove_whether(doc) vpos, base, prefix = detect_vpos(doc) mode = verb.否定形 if doc.endswith('ない') else 0 if vpos == 'NA' or random.random() < 0.5 : results.append((alt('もし|') + doc + alt('ならば|とき|場合'), f'if {mcode} :')) if vpos != 'NA' and random.random() < 0.7: doc2 = prefix + verb.emit_base(base, vpos, verb.仮定形|mode) + 'ば' results.append((alt('もし|') + doc2, f'if {mcode} :')) if vpos != 'NA' and random.random() < 0.7: doc2 = prefix + verb.emit_base(base, vpos, verb.過去形|mode) + alt('ならば|なら|ら|とき|場合') results.append((alt('もし|') + doc2, f'if {mcode} :')) if tokibi.OPTION['--partial']: emit_ifandor(mcode, doc, results) emit_ifandor(mcode, doc, results, pre=('かつ、', 'and')) if tokibi.OPTION['--partial']: emit_andor(code, docs, results, options) return False
def emit_inplace(code, docs, results, options): name = 'newname' for doc in docs: mcode, doc = check_modified_code(code, doc) vpos, base, prefix = verb.detect_last_vpos(doc) random_factor = tokibi.randomize() suffix = tokibi.alt('インプレースする|置き換える') if vpos.startswith('V'): #動詞 if random_factor < 0.5: suffix = verb.emit_base(base, vpos, verb.連用形)+'、' + suffix else: suffix = verb.emit_base(base, vpos, verb.接続形)+'、' + suffix if mcode[-2] == '(': # e.g.: df.dropna() mcode = mcode[:-1] + 'inplace=True)' else: # e.g.: df.drop('price', axis=1) mcode = mcode[:-1] + ', inplace=True)' results.append((prefix+suffix, mcode)) return False
def emit_not(code, docs, results, options): for doc in docs: mcode, doc = check_modified_code(code, doc) doc = remove_whether(doc) vpos, base, prefix = detect_vpos(doc) if vpos == 'NA': doc = doc + 'でない' else: mode = verb.過去形 if doc.endswith('た') else 0 doc = prefix + verb.emit_base(base, vpos, verb.否定形|mode) doc = doc.replace('既に', '未だ') results.append((doc + alt('か@6|かどうか@3|か否か'), transform_not(mcode))) return True
def emit_andor(code, docs, results, options): for doc in docs: mcode, doc = check_modified_code(code, doc) doc = remove_whether(doc) vpos, base, prefix = detect_vpos(doc) random_factor = random.random() if vpos == 'NA' or random_factor < 0.5 : pass else: mode = verb.否定形 if doc.endswith('ない') else 0 doc = prefix + verb.emit_base(base, vpos, verb.連用形|mode) results.append((doc+'、かつ、', f'{mcode} and')) results.append((doc+'、または、', f'{mcode} or')) return False