corpusFileName, grammarFileName = None, None testFileName = None for opt, arg in opts: if opt == "-c": # tree corpus corpusFileName = arg elif opt == "-g": # tree grammar grammarFileName = arg elif opt == "-s": # test sentences testFileName = arg # read/create grammar if not corpusFileName and not grammarFileName: # no tree corpus or grammar given print "Use '-c <file>' to give a tree corpus or '-g <file>' to give a grammar." sys.exit(2) elif corpusFileName: if not extractPCFG.fileExists(corpusFileName): print "The tree corpus '%s' does not exist." % corpusFileName sys.exit(2) grammar = extractPCFG.createGrammar( corpusFileName) # create grammar from corpus if not grammarFileName: grammarFileName = 'grammar_' + corpusFileName print "The grammar file is saved as: %s" % grammarFileName extractPCFG.saveToFile(grammar, grammarFileName) # save grammar elif grammarFileName: if not extractPCFG.fileExists(grammarFileName): print "The grammar '%s' does not exist." % grammarFileName sys.exit(2) try: # read grammar grammarFile = open(grammarFileName, 'r') grammar = ast.literal_eval(
testFileName, parsesFileName = None, None for opt, arg in opts: if opt == "-c": # tree corpus corpusFileName = arg elif opt == "-g": # tree grammar grammarFileName = arg elif opt == "-s": # test sentences testFileName = arg elif opt == "-p": # most probable trees for test sentences parsesFileName = arg # read/create grammar if not corpusFileName and not grammarFileName: # no tree corpus or grammar given print "Use '-c <file>' to give a tree corpus or '-g <file>' to give a grammar." sys.exit(2) elif corpusFileName: if not extractPCFG.fileExists(corpusFileName): print "The tree corpus '%s' does not exist." % corpusFileName sys.exit(2) grammar = extractPCFG.createGrammar( corpusFileName) # create grammar from corpus if not grammarFileName: grammarFileName = 'grammar_' + corpusFileName print "The grammar file is saved as: %s" % grammarFileName extractPCFG.saveToFile(grammar, grammarFileName) # save grammar elif grammarFileName: if not extractPCFG.fileExists(grammarFileName): print "The grammar '%s' does not exist." % grammarFileName sys.exit(2) try: # read grammar grammarFile = open(grammarFileName, 'r') grammar = ast.literal_eval(
testFileName, parsesFileName = None, None for opt, arg in opts: if opt == "-c": # tree corpus corpusFileName = arg elif opt == "-g": # tree grammar grammarFileName = arg elif opt == "-s": # test sentences testFileName = arg elif opt == "-p": # most probable trees for test sentences parsesFileName = arg # read/create grammar if not corpusFileName and not grammarFileName: # no tree corpus or grammar given print "Use '-c <file>' to give a tree corpus or '-g <file>' to give a grammar." sys.exit(2) elif corpusFileName: if not extractPCFG.fileExists(corpusFileName): print "The tree corpus '%s' does not exist." %corpusFileName sys.exit(2) grammar = extractPCFG.createGrammar(corpusFileName) # create grammar from corpus if not grammarFileName: grammarFileName = 'grammar_' + corpusFileName print "The grammar file is saved as: %s" %grammarFileName extractPCFG.saveToFile(grammar, grammarFileName) # save grammar elif grammarFileName: if not extractPCFG.fileExists(grammarFileName): print "The grammar '%s' does not exist." %grammarFileName sys.exit(2) try: # read grammar grammarFile = open(grammarFileName, 'r') grammar = ast.literal_eval(grammarFile.next().strip()) # read grammar from file except (SyntaxError, ValueError):
corpusFileName, grammarFileName = None, None testFileName = None for opt, arg in opts: if opt == "-c": # tree corpus corpusFileName = arg elif opt == "-g": # tree grammar grammarFileName = arg elif opt == "-s": # test sentences testFileName = arg # read/create grammar if not corpusFileName and not grammarFileName: # no tree corpus or grammar given print "Use '-c <file>' to give a tree corpus or '-g <file>' to give a grammar." sys.exit(2) elif corpusFileName: if not extractPCFG.fileExists(corpusFileName): print "The tree corpus '%s' does not exist." %corpusFileName sys.exit(2) grammar = extractPCFG.createGrammar(corpusFileName) # create grammar from corpus if not grammarFileName: grammarFileName = 'grammar_' + corpusFileName print "The grammar file is saved as: %s" %grammarFileName extractPCFG.saveToFile(grammar, grammarFileName) # save grammar elif grammarFileName: if not extractPCFG.fileExists(grammarFileName): print "The grammar '%s' does not exist." %grammarFileName sys.exit(2) try: # read grammar grammarFile = open(grammarFileName, 'r') grammar = ast.literal_eval(grammarFile.next().strip()) # read grammar from file except (SyntaxError, ValueError):