source: proto/SymbolTable/src/run_wcd.py @ 4881

Last change on this file since 4881 was 1794, checked in by vla24, 8 years ago

updated wcd performance script

File size: 1.8 KB
Line 
1import sys
2from subprocess import *
3import os
4
5def get_new_file_path(path):
6    # get filename
7    split_tuple = path.rpartition("/")
8    if (len(split_tuple[0]) == 0 and len(split_tuple[1]) == 0):
9        # file under the same directory
10        return "./lowercase_" + path
11    else:
12        return "./lowercase_" + split_tuple[2]
13
14def convert_file_to_lowercase(path):
15    new_path = get_new_file_path(path)
16
17    new_file_handle = open(new_path,'w')
18    original_file_handle = open(path,'r')
19
20    line = original_file_handle.readline() # Reading the whole line
21    while line:
22        lowercase_line = line.lower()
23        new_file_handle.write(lowercase_line)
24        line = original_file_handle.readline()
25
26    new_file_handle.close()
27    original_file_handle.close()
28
29    return new_path
30
31def run_test(dictionaryfile, textfile):
32    mes_f = open("mesfile", 'w')
33    call(['./wcd', dictionaryfile, textfile], stderr=mes_f)
34    mes_f.close()
35
36def run_test_output(dictionaryfile, textfile, outfile):
37    mes_f = open("mesfile", 'w')
38    call(['./wcd', dictionaryfile, textfile, outfile], stderr=mes_f)
39    mes_f.close()
40
41def delete_temporary_files(dictionaryfile, textfile):
42    os.remove (dictionaryfile)
43    os.remove (textfile)
44
45def delete_temporary_file(f):
46    os.remove (f)
47
48def main():
49    if (len(sys.argv)  < 3):
50        print "Usage: wcd <dictionaryfile> <textfile> [<outputfile>]"
51        exit(0)
52
53    dictionary_path = sys.argv[1]
54    text_path = sys.argv[2]
55
56    # convert files to lowercase
57    dictionary_new_path = convert_file_to_lowercase(dictionary_path)
58    text_new_path = convert_file_to_lowercase(text_path)
59
60    # run tests
61    if (len(sys.argv) == 3):
62        run_test(dictionary_new_path, text_new_path)
63    else:
64        run_test_output(dictionary_new_path, text_new_path, sys.argv[3])
65
66    # delete temporary files
67    delete_temporary_files(dictionary_new_path, text_new_path)
68
69if __name__ == "__main__": main()
Note: See TracBrowser for help on using the repository browser.