2
|
1 #!/usr/bin/env python
|
|
2
|
|
3 import random
|
|
4 import sys
|
|
5
|
|
6 from optparse import OptionParser
|
|
7 from pprint import pprint
|
16
|
8 from .api import Corpus
|
|
9
|
2
|
10
|
3
|
11 def dissociate(corpus, output=sys.stdout):
|
|
12 while corpus:
|
21
|
13 word = random.choice(list(corpus.keys()))
|
3
|
14 inedible = True
|
|
15 while corpus.get(word):
|
|
16 inedible = False
|
21
|
17 print((output, word))
|
3
|
18 word = corpus.eat(word)
|
|
19 if inedible: # eat it anyway
|
|
20 corpus.eat(word)
|
16
|
21
|
3
|
22
|
|
23 def main(args=sys.argv[1:]):
|
5
|
24 parser = OptionParser('%prog <path_or_url> <path_or_url> <...>')
|
2
|
25 options, args = parser.parse_args()
|
|
26
|
|
27 corpus = Corpus()
|
5
|
28 if args:
|
|
29 corpus.feed_stuff(*args)
|
|
30 else:
|
|
31 corpus.feed_stream(sys.stdin.read())
|
2
|
32 corpus.scramble()
|
3
|
33 dissociate(corpus)
|
2
|
34
|
|
35 if __name__ == '__main__':
|
3
|
36 main()
|