clean up. realize your fns are hopeless
This commit is contained in:
parent
0cde15bd9c
commit
c660b696f9
|
@ -1,11 +1,4 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import os
|
||||
import requests
|
||||
import markovify
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
"""
|
||||
mkv-this: input text, output markovified text.
|
||||
Copyright (C) 2020 mousebot@riseup.net.
|
||||
|
@ -29,10 +22,16 @@ import argparse
|
|||
see --help for other options.
|
||||
"""
|
||||
|
||||
import os
|
||||
import requests
|
||||
import markovify
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
|
||||
def main():
|
||||
# argparse for cmd line args
|
||||
parser = argparse.ArgumentParser(prog="mkv-this", description="markovify a local or remote text file and output the results to local text file.",
|
||||
parser = argparse.ArgumentParser(prog="mkv-this", description="markovify one or two local or remote text files and output the results to a local text file.",
|
||||
epilog="may you find many prophetic énoncés in your virtual bird guts! Here, this is not at all the becomings that are connected... so if you want to edit it like a bot yourself, it is trivial.")
|
||||
|
||||
# positional args:
|
||||
|
@ -42,27 +41,27 @@ def main():
|
|||
help="the file to save to, with path. if the file is used more than once, subsequent literature will be appended to the file after a star. defaults to ./mkv-output.txt.")
|
||||
|
||||
# optional args:
|
||||
parser.add_argument('-s', '--state-size', help="the number of preceeding words used to calculate the probability of the next word. defaults to 2, 1 makes it more random, 3 less so. must be an integer. anything more than 4 will likely have little effect.", type=int, default=2)
|
||||
parser.add_argument('-s', '--state-size', help="the number of preceeding words used to calculate the probability of the next word. defaults to 2, 1 makes it more random, 3 less so. > 4 will likely have little effect.", type=int, default=2)
|
||||
parser.add_argument(
|
||||
'-u', '--URL', help="infile is a URL. NB: for this to work best it should be the location of a text file.", action='store_true')
|
||||
'-u', '--URL', help="infile is a URL. NB: for this to work it should be the location of a text file.", action='store_true')
|
||||
parser.add_argument(
|
||||
'-n', '--sentences', help="the number of 'sentences' to output. defaults to 5. must be an integer.", type=int, default=5)
|
||||
'-n', '--sentences', help="the number of 'sentences' to output. defaults to 5.", type=int, default=5)
|
||||
parser.add_argument(
|
||||
'-l', '--length', help="set maximum number of characters per sentence. must be an integer.", type=int)
|
||||
'-l', '--length', help="set maximum number of characters per sentence.", type=int)
|
||||
parser.add_argument(
|
||||
'-o', '--overlap', help="the amount of overlap allowed between original text and the output, expressed as a ratio between 0 and 1. defaults to 0.5", type=float, default=0.5)
|
||||
'-o', '--overlap', help="the amount of overlap allowed between original and output, expressed as a ratio between 0 and 1. defaults to 0.5", type=float, default=0.5)
|
||||
parser.add_argument(
|
||||
'-c', '--combine', help="provide an another input text file with path to be combined with the first item.")
|
||||
'-c', '--combine', help="provide an another text file to be combined with the first item.")
|
||||
parser.add_argument('-C', '--combine-URL',
|
||||
help="provide an additional URL to be combined with the first item")
|
||||
parser.add_argument('-w', '--weight', help="specify the weight to be given to the second text provided with --combine. defaults to 1, and the weight of the initial text is also 1. setting this to 1.5 will place 50 percent more weight on the second text, while setting it to 0.5 will place less.", type=float, default=1)
|
||||
parser.add_argument('-w', '--weight', help="specify the weight to be given to the text provided with -c or -C. defaults to 1, and the weight of the initial text is 1. 1.5 will place more weight on the second text, 0.5 will place less.", type=float, default=1)
|
||||
|
||||
# switches
|
||||
parser.add_argument('-f', '--no-well-formed', help="don't enforce 'well_formed', ie allow the inclusion of sentences with []{}()""'' in them in the markov model. this might filth up your text, especially if it contains 'smart' quotes.", action='store_false')
|
||||
parser.add_argument('-f', '--no-well-formed', help="don't enforce 'well_formed': allow the inclusion of sentences containing []{}()""'' in the markov model. might filth up your text, eg if it contains 'smart' quotes.", action='store_false')
|
||||
# store_false = default to True.
|
||||
parser.add_argument(
|
||||
'--newline', help="sentences in input file end with newlines \
|
||||
rather than with full stops.", action='store_true')
|
||||
rather than full stops.", action='store_true')
|
||||
# store_true = default to False, become True if flagged.
|
||||
|
||||
args = parser.parse_args()
|
||||
|
@ -88,9 +87,10 @@ def main():
|
|||
well_formed=args.no_well_formed)
|
||||
|
||||
def mkbnewline(texttype):
|
||||
return markovify.Text(texttype, state_size=args.state_size,
|
||||
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(
|
||||
tries=2000, max_overlap_ratio=args.overlap,
|
||||
|
@ -181,8 +181,8 @@ def main():
|
|||
text_model = mkbnewline(text)
|
||||
# no --newline:
|
||||
else:
|
||||
text_model = mkbtext(text)
|
||||
|
||||
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
|
||||
|
|
|
@ -63,7 +63,7 @@ def main():
|
|||
well_formed=args.no_well_formed)
|
||||
|
||||
def mkbnewline(texttype):
|
||||
return markovify.Text(texttype, state_size=args.state_size,
|
||||
return markovify.NewlineText(texttype, state_size=args.state_size,
|
||||
well_formed=args.no_well_formed)
|
||||
|
||||
def writesent(tmodel):
|
||||
|
|
Loading…
Reference in New Issue