def parse(self, ss): """ tokens -> list of (hallucinated preposition, Selector, noun) Try to pull a pro-adverb out of the given words (typically just one word). """ rr = [] for is_archaic in [False, True]: for correlative, pro_adverb_col in \ self.ss_archaic2cors_pacs[(ss, is_archaic)]: noun = self.pro_adverb_col2noun[pro_adverb_col] prep = self.noun2hallucinate_prep.get(noun) count_res, _ = self.cor2res_gno[correlative] selector = Selector.from_correlative(correlative, count_res) rr.append((prep, selector, noun)) return rr
def parse(self, ss): """ tokens -> list of (hallucinated preposition, Selector, noun) Try to pull a pro-adverb out of the given words (typically just one word). """ rr = [] for is_archaic in [False, True]: for correlative, pro_adverb_col in \ self.ss_archaic2cors_pacs[(ss, is_archaic)]: noun = self.pro_adverb_col2noun[pro_adverb_col] prep = self.noun2hallucinate_prep.get(noun) count_res, _ = self.cor2res_gno[correlative] selector = Selector.from_correlative(correlative, count_res) rr.append((prep, selector, noun)) return rr
def recog_posdet_nn_head(self, root_token, noun, gram_n2): """ * PRP$ (ADJS) NN(S) * WP$ (ADJS) NN(S) """ downs = filter(lambda (rel, child): rel not in ('cc', 'conj', 'prep'), root_token.downs) if not downs: return [] rel, possessor = downs[0] if rel != 'pos': return [] attrs = [] for rel, child in downs[1:]: if rel != 'amod': return [] attrs.append(child.text) nn = [] for declension in self.personal_mgr.posdet_parse((possessor.text, )): pos = PersonalPronoun(declension, PersonalPronounCase.OBJECT) correlative = Correlative.DEF count_restriction = self.det_pronoun_mgr.cor2res_gno[correlative][ 0] selector = Selector.from_correlative(correlative, count_restriction) if not selector: continue for selector in selector.restricted_to_grammatical_number( gram_n2, self.det_pronoun_mgr.cor2res_gno): n = SurfaceCommonNoun(possessor=pos, selector=selector, attributes=list(attrs), noun=noun) nn.append(n) return map(lambda n: (None, n), nn)
def recog_posdet_nn_head(self, root_token, noun, gram_n2): """ * PRP$ (ADJS) NN(S) * WP$ (ADJS) NN(S) """ downs = filter(lambda (rel, child): rel not in ('cc', 'conj', 'prep'), root_token.downs) if not downs: return [] rel, possessor = downs[0] if rel != 'pos': return [] attrs = [] for rel, child in downs[1:]: if rel != 'amod': return [] attrs.append(child.text) nn = [] for declension in self.personal_mgr.posdet_parse((possessor.text,)): pos = PersonalPronoun(declension, PersonalPronounCase.OBJECT) correlative = Correlative.DEF count_restriction = self.det_pronoun_mgr.cor2res_gno[correlative][0] selector = Selector.from_correlative(correlative, count_restriction) if not selector: continue for selector in selector.restricted_to_grammatical_number( gram_n2, self.det_pronoun_mgr.cor2res_gno): n = SurfaceCommonNoun(possessor=pos, selector=selector, attributes=list(attrs), noun=noun) nn.append(n) return map(lambda n: (None, n), nn)
def recog_how_many_nn_head(self, root_token, noun, n2): many = None for rel, child in root_token.downs: if rel == 'amod' and child.text in ('few', 'many'): many = child break if not many: return [] how = None for rel, child in many.downs: if rel == 'advmod' and child.text == 'how': how = child number = Number(None) correlative = Correlative.INDEF count_restriction = self.det_pronoun_mgr.cor2res_gno[correlative][0] selector = Selector.from_correlative(correlative, count_restriction) assert selector n = SurfaceCommonNoun(selector=selector, number=number, noun=noun) return [(None, n)]
def recog_how_many_nn_head(self, root_token, noun, n2): many = None for rel, child in root_token.downs: if rel == 'amod' and child.text in ('few', 'many'): many = child break if not many: return [] how = None for rel, child in many.downs: if rel == 'advmod' and child.text == 'how': how = child number = Number(None) correlative = Correlative.INDEF count_restriction = self.det_pronoun_mgr.cor2res_gno[correlative][0] selector = Selector.from_correlative(correlative, count_restriction) assert selector n = SurfaceCommonNoun(selector=selector, number=number, noun=noun) return [(None, n)]