def parseOrders(self, sentence): #read the list of possible actions # acts = readFiles.functionList() # acts.importFiles() # sentence = "bring the coke to John_NN and leave the apartment" acts = readFiles.inv_functionList() # c = a.batch_parse(sentence) # # c = a.batch_parse(sentence.lower()) # d = c.strip().split("\n") # # d.index('') # # Extract parse tree data from Parser # tree = d[:d.index('')] # tree = '\n'.join(tree) # # Extract dependencies data from Parse # depends = d[d.index('') + 1:] # deps = self.extract_dependencies(depends) # s = tokenize_sentence(sentence) # n = change_exceptions(s, deps) n = 1 s = sentence print s while ex.check_sentence_changed(s, n): try: s = n[:] sentence = ex.detokenize_sentence(n) # print sentence + 'asfa' except: sentence = sentence # print sentence + 'fasf' c = a.batch_parse(sentence) # c = a.batch_parse(sentence.lower()) d = c.strip().split("\n") # d.index('') # Extract parse tree data from Parser tree = d[:d.index('')] tree = '\n'.join(tree) # Extract dependencies data from Parse depends = d[d.index('') + 1:] deps = self.extract_dependencies(depends) self.depends = depends self.tree = tree s = ex.tokenize_sentence(sentence) # print 'sentence: \n' # print s n = ex.change_exceptions(s, deps) print s # print 'new sentence: \n' # print n # print s # print ex.check_sentence_changed(s, n) # print '!!!!!!!!!!!' # Prepare tree to extract verbs (or any other data) t = tree.strip().split(' ') n = True while n: try: t.remove('') except: n = False tt = [] for part in t: try: part = part.replace("\n", "") except: True tt.append(part) # Find the verbs (predicates) in the sentence VerbList = [] verbs = True ttt = " ".join(tt) while verbs: try: verbPos = ttt.find('(VB') 1 / (verbPos + 1) # print 'aqui' # print ttt[verbPos + 4:verbPos + ttt[verbPos:].find(')')] VerbList.append(ttt[verbPos + 4:verbPos + ttt[verbPos:].find(')')]) ttt = ttt[verbPos + 3:] except: verbs = False # Ignore determinants, conjunctions and clausal complements rmList = ['det', 'ccomp', 'conj_and', 'root'] # print len(deps) for dep in deps: if dep.relation in rmList: # print dep.relation deps.remove(dep) # Add verb complements from dependencies list verbs = verbList() for v in VerbList: # print v v = v.strip(' ').lower() verbs.add_newverb(v) for dep in deps: if dep.mainVal == v: verbs.add_complement(v, dep) # print len(verbs) # Assigns each verb to an order # for v in verbs: # print v # try: # print v.verb # except: # print 'no verb' for v in verbs: o = orders() o.set_order(verbs[v], acts) self.actionSet.append(o) i = 1 for order in self.actionSet: print 'order #' + str(i) + ' of ' + str(len(self.actionSet)) print 'action:' print order.action print 'item:' print order.item print 'location:' print order.location print 'person:' print order.person i += 1 # O1 = orders() # O1.action = 'bring_to' # O1.item = 'coke' # O1.person = 'John' # O2 = orders() # O2.action = 'exit' # self.actionSet=[] # self.actionSet.append(O1) # self.actionSet.append(O2) return self
def parseOrders(self, sentence): #read the list of possible actions # acts = readFiles.functionList() # acts.importFiles() # sentence = "bring the coke to John_NN and leave the apartment" acts = readFiles.inv_functionList() #Load VerbCategories.txt # c = a.batch_parse(sentence) # # c = a.batch_parse(sentence.lower()) # d = c.strip().split("\n") # # d.index('') # # Extract parse tree data from Parser # tree = d[:d.index('')] # tree = '\n'.join(tree) # # Extract dependencies data from Parse # depends = d[d.index('') + 1:] # deps = self.extract_dependencies(depends) # s = tokenize_sentence(sentence) # n = change_exceptions(s, deps) commands = parseSentence(sentence) print("----------------comands---------------") print commands print("----------------fi comands---------------") if commands == 'unk': #if parserSentence couldnt return a thing return self fith confidence = 0 and finish self.confidence = '0' return self # not implemented: must be set the list of word topics to find and in which grammar # wordlist = grammarFileReader(wordset,path) # grammarFileWriter(wordlist) pervious_person = '' person = '' for c in commands: o = orders() action = '' item = '' pervious_person = person person = '' location = '' for prod in c.productions(): s = str(prod.lhs()) if s == 'VB': action = str( prod.rhs()).strip('(').strip(')').strip(',').strip("'") elif s == 'ITEM': item = '_'.join(prod.rhs()) elif s == 'PERSON': person = str( prod.rhs()).strip('(').strip(')').strip(',').strip("'") elif s == 'LOCATION': location = '_'.join(prod.rhs()) elif s == 'PRON': r = str( prod.rhs()).strip('(').strip(')').strip(',').strip("'") if r == 'it': item = self.actionSet[len(self.actionSet) - 1].item elif r == 'me' or r == 'my': person = 'referee' elif r == 'him': person = pervious_person elif s == 'FROM': # could be cleaned if action == 'bring': action = 'bring_from' person = 'referee' if action == 'find': if person == '': action == 'find_object' else: action == 'find_person' if action == 'exit' or action == 'leave': action = 'go_to' location = 'exit' try: action = acts[action] except: action = action if action == 'bring' or action == 'bring_from': if person == '': person = 'referee' print action + person try: o.define_order(action1=acts[action], item1=item, person1=person, location1=location) except KeyError: o.define_order(action1=action, item1=item, person1=person, location1=location) self.actionSet.append(o) # # Prepare tree to extract verbs (or any other data) # t = tree.strip().split(' ') # n = True # while n: # try: # t.remove('') # except: # n = False # tt = [] # for part in t: # try: # part = part.replace("\n", "") # except: # True # tt.append(part) # # Find the verbs (predicates) in the sentence # VerbList = [] # verbs = True # ttt = " ".join(tt) # while verbs: # try: # verbPos = ttt.find('(VB') # 1 / (verbPos + 1) # # print 'aqui' # # print ttt[verbPos + 4:verbPos + ttt[verbPos:].find(')')] # VerbList.append(ttt[verbPos + 4:verbPos + ttt[verbPos:].find(')')]) # ttt = ttt[verbPos + 3:] # except: # verbs = False # # Ignore determinants, conjunctions and clausal complements # rmList = ['det', 'ccomp', 'conj_and', 'root'] # # print len(deps) # for dep in deps: # if dep.relation in rmList: # # print dep.relation # deps.remove(dep) # # Add verb complements from dependencies list # verbs = verbList() # for v in VerbList: # # print v # v = v.strip(' ').lower() # verbs.add_newverb(v) # for dep in deps: # if dep.mainVal == v: # verbs.add_complement(v, dep) # # print len(verbs) # # Assigns each verb to an order # # for v in verbs: # # print v # # try: # # print v.verb # # except: # # print 'no verb' # for v in verbs: # o = orders() # o.set_order(verbs[v], acts) # self.actionSet.append(o) i = 1 for order in self.actionSet: print 'order #' + str(i) + ' of ' + str(len(self.actionSet)) print 'action:' print order.action print 'item:' print order.item print 'location:' print order.location print 'person:' print order.person i += 1 # O1 = orders() # O1.action = 'bring_to' # O1.item = 'coke' # O1.person = 'John' # O2 = orders() # O2.action = 'exit' # self.actionSet=[] # self.actionSet.append(O1) # self.actionSet.append(O2) return self
def parseOrders(self, sentence): #read the list of possible actions # acts = readFiles.functionList() # acts.importFiles() # sentence = "bring the coke to John_NN and leave the apartment" acts = readFiles.inv_functionList() #Load VerbCategories.txt # c = a.batch_parse(sentence) # # c = a.batch_parse(sentence.lower()) # d = c.strip().split("\n") # # d.index('') # # Extract parse tree data from Parser # tree = d[:d.index('')] # tree = '\n'.join(tree) # # Extract dependencies data from Parse # depends = d[d.index('') + 1:] # deps = self.extract_dependencies(depends) # s = tokenize_sentence(sentence) # n = change_exceptions(s, deps) commands = parseSentence(sentence) print("----------------comands---------------") print commands print("----------------fi comands---------------") if commands == 'unk': #if parserSentence couldnt return a thing return self fith confidence = 0 and finish self.confidence = '0' return self # not implemented: must be set the list of word topics to find and in which grammar # wordlist = grammarFileReader(wordset,path) # grammarFileWriter(wordlist) pervious_person = '' person = '' for c in commands: o = orders() action = '' item = '' pervious_person = person person = '' location = '' for prod in c.productions(): s = str(prod.lhs()) if s == 'VB': action = str(prod.rhs()).strip('(').strip(')').strip(',').strip("'") elif s == 'ITEM': item = '_'.join(prod.rhs()) elif s == 'PERSON': person = str(prod.rhs()).strip('(').strip(')').strip(',').strip("'") elif s == 'LOCATION': location = '_'.join(prod.rhs()) elif s == 'PRON': r = str(prod.rhs()).strip('(').strip(')').strip(',').strip("'") if r == 'it': item = self.actionSet[len(self.actionSet)-1].item elif r == 'me': person = 'referee' elif r == 'him': person = pervious_person elif s == 'FROM': # could be cleaned if action == 'bring': action = 'bring_from' person = 'referee' if action == 'find': if person == '': action == 'find_object' else: action == 'find_person' if action == 'exit' or action == 'leave': action = 'go_to' location = 'exit' try: action=acts[action] except: action=action if action == 'bring' or action == 'bring_from': if person == '': person = 'referee' print action + person try: o.define_order(action1=acts[action], item1=item, person1=person, location1=location) except KeyError: o.define_order(action1=action, item1=item, person1=person, location1=location) self.actionSet.append(o) # # Prepare tree to extract verbs (or any other data) # t = tree.strip().split(' ') # n = True # while n: # try: # t.remove('') # except: # n = False # tt = [] # for part in t: # try: # part = part.replace("\n", "") # except: # True # tt.append(part) # # Find the verbs (predicates) in the sentence # VerbList = [] # verbs = True # ttt = " ".join(tt) # while verbs: # try: # verbPos = ttt.find('(VB') # 1 / (verbPos + 1) # # print 'aqui' # # print ttt[verbPos + 4:verbPos + ttt[verbPos:].find(')')] # VerbList.append(ttt[verbPos + 4:verbPos + ttt[verbPos:].find(')')]) # ttt = ttt[verbPos + 3:] # except: # verbs = False # # Ignore determinants, conjunctions and clausal complements # rmList = ['det', 'ccomp', 'conj_and', 'root'] # # print len(deps) # for dep in deps: # if dep.relation in rmList: # # print dep.relation # deps.remove(dep) # # Add verb complements from dependencies list # verbs = verbList() # for v in VerbList: # # print v # v = v.strip(' ').lower() # verbs.add_newverb(v) # for dep in deps: # if dep.mainVal == v: # verbs.add_complement(v, dep) # # print len(verbs) # # Assigns each verb to an order # # for v in verbs: # # print v # # try: # # print v.verb # # except: # # print 'no verb' # for v in verbs: # o = orders() # o.set_order(verbs[v], acts) # self.actionSet.append(o) i = 1 for order in self.actionSet: print 'order #' + str(i) + ' of ' + str(len(self.actionSet)) print 'action:' print order.action print 'item:' print order.item print 'location:' print order.location print 'person:' print order.person i += 1 # O1 = orders() # O1.action = 'bring_to' # O1.item = 'coke' # O1.person = 'John' # O2 = orders() # O2.action = 'exit' # self.actionSet=[] # self.actionSet.append(O1) # self.actionSet.append(O2) return self