def extract_sub_relations(self, mention_x: MentionDataLight, mention_y: MentionDataLight, relation: RelationType) -> RelationType: """ Check if input mentions has the given relation between them Args: mention_x: MentionDataLight mention_y: MentionDataLight relation: RelationType Returns: RelationType: relation in case mentions has given relation or RelationType.NO_RELATION_FOUND otherwise """ if relation is not RelationType.VERBOCEAN_MATCH: return RelationType.NO_RELATION_FOUND mention_x_str = mention_x.tokens_str mention_y_str = mention_y.tokens_str if StringUtils.is_pronoun( mention_x_str.lower()) or StringUtils.is_pronoun( mention_y_str.lower()): return RelationType.NO_RELATION_FOUND if self.is_verbocean_relation(mention_x, mention_y): return RelationType.VERBOCEAN_MATCH return RelationType.NO_RELATION_FOUND
def extract_sub_relations(self, mention_x: MentionDataLight, mention_y: MentionDataLight, relation: RelationType) -> RelationType: """ Check if input mentions has the given relation between them Args: mention_x: MentionDataLight mention_y: MentionDataLight relation: RelationType Returns: RelationType: relation in case mentions has given relation or RelationType.NO_RELATION_FOUND otherwise """ if relation is not RelationType.WORD_EMBEDDING_MATCH: return RelationType.NO_RELATION_FOUND mention_x_str = mention_x.tokens_str mention_y_str = mention_y.tokens_str if StringUtils.is_pronoun( mention_x_str.lower()) or StringUtils.is_pronoun( mention_y_str.lower()): if not self.contextual: return RelationType.NO_RELATION_FOUND if mention_x.mention_context is None or mention_y.mention_context is None: return RelationType.NO_RELATION_FOUND if self.is_word_embed_match(mention_x, mention_y): return RelationType.WORD_EMBEDDING_MATCH return RelationType.NO_RELATION_FOUND
def extract_sub_relations(self, mention_x: MentionDataLight, mention_y: MentionDataLight, relation: RelationType) -> RelationType: """ Check if input mentions has the given relation between them Args: mention_x: MentionDataLight mention_y: MentionDataLight relation: RelationType Returns: RelationType: relation in case mentions has given relation or RelationType.NO_RELATION_FOUND otherwise """ mention_x_str = mention_x.tokens_str mention_y_str = mention_y.tokens_str if StringUtils.is_pronoun(mention_x_str.lower()) or StringUtils.is_pronoun( mention_y_str.lower()): return RelationType.NO_RELATION_FOUND page_x = self.wordnet_impl.get_pages(mention_x) page_y = self.wordnet_impl.get_pages(mention_y) if page_x and page_y: if relation == RelationType.WORDNET_DERIVATIONALLY: return self.extract_derivation(page_x, page_y) if relation == RelationType.WORDNET_PARTIAL_SYNSET_MATCH: return self.extract_partial_synset_match(page_x, page_y) if relation == RelationType.WORDNET_SAME_SYNSET: return self.extract_same_synset_entity(page_x, page_y) return RelationType.NO_RELATION_FOUND
def extract_sub_relations(self, mention_x: MentionDataLight, mention_y: MentionDataLight, relation: RelationType) -> RelationType: """ Check if input mentions has the given relation between them Args: mention_x: MentionDataLight mention_y: MentionDataLight relation: RelationType Returns: RelationType: relation in case mentions has given relation or RelationType.NO_RELATION_FOUND otherwise """ mention_x_str = mention_x.tokens_str mention_y_str = mention_y.tokens_str if StringUtils.is_pronoun( mention_x_str.lower()) or StringUtils.is_pronoun( mention_y_str.lower()): return RelationType.NO_RELATION_FOUND if relation == RelationType.EXACT_STRING: return self.extract_exact_string(mention_x, mention_y) if relation == RelationType.FUZZY_FIT: return self.extract_fuzzy_fit(mention_x, mention_y) if relation == RelationType.FUZZY_HEAD_FIT: return self.extract_fuzzy_head_fit(mention_x, mention_y) if relation == RelationType.SAME_HEAD_LEMMA: is_same_lemma = self.extract_same_head_lemma(mention_x, mention_y) if is_same_lemma != RelationType.NO_RELATION_FOUND: return relation return RelationType.NO_RELATION_FOUND
def extract_all_relations( self, mention_x: MentionDataLight, mention_y: MentionDataLight) -> Set[RelationType]: """ Try to find if mentions has anyone or more of the relations this class support Args: mention_x: MentionDataLight mention_y: MentionDataLight Returns: Set[RelationType]: One or more of: RelationType.EXACT_STRING, RelationType.FUZZY_FIT, RelationType.FUZZY_HEAD_FIT, RelationType.SAME_HEAD_LEMMA, RelationType.SAME_HEAD_LEMMA_RELAX """ relations = set() mention_x_str = mention_x.tokens_str mention_y_str = mention_y.tokens_str if StringUtils.is_pronoun( mention_x_str.lower()) or StringUtils.is_pronoun( mention_y_str.lower()): relations.add(RelationType.NO_RELATION_FOUND) return relations relations.add(self.extract_exact_string(mention_x, mention_y)) relations.add(self.extract_fuzzy_fit(mention_x, mention_y)) relations.add(self.extract_fuzzy_head_fit(mention_x, mention_y)) relations.add(self.extract_same_head_lemma(mention_x, mention_y)) if len(relations) == 0: relations.add(RelationType.NO_RELATION_FOUND) return relations
def is_both_opposite_personal_pronouns(phrase1: str, phrase2: str) -> bool: """ check if both phrases refers to pronouns Returns: bool """ result = False if StringUtils.is_pronoun(phrase1.lower()) and StringUtils.is_pronoun( phrase2.lower()): result = True return result
def extract_all_relations( self, mention_x: MentionDataLight, mention_y: MentionDataLight) -> Set[RelationType]: """ Try to find if mentions has anyone or more of the relations this class support Args: mention_x: MentionDataLight mention_y: MentionDataLight Returns: Set[RelationType]: One or more of: RelationType.WORDNET_SAME_SYNSET_ENTITY, RelationType.WORDNET_SAME_SYNSET_EVENT, RelationType.WORDNET_PARTIAL_SYNSET_MATCH, RelationType.WORDNET_DERIVATIONALLY """ relations = set() mention_x_str = mention_x.tokens_str mention_y_str = mention_y.tokens_str if StringUtils.is_pronoun( mention_x_str.lower()) or StringUtils.is_pronoun( mention_y_str.lower()): relations.add(RelationType.NO_RELATION_FOUND) return relations page_x = self.wordnet_impl.get_pages(mention_x) page_y = self.wordnet_impl.get_pages(mention_y) if page_x and page_y: deriv_rel = self.extract_derivation(page_x, page_y) part_syn_rel = self.extract_partial_synset_match(page_x, page_y) same_syn_rel = self.extract_same_synset_entity(page_x, page_y) if deriv_rel != RelationType.NO_RELATION_FOUND: relations.add(deriv_rel) if part_syn_rel != RelationType.NO_RELATION_FOUND: relations.add(part_syn_rel) if same_syn_rel != RelationType.NO_RELATION_FOUND: relations.add(same_syn_rel) if len(relations) == 0: relations.add(RelationType.NO_RELATION_FOUND) return relations
def test_is_pronoun(): assert StringUtils.is_pronoun('anybody') assert StringUtils.is_pronoun('the') is False
def test_is_pronoun(): assert StringUtils.is_pronoun("anybody") assert StringUtils.is_pronoun("the") is False