def construct_one_lookup_table(verb_sayer, lemmas, is_pro_verbs): finite_options = SurfaceVerb.finite_options(lemmas, is_pro_verbs) nonfinite_options = SurfaceVerb.nonfinite_options(lemmas, is_pro_verbs) sss2vv = defaultdict(list) for aa in chain(product(*finite_options), product(*nonfinite_options)): v = SurfaceVerb.from_tuple(aa) for sss in verb_sayer.get_all_say_options(v): sss = (tuple(sss[0]), tuple(sss[1])) sss2vv[sss].append(v) return sss2vv
def to_surface(self, transform_state, say_state, idiolect): argx_to_front = decide_arg_to_front( self.rels_vargs, self.purpose, self.subj_index) # Verb context. voice = self.decide_voice() conj = self.decide_conjugation(transform_state, say_state, idiolect) assert conj is_fronting = argx_to_front is not None info = transform_state.purpose_mgr.get(self.purpose) is_split = info.split_verb(is_fronting) relative_cont = RelativeContainment.NOT_REL contract_not = idiolect.contractions split_inf = idiolect.split_infinitive if idiolect.subjunctive_were: sbj_handling = SubjunctiveHandling.WERE_SBJ else: sbj_handling = SubjunctiveHandling.WAS_SBJ surface_verb = SurfaceVerb( self.verb, voice, conj, is_split, relative_cont, contract_not, split_inf, sbj_handling) surface_verb.check(allow_wildcards=False) # Figure out prepositions for our relations. rels_types = [] for rel, arg in self.rels_vargs: rels_types.append((rel, arg.relation_arg_type())) preps = transform_state.relation_mgr.decide_preps( rels_types, self.subj_index) # Build list of properly prepositioned surface arguments (without # fronting or imperative subject omission). orig_preps_surfs = [] for (rel, arg), prep in zip(self.rels_vargs, preps): surface = arg.to_surface(transform_state, say_state, idiolect) orig_preps_surfs.append((prep, surface)) # If imperative, we disappear the subject ("do this" vs "you do this"). is_imperative = self.verb.modality.flavor == ModalFlavor.IMPERATIVE # Apply transformations to get surface structure for args (eg, # fronting). preps_surfs, vmain_index = transform( orig_preps_surfs, self.subj_index, is_imperative, argx_to_front, idiolect.stranding) # Get the complementizer. complementizer = STATUS2COMPLEMENTIZER[self.status] return SurfaceContentClause( complementizer, surface_verb, self.adverbs, preps_surfs, vmain_index)
def to_surface(self, transform_state, say_state, idiolect): argx_to_front = decide_arg_to_front(self.rels_vargs, self.purpose, self.subj_index) # Verb context. voice = self.decide_voice() conj = self.decide_conjugation(transform_state, say_state, idiolect) assert conj is_fronting = argx_to_front is not None info = transform_state.purpose_mgr.get(self.purpose) is_split = info.split_verb(is_fronting) relative_cont = RelativeContainment.NOT_REL contract_not = idiolect.contractions split_inf = idiolect.split_infinitive if idiolect.subjunctive_were: sbj_handling = SubjunctiveHandling.WERE_SBJ else: sbj_handling = SubjunctiveHandling.WAS_SBJ surface_verb = SurfaceVerb(self.verb, voice, conj, is_split, relative_cont, contract_not, split_inf, sbj_handling) surface_verb.check(allow_wildcards=False) # Figure out prepositions for our relations. rels_types = [] for rel, arg in self.rels_vargs: rels_types.append((rel, arg.relation_arg_type())) preps = transform_state.relation_mgr.decide_preps( rels_types, self.subj_index) # Build list of properly prepositioned surface arguments (without # fronting or imperative subject omission). orig_preps_surfs = [] for (rel, arg), prep in zip(self.rels_vargs, preps): surface = arg.to_surface(transform_state, say_state, idiolect) orig_preps_surfs.append((prep, surface)) # If imperative, we disappear the subject ("do this" vs "you do this"). is_imperative = self.verb.modality.flavor == ModalFlavor.IMPERATIVE # Apply transformations to get surface structure for args (eg, # fronting). preps_surfs, vmain_index = transform(orig_preps_surfs, self.subj_index, is_imperative, argx_to_front, idiolect.stranding) # Get the complementizer. complementizer = STATUS2COMPLEMENTIZER[self.status] return SurfaceContentClause(complementizer, surface_verb, self.adverbs, preps_surfs, vmain_index)
def from_ints(s2nn, options_per_field, num_options_per_field): sss2vv = defaultdict(list) for s, nn in s2nn.iteritems(): sss = unpack_verb_words(s) vv = [] for n in nn: ints = wildcardy_int_tuple_from_int(n, num_options_per_field) v = SurfaceVerb.from_int_tuple(ints, options_per_field) vv.append(v) sss2vv[sss] = vv return sss2vv
def load_lookup_tables(f): """ f -> be, pro, deverbed """ verbs_used = ['be', 'see', MAGIC_INTS_LEMMA] options_per_field = SurfaceVerb.all_options(verbs_used, [False, True]) zz = map(len, options_per_field) d = json.load(open(f)) be = from_ints(d['be'], options_per_field, zz) pro = from_ints(d['pro-verb'], options_per_field, zz) deverbed = from_ints(d['deverbed'], options_per_field, zz) return be, pro, deverbed
def load(d, loader): complementizer = Complementizer.from_str[d['complementizer']] verb = SurfaceVerb.load(d['verb']) preps_vargs = [] for prep, arg in d['preps_vargs']: if arg: arg = loader.load(arg) preps_vargs.append((prep, arg)) adverbs = d['adverbs'] vmain_index = d['vmain_index'] return SurfaceContentClause( complementizer, verb, adverbs, preps_vargs, vmain_index)
def save_lookup_tables(be, pro, deverbed, f): """ be, pro, deverbed, f -> None """ verbs_used = ['be', 'see', MAGIC_INTS_LEMMA] options_per_field = SurfaceVerb.all_options(verbs_used, [False, True]) zz = map(len, options_per_field) be_s2nn = to_ints(be, options_per_field, zz) pro_verb_s2nn = to_ints(pro, options_per_field, zz) deverbed_s2nn = to_ints(deverbed, options_per_field, zz) d = { 'be': be_s2nn, 'pro-verb': pro_verb_s2nn, 'deverbed': deverbed_s2nn, } dir_name = os.path.dirname(f) if not os.path.exists(dir_name): os.makedirs(dir_name) json.dump(d, open(f, 'wb'))
def main(): conj_f = 'panoptes/ling/verb/conjugations.csv' verb_f = 'data/verbs.json' m = VerbManager.from_files(conj_f, verb_f) j = { 'sbj_handling': 'WERE_SBJ', 'relative_cont': 'NOT_REL', 'contract_not': True, 'intrinsics': { 'polarity': { 'tf': True, 'is_contrary': False }, 'verb_form': 'FINITE', 'lemma': 'go', 'tense': 'PRESENT', 'aspect': { 'is_prog': False, 'is_perf': False }, 'is_pro_verb': False, 'modality': { 'is_cond': False, 'flavor': 'IMPERATIVE' } }, 'split_inf': True, 'is_split': False, 'conj': 'S2', 'voice': 'ACTIVE' } v_to_say = SurfaceVerb.load(j) assert m.say(v_to_say) == ([], ['go']) sss = ((), ('go',)) vv = m.parse(sss) assert any(map(lambda v: v.may_match(v_to_say), vv)) text = """ sbj_handling: WERE_SBJ relative_cont: NOT_REL contract_not: true split_inf: true is_split: true conj: S2 voice: ACTIVE intrinsics: lemma: go polarity: tf: true is_contrary: false tense: PRESENT aspect: is_perf: true is_prog: false modality: flavor: INDICATIVE is_cond: true verb_form: FINITE is_pro_verb: false """ j = yaml.load(text) v = SurfaceVerb.load(j) assert m.say(v) == (['would'], ['[AUX]have', 'gone'])