def _parse_as_who(self, chktree): if self.vb: print "Called _parse_as_who(chktree):- EntitySet" entSet = EntitySet("trivia", self.vb) negation = False looking_for = 'person' for x in chktree: if self._isLeaf(x): negation = self._negator(self._getLeafTxt(x), negation) keyword = None if self._getLeafTos(x) == "KW_DIRECTOR": keyword = 'director' elif self._getLeafTos(x) == "KW_STAR": keyword = 'actor' if keyword: if not entSet.has_entity('type'): entSet.add_entity('type', keyword) else: looking_for = keyword else: if x.node == "TITLE": entSet.add_entity2("movieTitle", self._getTreeTxt(x), negation) negation = False elif x.node == "PERSON": personName = self._getTreeTxt(x) if not entSet.has_entity('type'): entSet.add_entity('type', 'person') entSet.add_entity('character', personName) else: entSet.add_entity2(looking_for, personName, negation) negation = False if entSet.count_entities() == 0: #empty entitySet -> unable to parse utterance -> let DM know entSet.change_classifier("unknown") elif not entSet.has_entity('type'): entSet.add_entity('type', 'person') return [ entSet ]
def _parse_as_what(self, chktree): if self.vb: print "Called _parse_as_what(%s):- EntitySet" % (chktree.node) entSet = EntitySet("trivia", self.vb) looking_for = 'other' negation = False ## Shouldn't need this with changes to KW_PLOT below: ''' flat = chktree.leaves() if flat[ len(flat) - 1 ][1] == ":": last = flat[ len(flat) - 2 ] else: last = flat[ len(flat) - 1 ] if last[1] == "KW_PLOT": entSet.add_entity("type", "plot") ''' for itor,x in enumerate(chktree): if self._isLeaf(x): nodetype = self._getLeafTos(x) nodetxt = self._getLeafTxt(x) if not entSet.has_entity('type'): if nodetype == "KW_YEAR": return self._parse_as_when(chktree) elif nodetype == "KW_DIRECTOR" or nodetype == "KW_STAR": next = chktree[itor+1] if self._isTreeBranch(next) and next.node == 'PERSON': looking_for = 'actor' if nodetype == 'KW_DIRECTOR': looking_for = 'director' else: return self._parse_as_who(chktree) elif nodetype == "KW_GENRE": entSet.add_entity("type", "genre") elif nodetype == "KW_MOVIE": entSet.add_entity("type", "movieTitle") elif nodetype == "KW_PLOT": entSet.add_entity("type", "plot") elif nodetype == "GNRE": entSet.add_entity("type", "movieTitle") entSet.add_entity("genre", nodetxt) else: negation = self._negator(nodetxt, negation) if nodetype == 'POS': ## We mis-categorized the type. ## Ex: "What was director Michael Bay's latest movie?" ## Director is not what the user is looking for. director describes Michael Bay, which describes movie. #if entSet.has_entity('type'): # looking_for = entSet.find_entity('type') # if looking_for = 'director' or looking_for == 'actor' pass if nodetype == "KW_DIRECTOR": looking_for = "director" elif nodetype == "KW_STAR": looking_for = "actor" elif nodetype == "KW_PLOT": #looking_for = "plot" ## TODO: TEST THIS entSet.add_entity('type', 'plot') elif nodetype == "GNRE": entSet.add_entity2('genre', nodetxt, negation) negation = False else: if x.node == "TITLE": entSet.add_entity2('movieTitle', self._getTreeTxt(x), negation) elif x.node == "PERSON": subject = looking_for if looking_for == 'other': subject = 'person' entSet.add_entity2(subject, self._getTreeTxt(x), negation) negation = False return [ entSet ]