Пример #1
0
def personalize_text_for_narrator( explo, msg ):
    mygram = grammar.base_grammar( None, None, explo )
    for p in explo.camp.active_plots():
        pgram = p.get_dialogue_grammar( None, explo )
        if pgram:
            grammar.absorb( mygram, pgram )
    return grammar.convert_tokens( msg, mygram )
Пример #2
0
def personalize_text( in_text, speaker_voice, gramdb ):
    """Return text personalized for the provided context."""
    # Split the text into individual words.
    all_words = split_words_and_punctuation( grammar.convert_tokens( in_text, gramdb ) )
    out_text = []

    # Going through the words, check for conversions in the conversion table.
    for w in all_words:
        out_text.append( w )

        for t in range( 5, 0, -1 ):
            if len( out_text ) >= t:
                mykey = " ".join( out_text[-t:] )

                if mykey in personalizer.PT_DATABASE:
                    choices = []

                    for c in personalizer.PT_DATABASE[ mykey ]:
                        if c.fits_voice( speaker_voice ):
                            choices.append( c.subtext )

                    if choices and random.randint( 0, len( choices ) + 1 ) != 0:
                        myswap = random.choice( choices )

                        del out_text[-t:]
                        words_to_add = split_words_and_punctuation( myswap )
                        out_text += words_to_add

    out_text = preprocess_out_text( out_text )
    return " ".join( out_text )
Пример #3
0
def personalize_text_for_narrator( explo, msg ):
    mygram = grammar.base_grammar( None, None, explo )
    for p in explo.camp.active_plots():
        pgram = p.get_dialogue_grammar( None, explo )
        if pgram:
            grammar.absorb( mygram, pgram )
    return grammar.convert_tokens( msg, mygram )
Пример #4
0
def personalize_text( in_text, speaker_voice, gramdb ):
    """Return text personalized for the provided context."""
    # Split the text into individual words.
    all_words = split_words_and_punctuation( grammar.convert_tokens( in_text, gramdb ) )
    out_text = []

    # Going through the words, check for conversions in the conversion table.
    for w in all_words:
        out_text.append( w )

        for t in range( 5, 0, -1 ):
            if len( out_text ) >= t:
                mykey = " ".join( out_text[-t:] )

                if mykey in personalizer.PT_DATABASE:
                    choices = []

                    for c in personalizer.PT_DATABASE[ mykey ]:
                        if c.fits_voice( speaker_voice ):
                            choices.append( c.subtext )

                    if choices and random.randint( 0, len( choices ) + 1 ) != 0:
                        myswap = random.choice( choices )

                        del out_text[-t:]
                        words_to_add = split_words_and_punctuation( myswap )
                        out_text += words_to_add

    out_text = preprocess_out_text( out_text )
    return " ".join( out_text )
Пример #5
0
 def format_text( self, text, mygrammar, offer ):
     text = grammar.convert_tokens( text, mygrammar )
     if offer:
         text = text.format(**offer.data)
     return text
Пример #6
0
 def format_text(self, text, mygrammar, offer):
     text = grammar.convert_tokens(text, mygrammar)
     if offer:
         text = text.format(**offer.data)
     return text