def setUp(self): io = CKYIO('../../../resources/GRAMMAR.IN', '../../../resources/LEXICON.IN', '../../../resources/SENTENCES.IN') outfile = 'OUTFILE.' self.parser = CKY(io.readGrammar(), io.readLexicon(), outfile) self.parser.matrix = [] self.parser.initializeTable(4)
# Theory of call: # - args.dest : contains content user entered # - e.g: args.grammar will return file name of file contain grammar if args: try: #Call to main parser #Read files if (args.algorithm == "c"): io = CKYIO(args.grammar, args.lexicon, args.sentence) listGrammar = io.readGrammar() listLexicon = io.readLexicon() listSentence = io.readSentence() #End read files #Initialize CYK cykInstance = CKY(listGrammar, listLexicon, args.outfile) startTime = time.clock() #Parse for each sentence INPUT for sent in listSentence: cykInstance.syntacticAnalyzer(sent) #End parse stopTime = time.clock() print "Analysis success. " \ "Please check output file! \nTime is: " \ ,stopTime-startTime elif (args.algorithm == "e"): io = EarleyIO() gram1 = io.readGrammar(args.grammar) gram2 = io.readLexicon(args.lexicon) gram1.extend(gram2) sents = io.readSentence(args.sentence)