def dep_csubjpass(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens): target_token = token.head if target_token.dep_ is "aux" or target_token.dep_ is "auxpass": target_token = target_token.head token_predicate = library.get_predicate(token, predicates) target_predicate = library.get_predicate(target_token, predicates) if target_predicate is not None: target_predicate.subj_token_list = token_predicate.subj_token_list else: library.make_predicate(predicates, target_token, target_token, token_predicate.subj_token_list)
def dep_oprd(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens): target_token = token.head target_predicate = library.get_predicate(target_token, predicates) if target_token in passive_tokens: #LA FALLA STA IN DUE VERBI AL PASSIVO UNITI DA UNA CONGIUNZIONE if not library.get_predicate( token, predicates) and target_predicate.obj_token_list != []: library.make_predicate(predicates, token, target_predicate.obj_token_list[0]) else: if not library.get_predicate( token, predicates) and target_predicate.subj_token_list != []: library.make_predicate(predicates, token, target_predicate.subj_token_list[0])
def dep_relcl(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens): if library.get_predicate(token, predicates) is None: library.make_predicate(predicates, token, token, token.head) else: library.add_to_subj_list(token.head, token, variables, predicates, num_of_terms)
def dep_pcomp(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens): prep_token = token.head prep_head = prep_token.head if prep_head.dep_ is "xcomp": prep_head = library.until_not("xcomp", prep_head) if library.get_predicate(prep_token, predicates) is None: library.make_mono_predicate(token, predicates) library.make_predicate(predicates, prep_token, prep_head, token)
def dep_advmod(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens): if not library.get_predicate(token, predicates): if token.tag_ == "WRB": cond_tokens.append(token) library.make_predicate(predicates, token, token.head) else: dep_modifier(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens)
def dep_modifier(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens): if not library.get_predicate(token, predicates): target_token = token.head if target_token.dep_ in dep_modifiers: while target_token.dep_ in dep_modifiers: target_token = target_token.head elif target_token.dep_ is "xcomp": target_token = library.until_not("xcomp", target_token) library.make_mono_predicate(target_token, predicates) library.make_predicate(predicates, token, target_token)
def dep_compound(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens): target_token = token.head if target_token.dep_ is "poss": library.make_predicate(predicates, token, target_token) elif target_token.dep_ is "conj": conj_head = library.until_not("conj", token.head) if conj_head.dep_ in dep_modifiers: conj_head_predicate = library.get_predicate(conj_head, predicates) library.make_predicate(predicates, token.head, conj_head_predicate.dep_token, None, None, token) else: dep_modifier(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens)
def dep_pobj(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens): if token.dep_ is "conj": pobj_token = library.until_not("conj", token) prep_token = pobj_token.head else: prep_token = token.head if prep_token.dep_ is "prt": target_token = prep_token.head if target_token.dep_ is "xcomp": target_token = library.until_not("xcomp", target_token) if not library.add_to_obj_list(token, target_token, variables, predicates, num_of_terms): library.make_predicate(predicates, target_token, target_token, None, token) library.make_mono_predicate(token, predicates) else: if prep_token.dep_ is "conj": prep_head = library.until_not("conj", prep_token) prep_head = prep_head.head else: prep_head = prep_token.head if prep_head.dep_ is "appos": prep_head = library.until_not("appos", prep_head) elif prep_head.dep_ is "xcomp": prep_head = library.until_not("xcomp", prep_head) #elif prep_head.dep_ is "conj": # prep_head = library.until_not("conj", prep_head) if prep_token.dep_ is "agent": library.add_to_subj_list(token, prep_head, variables, predicates, num_of_terms) while prep_head.dep_ is "conj" and prep_head.head in passive_tokens: library.add_to_subj_list(token, prep_head.head, variables, predicates, num_of_terms) prep_head = prep_head.head elif library.get_predicate(prep_token, predicates) is None: library.make_mono_predicate(token, predicates) library.make_mono_predicate(prep_head, predicates) library.make_predicate(predicates, prep_token, prep_head, token)
def dep_conj(token, variables, predicates, cond_tokens, passive_tokens, num_of_terms, isa_tokens): target_token = token.head token_predicate = library.get_predicate(token, predicates) target_predicate = library.get_predicate(target_token, predicates) conj_head = library.until_not("conj", token) if conj_head.dep_ is "xcomp": if not library.add_to_prefix(conj_head.head, token, predicates): head_predicate = library.get_predicate( library.until_not("xcomp", conj_head), predicates) library.make_predicate(predicates, token, token, head_predicate.subj_token_list, None, None, conj_head.head) #MANCA UNA SUFFIX LIST elif conj_head.dep_ == "ROOT" or conj_head.dep_ is "relcl" or conj_head.dep_ is "advcl" or conj_head.tag_ in library.pos_verbs: #NON PUò CONSIDERARE I CASI COME "TRUMP HAS BEEN JUDGED GUILTY AND TAKEN TO PRISON" O "TRUMP HAS BEEN JUDGED GUILTY AND NOW IS IN PRISON" (PROVARE AD USARE IL TAG_ DEL VERBO) for cond_token in cond_tokens: cond_predicate = library.get_predicate(cond_token, predicates) if cond_predicate.dep_token == conj_head: library.make_predicate(predicates, cond_token, token) break if token_predicate is not None: if target_token in passive_tokens and token_predicate.obj_token_list == [] and token_predicate.subj_token_list == []: token_predicate.obj_token_list = target_predicate.obj_token_list elif target_token not in passive_tokens and token not in passive_tokens and token_predicate.subj_token_list == []: token_predicate.subj_token_list = target_predicate.subj_token_list else: if target_token in passive_tokens: library.make_predicate(predicates, token, token, None, target_predicate.obj_token_list) else: library.make_predicate(predicates, token, token, target_predicate.subj_token_list, None) elif conj_head.dep_ is "attr" or target_token.dep_ is "nsubj" or target_token.dep_ is "nsubjpass" or target_token.dep_ is "dobj" or target_token.dep_ is "acomp": library.add_to_same_var_list(target_token, token, variables, predicates, num_of_terms) elif conj_head.dep_ in dep_modifiers: if not library.get_predicate(token, predicates): target_predicate = library.get_predicate(target_token, predicates) library.make_predicate(predicates, token, target_predicate.dep_token) elif conj_head.dep_ is "pobj": prep_token = conj_head.head if prep_token.dep_ is "agent": prep_head = prep_token.head library.add_to_subj_list(token, prep_head, variables, predicates, num_of_terms)