-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestgra.py
76 lines (61 loc) · 2.36 KB
/
testgra.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import getgra
import sys
import datetime
from optparse import OptionParser
import os
program_name = sys.argv[0]
baseversion = "0"
subversion = "13"
version = baseversion + "." + subversion
exactlynow = datetime.datetime.now()
now = exactlynow.replace(microsecond=0).isoformat()
validexts = [".xml"]
def dotestgra(testgrain, logfile):
filenames = []
for root, dirs, thefiles in os.walk(testgrain):
for filename in thefiles:
fullname = os.path.join(root, filename)
(base, ext) = os.path.splitext(filename)
if ext in validexts:
filenames.append(fullname)
outfile = open(testgraoutfilename, 'w', encoding='utf8')
for filename in filenames:
print(filename, file=outfile)
(sentence, grastr) = getgra.getgra(filename, logfile, utterance=True)
print(sentence, file=outfile)
print(grastr, file=outfile)
outfile.close()
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
help="test on this file only")
parser.add_option("-i", "--inpath",
dest="inpath", default="testgrain",
help="path to input files")
parser.add_option("-o", "--outpath",
dest="outpath", default="testgraout",
help="path to output files")
parser.add_option("-l", "--logpath",
dest="logpath", default="testgralog",
help="path to log files")
parser.add_option("--logfile", dest="logfilename", default="testgralog.txt",
help="log filename")
parser.add_option("--outfile", dest="outfilename", default="testgraout.txt",
help="output filename")
(options, args) = parser.parse_args()
testgrain = options.inpath
testgraout = options.outpath
testgralog = options.logpath
testgraoutfilename = os.path.join(testgraout, options.outfilename)
testgralogfilename = os.path.join(testgralog, options.logfilename)
if options.filename is not None:
mygrafile = options.filename
else:
mygrafile = ""
if mygrafile!="":
testgralogfile = open(testgralogfilename, 'w', encoding='utf8')
result= getgra.getgra(mygrafile,testgralogfile)
print(result)
else:
testgralogfile = open(testgralogfilename, 'w', encoding='utf8')
dotestgra(testgrain, testgralogfile)
exit()