fuse 2 fns
This commit is contained in:
parent
c660b696f9
commit
0d0bd9c597
|
@ -1,4 +1,5 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
"""
|
||||
mkv-this: input text, output markovified text.
|
||||
Copyright (C) 2020 mousebot@riseup.net.
|
||||
|
@ -89,45 +90,50 @@ def main():
|
|||
def mkbnewline(texttype):
|
||||
return markovify.NewlineText(texttype, state_size=args.state_size,
|
||||
well_formed=args.no_well_formed)
|
||||
|
||||
# this is terrible:
|
||||
def writesent(tmodel):
|
||||
return output.write(str(tmodel.make_sentence(
|
||||
|
||||
def writesentence(tmodel):
|
||||
for i in range(args.sentences):
|
||||
output = open(args.outfile, 'a') # append
|
||||
# short:
|
||||
if args.length:
|
||||
output.write(str(tmodel.make_short_sentence(
|
||||
tries=2000, max_overlap_ratio=args.overlap,
|
||||
max_chars=args.length)) + '\n\n')
|
||||
|
||||
def writeshortsent(tmodel):
|
||||
return output.write(str(tmodel.make_short_sentence(
|
||||
# normal:
|
||||
else:
|
||||
output.write(str(tmodel.make_sentence(
|
||||
tries=2000, max_overlap_ratio=args.overlap,
|
||||
max_chars=args.length)) + '\n\n')
|
||||
max_chars=args.length)) + '\n\n')
|
||||
output.write(str('*\n\n'))
|
||||
output.close()
|
||||
|
||||
fnf = 'error: file not found. please provide a path to a really-existing \
|
||||
file!'
|
||||
|
||||
# if a combine file is provided, we will combine it w infile/URL:
|
||||
# if a -c, combine it w infile/URL:
|
||||
if args.combine or args.combine_URL:
|
||||
if args.combine:
|
||||
# get raw text as a string for both files:
|
||||
# get raw text as a string for both:
|
||||
try:
|
||||
# infile can be a URL:
|
||||
# infile is URL:
|
||||
if args.URL:
|
||||
text = URL(args.infile)
|
||||
# or normal file:
|
||||
# or normal:
|
||||
else:
|
||||
text = read(args.infile)
|
||||
# read combine file:
|
||||
# read -c file:
|
||||
ctext = read(args.combine)
|
||||
except FileNotFoundError:
|
||||
print(fnf)
|
||||
sys.exit()
|
||||
|
||||
# if combine_URL is provided, we will combine it w infile/URL:
|
||||
# if -C, combine it w infile/URL:
|
||||
elif args.combine_URL:
|
||||
try:
|
||||
# infile can still be a URL:
|
||||
# infile is URL:
|
||||
if args.URL:
|
||||
text = URL(args.infile)
|
||||
# or normal file:
|
||||
# or normal:
|
||||
else:
|
||||
text = read(args.infile)
|
||||
except FileNotFoundError:
|
||||
|
@ -137,10 +143,11 @@ def main():
|
|||
ctext = URL(args.combine_URL)
|
||||
|
||||
# build the models and build a combined model:
|
||||
# with newline flagged:
|
||||
# with --newline:
|
||||
if args.newline:
|
||||
text_model = mkbnewline(text)
|
||||
ctext_model = mkbnewline(ctext)
|
||||
# no --newline:
|
||||
else:
|
||||
text_model = mkbtext(text)
|
||||
ctext_model = mkbtext(ctext)
|
||||
|
@ -148,26 +155,15 @@ def main():
|
|||
combo_model = markovify.combine(
|
||||
[text_model, ctext_model], [1, args.weight])
|
||||
|
||||
# Print -n number of randomly-generated sentences
|
||||
for i in range(args.sentences):
|
||||
output = open(args.outfile, 'a') # appending
|
||||
# short sentence:
|
||||
if args.length:
|
||||
writeshortsent(combo_model)
|
||||
# normal sentence:
|
||||
else:
|
||||
writesent(combo_model)
|
||||
output.write(str('*\n\n'))
|
||||
# add a star between each appended set.
|
||||
output.close()
|
||||
|
||||
# if no combine, just do normal:
|
||||
writesentence(combo_model)
|
||||
|
||||
# if no -c/-C, do normal:
|
||||
else:
|
||||
# Get raw text as string.
|
||||
# either from a URL:
|
||||
# either URL:
|
||||
if args.URL:
|
||||
text = URL(args.infile)
|
||||
# or local file:
|
||||
# or local:
|
||||
else:
|
||||
try:
|
||||
text = read(args.infile)
|
||||
|
@ -183,18 +179,7 @@ def main():
|
|||
else:
|
||||
text_model = mkbtext(text)
|
||||
|
||||
# Print -n number of randomly-generated sentences
|
||||
for i in range(args.sentences):
|
||||
output = open(args.outfile, 'a') # append to file
|
||||
# short sentence:
|
||||
if args.length:
|
||||
writeshortsent(text_model)
|
||||
# normal sentence:
|
||||
else:
|
||||
writesent(text_model)
|
||||
output.write(str('*\n\n'))
|
||||
# add a star between each appended set.
|
||||
output.close()
|
||||
writesentence(text_model)
|
||||
|
||||
print('\n: The options you used are as follows:\n')
|
||||
for key, value in vars(args).items():
|
||||
|
|
Loading…
Reference in New Issue