def relative_verse(noun, pos_dict=None): random.seed() main_np = syntax_maker.create_personal_pronoun_phrase("3", "SG") if pos_dict and "nouns" in pos_dict: rel_ws = pos_dict["nouns"] else: rel_ws = word_lookup.get_related_words(noun) if len(rel_ws) == 0: synonym = noun else: synonym = random.choice(rel_ws) if pos_dict and "verbs" in pos_dict: random.seed() verb1 = random.choice(pos_dict["verbs"]) verb2 = random.choice(pos_dict["verbs"]) else: verb1 = noun_tool.get_a_verb(synonym) verb2 = noun_tool.get_a_verb(noun) if verb1 is None: verb1 = noun_tool.get_a_verb(noun) if verb1 is None or verb2 is None: return None relative_p = syntax_maker.create_verb_pharse(verb1) relative_p.components["dir_object"] = syntax_maker.create_phrase( "NP", synonym) syntax_maker.add_relative_clause_to_np(main_np, relative_p, subject=True) phrase = syntax_maker.create_verb_pharse(verb2) phrase.components["subject"] = main_np phrase.components["dir_object"] = syntax_maker.create_phrase("NP", noun) return {"verse": str(phrase), "noun": noun}
def construct_a_metaphor(noun, use_pronoun=False, pos_dict=None): random.seed() possibilities = list_possible_metaphors(noun) if len(possibilities) == 0: return None comp_noun = random.choice(list(possibilities.keys())) verb = random.choice(possibilities[comp_noun]) metaphor_phrase = syntax_maker.create_copula_phrase() if use_pronoun: sp = syntax_maker.create_personal_pronoun_phrase("2", "SG") person = "2" number = "SG" else: sp = syntax_maker.create_phrase("NP", noun, {u"PERS": "3", u"NUM": "SG"}) person = "3" number = "SG" metaphor_phrase.components["subject"] = sp metaphor_phrase.components["predicative"] = syntax_maker.create_phrase("NP", comp_noun, {u"PERS": "3", u"NUM": "SG"}) meta_string = metaphor_phrase.to_string() explain_phrase = syntax_maker.create_verb_pharse(verb) explain_phrase.components["subject"] = syntax_maker.create_personal_pronoun_phrase(person,number,True) add_adverb = True if "dir_object" in explain_phrase.components: if pos_dict: add_adverb = True dir_o = random.choice(pos_dict["nouns"]) else: add_adverb = False dir_o = noun_tool.get_an_object(verb, "dir") explain_phrase.components["dir_object"] = syntax_maker.create_phrase("NP", dir_o, {u"PERS": "3", u"NUM": "SG"}) if "indir_object" in explain_phrase.components: if pos_dict: indir_o = random.choice(pos_dict["nouns"]) else: indir_o = noun_tool.get_an_object(verb, "indir") explain_phrase.components["indir_object"] = syntax_maker.create_phrase("NP", indir_o, {u"PERS": "3", u"NUM": "SG"}) explain_string = explain_phrase.to_string() adverb = "" if pos_dict and "adverbs" in pos_dict: adverb = " " + random.choice(pos_dict["adverbs"]) elif add_adverb: pos_adverb = verb_valence.get_an_adverb(verb) if pos_adverb is not None: adverb = " " + pos_adverb verse = meta_string + "\n" + explain_string + adverb return {"verse": verse, "noun": comp_noun, "verb" : verb}
def subjective_opinion(noun, person="SG1", aux=None, pos_dict = None): random.seed() if pos_dict and "verbs" in pos_dict: verb = random.choice(pos_dict["verbs"]) else: while True: verb = pronoun_tool.give_a_verb(person) if verb is None: return None if verb_valence.is_copula(verb) or syntax_maker.is_auxiliary_verb(verb): pass elif verb_valence.valency_count(verb) > 1: break phrase = syntax_maker.create_verb_pharse(verb) num = person[:2] pers = person[2:] phrase.components["subject"] = syntax_maker.create_phrase("NP", pronoun_tool.pronoun(person), {u"PERS": pers, u"NUM": num}) if "indir_object" in phrase.components: indir_o = noun if pos_dict and "nouns" in pos_dict: dir_o = random.choice(pos_dict["nouns"]) else: dir_o = noun_tool.get_an_object(verb, "dir") else: dir_o = noun if "dir_object" in phrase.components: phrase.components["dir_object"] = syntax_maker.create_phrase("NP", dir_o, {u"PERS": "3", u"NUM": "SG"}) if "indir_object" in phrase.components: phrase.components["indir_object"] = syntax_maker.create_phrase("NP", indir_o, {u"PERS": "3", u"NUM": "SG"}) if aux is None: aux = random.choice([True, False]) if aux: syntax_maker.add_auxiliary_verb_to_vp(phrase) if random.choice([True, False]): syntax_maker.negate_verb_pharse(phrase) return {"verse": phrase.to_string(), "noun": dir_o, "verb": verb}
def counterfactual_verse(noun, person="SG1", question=None, negation=None, prodrop=False, use_pronoun=False, passive=False, pos_dict=None): random.seed() num = person[:2] pers = person[2:] subject = None if not prodrop: subject = pronoun_tool.pronoun(person) interrog = "" if pos_dict and "verbs" in pos_dict: verb = random.choice(pos_dict["verbs"]) else: verb = noun_tool.get_a_verb(noun) if verb is None: return None condition_phrase = syntax_maker.create_verb_pharse(verb) condition_phrase.morphology[u"MOOD"] = "COND" if use_pronoun: p_num = num if pers == "1": p_pers = "2" else: p_pers = "1" sp = syntax_maker.create_personal_pronoun_phrase(p_pers,p_num) else: sp =syntax_maker.create_phrase("NP",noun, {u"PERS": "3", u"NUM": "PL"}) condition_phrase.components["subject"] = sp dir_o = None if "dir_object" in condition_phrase.components: if pos_dict and "nouns" in pos_dict: dir_o = random.choice(pos_dict["nouns"]) else: dir_o = noun_tool.get_an_object(verb, "dir") condition_phrase.components["dir_object"] = syntax_maker.create_phrase("NP", dir_o, {u"PERS": "3", u"NUM": "SG"}) if "indir_object" in condition_phrase.components: if pos_dict and "nouns" in pos_dict: indir_o = random.choice(pos_dict["nouns"]) else: indir_o = noun_tool.get_an_object(verb, "indir") condition_phrase.components["indir_object"] = syntax_maker.create_phrase("NP", indir_o, {u"PERS": "3", u"NUM": "SG"}) if negation is None: negation = random.choice([True, False]) if negation: syntax_maker.negate_verb_pharse(condition_phrase) if passive: syntax_maker.turn_vp_to_passive(condition_phrase) if pos_dict and "verbs" in pos_dict: verb = random.choice(pos_dict["verbs"]) else: while True: verb = pronoun_tool.give_a_verb(person) if verb is None: return None if verb_valence.is_copula(verb) or syntax_maker.is_auxiliary_verb(verb): pass elif verb_valence.valency_count(verb) > 1: break phrase = syntax_maker.create_verb_pharse(verb) phrase.morphology[u"MOOD"] = "COND" phrase.components["subject"] = syntax_maker.create_phrase("NP", subject, {u"PERS": pers, u"NUM": num}) if "dir_object" in phrase.components: if use_pronoun: dop = syntax_maker.create_personal_pronoun_phrase(p_pers,p_num) else: dop = syntax_maker.create_phrase("NP", noun, {u"PERS": "3", u"NUM": "SG"}) phrase.components["dir_object"] = dop if "indir_object" in phrase.components: if pos_dict and "nouns" in pos_dict: indir_o = random.choice(pos_dict["nouns"]) else: indir_o = noun_tool.get_an_object(verb, "indir") phrase.components["indir_object"] = syntax_maker.create_phrase("NP", indir_o, {u"PERS": "3", u"NUM": "SG"}) if question is None: question = random.choice([True, False]) if question: syntax_maker.turn_vp_into_question(phrase) interrog = "?" return_verse = {"noun":noun, "verb": verb} if dir_o is not None: return_verse["noun"] = dir_o conjunction = random.choice(counterfactual_conjunctions) return_verse["verse"] = conjunction + " " + condition_phrase.to_string() + ", " + phrase.to_string() + interrog return return_verse
def propositional_attitude(noun, person="SG1", question=None, negation=None, prodrop=False, pos_dict=None): random.seed() #Main clause attitude_subject = None if not prodrop: attitude_subject = pronoun_tool.pronoun(person) num = person[:2] pers = person[2:] attitude_verb = random.choice(attitude_verbs) attitude_phrase = syntax_maker.create_verb_pharse(attitude_verb) attitude_phrase.components["subject"] = syntax_maker.create_phrase("NP", attitude_subject, {u"PERS": pers, u"NUM": num}) interrog = "" if negation is None: negation = random.choice([True, False]) if negation: syntax_maker.negate_verb_pharse(attitude_phrase) if question is None: question = random.choice([True, False]) if question: syntax_maker.turn_vp_into_question(attitude_phrase) interrog = "?" #Subordinate clause verb = noun_tool.get_a_verb(noun) if verb is None: return None vp = syntax_maker.create_verb_pharse(verb) vp.components["subject"] = syntax_maker.create_phrase("NP", noun, {u"PERS": "3", u"NUM": "SG"}) add_adverb = True if "dir_object" in vp.components: add_adverb = False if pos_dict and "nouns" in pos_dict: dir_o = random.choice(pos_dict["nouns"]) else: dir_o = noun_tool.get_an_object(verb, "dir") noun = dir_o vp.components["dir_object"] = syntax_maker.create_phrase("NP", dir_o, {u"PERS": "3", u"NUM": "SG"}) if "indir_object" in vp.components: if pos_dict and "nouns" in pos_dict: indir_o = random.choice(pos_dict["nouns"]) else: indir_o = noun_tool.get_an_object(verb, "indir") vp.components["indir_object"] = syntax_maker.create_phrase("NP", indir_o, {u"PERS": "3", u"NUM": "SG"}) adverb = "" if add_adverb: if pos_dict and "adverbs" in pos_dict: pos_adverb = random.choice(pos_dict["adverbs"]) else: pos_adverb = verb_valence.get_an_adverb(verb) if pos_adverb is not None: adverb = " " + pos_adverb conjunction = random.choice(attitude_conjunctions) verse = attitude_phrase.to_string() + ", " + conjunction + " " + vp.to_string() + adverb +interrog return {"verse": verse, "noun": noun, "verb": verb}
def create_verse(noun, pos_dict=None): random.seed() if pos_dict: word = random.choice(pos_dict["nouns"]) else: syns = word_lookup.get_related_words(noun) if len(syns) == 0: return None word = random.choice(syns) if word is None: word = noun verbs = noun_tool.verbs_for_noun(word) if len(verbs) == 0: verbs = noun_tool.verbs_for_noun(noun) if len(verbs) == 0 and pos_dict and "verbs" in pos_dict: verbs = pos_dict["verbs"] elif len(verbs) == 0: return None if "olla" in verbs: del verbs["olla"] if type(verbs) == dict: verb = random.choice(list(verbs.keys())) else: verb = random.choice(verbs) phrase = syntax_maker.create_verb_pharse(verb) #Start of the sentence, "aurinkona, valona..." phrase.order.insert(0, "Advl") advl = {u"CASE": "Ess"} phrase.governance["Advl"] = advl phrase.components["Advl"] = syntax_maker.create_phrase( "NP", word, { u"PERS": "3", u"NUM": "SG" }) phrase.components["subject"] = syntax_maker.create_phrase( "NP", "se", { u"PERS": "3", u"NUM": "SG" }) add_adverb = True if "dir_object" in phrase.components: add_adverb = False if pos_dict and "nouns" in pos_dict: dir_o = random.choice(pos_dict["nouns"]) else: dir_o = noun_tool.get_an_object(verb, "dir") phrase.components["dir_object"] = syntax_maker.create_phrase( "NP", dir_o, { u"PERS": "3", u"NUM": "SG" }) if "indir_object" in phrase.components: if pos_dict and "nouns" in pos_dict: indir_o = random.choice(pos_dict["nouns"]) else: indir_o = noun_tool.get_an_object(verb, "indir") phrase.components["indir_object"] = syntax_maker.create_phrase( "NP", indir_o, { u"PERS": "3", u"NUM": "SG" }) explain_string = phrase.to_string() adverb = "" if pos_dict and "adverbs" in pos_dict: adverb = " " + random.choice(pos_dict["adverbs"]) if add_adverb: pos_adverb = verb_valence.get_an_adverb(verb) if pos_adverb is not None: adverb = pos_adverb + " " verse = adverb + explain_string return {"verse": verse, "noun": word, "verb": verb}