Exemplo n.º 1
0
def generate(sentences=SENTENCES_DEFAULT):
    # print(repr(request.args['s']))
    sentences=int(sentences)

    chain = ScanResults()
    chain.add_files(CORPUS_GLOB)
    chain.train(n=TRAIN_N_DEFAULT, paragraphs=TRAIN_PARA_DEFAULT)
    if chain.errors:
        return render_template('error.html', errors=[repr(item) for item in chain.errors])

    return render_template('output.html', output=chain.sentences(n=sentences))
Exemplo n.º 2
0
from scanresults import ScanResults
import sys
from argparse import ArgumentParser

parser = ArgumentParser(description='Generate markov text from a corpus')
parser.add_argument('-t','--train', default=2, type=int, metavar='train_n',
                    help="The size of the Markov state prefix to train the corpus on")
parser.add_argument('-s','--sentences', default=25, type=int, metavar='sentences',
                    help="The number of sentences to print")
parser.add_argument('corpus_path', nargs="+",
                    help="Paths to corpus files to train on. Globs are permitted")
args = parser.parse_args()

sr = ScanResults()
sr.add_files(*args.corpus_path)

sr.train(args.train)
out = sr.sentences(args.sentences)
if out is not None:
    print(out)