0
|
1 #!/usr/bin/env python
|
|
2
|
|
3 import sys
|
|
4
|
|
5 import urllib2
|
|
6
|
|
7 from optparse import OptionParser
|
|
8 from pprint import pprint
|
|
9 from wordstream.api import Corpus
|
|
10
|
|
11 def main(args=sys.argv[1:]):
|
5
|
12 parser = OptionParser('%prog [options] <path_or_url> <path_or_url> <...>')
|
0
|
13 parser.add_option('--print-corpus', dest='print_corpus', default=False,
|
5
|
14 action='store_true',
|
|
15 help="print the given corpus of associations")
|
0
|
16 parser.add_option('-n', type='int', dest='n', default=1,
|
5
|
17 help='number of words to eat per munch')
|
0
|
18 options, args = parser.parse_args()
|
|
19
|
|
20 corpus = Corpus()
|
|
21
|
|
22 corpus.feed_stuff(*args)
|
|
23 if options.print_corpus:
|
|
24 pprint(corpus)
|
5
|
25 sys.exit(0)
|
0
|
26
|
|
27 n = 1
|
|
28
|
|
29 while 1:
|
|
30 stream = raw_input()
|
|
31 splitstream = stream.split()
|
|
32 if splitstream:
|
|
33 for i in range(n):
|
|
34 word = corpus.eat(splitstream[-1])
|
|
35 if not word:
|
|
36 break
|
|
37 print word
|
|
38
|
|
39 if __name__ == '__main__':
|
|
40 main()
|