Mercurial > hg > wordstream
view wordstream/dissociate.py @ 21:c05704d14958 default tip
py3
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 02 Feb 2022 16:15:36 +0000 |
parents | 50b319ad87b8 |
children |
line wrap: on
line source
#!/usr/bin/env python import random import sys from optparse import OptionParser from pprint import pprint from .api import Corpus def dissociate(corpus, output=sys.stdout): while corpus: word = random.choice(list(corpus.keys())) inedible = True while corpus.get(word): inedible = False print((output, word)) word = corpus.eat(word) if inedible: # eat it anyway corpus.eat(word) def main(args=sys.argv[1:]): parser = OptionParser('%prog <path_or_url> <path_or_url> <...>') options, args = parser.parse_args() corpus = Corpus() if args: corpus.feed_stuff(*args) else: corpus.feed_stream(sys.stdin.read()) corpus.scramble() dissociate(corpus) if __name__ == '__main__': main()