MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / test

Function test

tools/python-3.11.9-amd64/Tools/demo/markov.py:39–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37
38
39def test():
40 import sys, random, getopt
41 args = sys.argv[1:]
42 try:
43 opts, args = getopt.getopt(args, '0123456789cdwq')
44 except getopt.error:
45 print('Usage: %s [-#] [-cddqw] [file] ...' % sys.argv[0])
46 print('Options:')
47 print('-#: 1-digit history size (default 2)')
48 print('-c: characters (default)')
49 print('-w: words')
50 print('-d: more debugging output')
51 print('-q: no debugging output')
52 print('Input files (default stdin) are split in paragraphs')
53 print('separated blank lines and each paragraph is split')
54 print('in words by whitespace, then reconcatenated with')
55 print('exactly one space separating words.')
56 print('Output consists of paragraphs separated by blank')
57 print('lines, where lines are no longer than 72 characters.')
58 sys.exit(2)
59 histsize = 2
60 do_words = False
61 debug = 1
62 for o, a in opts:
63 if '-0' <= o <= '-9': histsize = int(o[1:])
64 if o == '-c': do_words = False
65 if o == '-d': debug += 1
66 if o == '-q': debug = 0
67 if o == '-w': do_words = True
68 if not args:
69 args = ['-']
70
71 m = Markov(histsize, random.choice)
72 try:
73 for filename in args:
74 if filename == '-':
75 f = sys.stdin
76 if f.isatty():
77 print('Sorry, need stdin from file')
78 continue
79 else:
80 f = open(filename, 'r')
81 with f:
82 if debug: print('processing', filename, '...')
83 text = f.read()
84 paralist = text.split('\n\n')
85 for para in paralist:
86 if debug > 1: print('feeding ...')
87 words = para.split()
88 if words:
89 if do_words:
90 data = tuple(words)
91 else:
92 data = ' '.join(words)
93 m.put(data)
94 except KeyboardInterrupt:
95 print('Interrupted -- continue with data read so far')
96 if not m.trans:

Callers 1

markov.pyFile · 0.70

Calls 13

putMethod · 0.95
getMethod · 0.95
MarkovClass · 0.85
tupleClass · 0.85
printFunction · 0.50
openFunction · 0.50
getoptMethod · 0.45
exitMethod · 0.45
isattyMethod · 0.45
readMethod · 0.45
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected