Exemple #1
0
 def unmatched(self, model) -> NExpr:
     name = tokibi.alt(model.names[self.name]) if self.name in model.names else self.name
     value = self.params[0].match(model)
     if tokibi.OPTION['MultipleSentence']:
         return tokibi.NPhrase((name, 'は'), (value, 'に'), tokibi.NPred('する', 'VS'))
     else:
         return tokibi.NPhrase((name, 'を'), (value, 'に'), tokibi.NPred('する', 'VS', mode=verb.THEN))
Exemple #2
0
def emit(code, docs, buffers, options):
    for doc in docs:
        if doc.endswith('かどうか'):
            tokibi.randomize()
            cond = doc[:-4]
            buffers.append((cond + tokibi.alt('かどうか|か否か|か|か'), code))
            if cond.endswith('る') or cond.endswith('い') or cond.endswith('た'):
                doc = tokibi.choice(条件.apply({'X': doc[:-4]}).generate())
            else:
                doc = tokibi.choice(条件2.apply({'X': doc[:-4]}).generate())
            buffers.append((doc, f'if {code}:'))
        else:
            buffers.append((doc, code))
Exemple #3
0
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
Exemple #4
0
 def translate(self, expression, suffix='。'):
     tokibi.randomize()
     try:
         tree = snipet_parser(expression)
         # print(repr(tree))
         code = self.reader.visit(tree)
         # print(type(code), code)
         pred = code.match(self)
         if tokibi.OPTION['MultipleSentence']:
             buffer = []
             main = EOS(tokibi.emit(pred, 0, '', buffer))
             if len(buffer) > 0:
                 main += tokibi.alt('その際、|そこで、|') + (
                     suffix.join(buffer)) + suffix
             return code, main
         return code, EOS(tokibi.emit(pred))
     except InterruptedError:
         return expression, 'err'
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
def alt(s):
    tokibi.randomize()
    return tokibi.alt(s)