nlp_architect.data.cdc_resources.relations package
Submodules
nlp_architect.data.cdc_resources.relations.computed_relation_extraction module
-
class
nlp_architect.data.cdc_resources.relations.computed_relation_extraction.
ComputedRelationExtraction
[source] Bases:
nlp_architect.data.cdc_resources.relations.relation_extraction.RelationExtraction
Extract Relation between two mentions according to computation and rule based algorithms
-
extract_all_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → Set[nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType][source] Try to find if mentions has anyone or more of the relations this class support
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: - One or more of: RelationType.EXACT_STRING, RelationType.FUZZY_FIT,
RelationType.FUZZY_HEAD_FIT, RelationType.SAME_HEAD_LEMMA, RelationType.SAME_HEAD_LEMMA_RELAX
Return type: Set[RelationType]
-
static
extract_exact_string
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has exact string relation
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: RelationType.EXACT_STRING or RelationType.NO_RELATION_FOUND
-
static
extract_fuzzy_fit
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has fuzzy fit relation
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: RelationType.FUZZY_FIT or RelationType.NO_RELATION_FOUND
-
static
extract_fuzzy_head_fit
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has fuzzy head fit relation
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: RelationType.FUZZY_HEAD_FIT or RelationType.NO_RELATION_FOUND
-
static
extract_same_head_lemma
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has same head lemma relation
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: RelationType.SAME_HEAD_LEMMA or RelationType.NO_RELATION_FOUND
-
extract_sub_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight, relation: nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has the given relation between them
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
- relation – RelationType
Returns: - relation in case mentions has given relation or
RelationType.NO_RELATION_FOUND otherwise
Return type:
-
nlp_architect.data.cdc_resources.relations.referent_dict_relation_extraction module
-
class
nlp_architect.data.cdc_resources.relations.referent_dict_relation_extraction.
ReferentDictRelationExtraction
(method: nlp_architect.data.cdc_resources.relations.relation_types_enums.OnlineOROfflineMethod = <OnlineOROfflineMethod.ONLINE: 'online'>, ref_dict: str = None)[source] Bases:
nlp_architect.data.cdc_resources.relations.relation_extraction.RelationExtraction
-
extract_all_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → Set[nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType][source]
-
extract_sub_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight, relation: nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has the given relation between them
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
- relation – RelationType
Returns: - relation in case mentions has given relation or
RelationType.NO_RELATION_FOUND otherwise
Return type:
-
static
get_supported_relations
()[source] Return all supported relations by this class
Returns: List[RelationType]
-
is_referent_dict
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → bool[source] Check if input mentions has referent dictionary relation between them
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: bool
-
nlp_architect.data.cdc_resources.relations.relation_extraction module
-
class
nlp_architect.data.cdc_resources.relations.relation_extraction.
RelationExtraction
[source] Bases:
object
-
extract_relation
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight, relation: nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Base Class Check if Sub class support given relation before executing the sub class
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
- relation – RelationType
Returns: - relation in case mentions has given relation and
RelationType.NO_RELATION_FOUND otherwise
Return type:
-
extract_sub_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight, relation: nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source]
-
nlp_architect.data.cdc_resources.relations.relation_types_enums module
-
class
nlp_architect.data.cdc_resources.relations.relation_types_enums.
EmbeddingMethod
[source] Bases:
enum.Enum
An enumeration.
-
ELMO
= 'elmo'
-
ELMO_OFFLINE
= 'elmo_offline'
-
GLOVE
= 'glove'
-
GLOVE_OFFLINE
= 'glove_offline'
-
-
class
nlp_architect.data.cdc_resources.relations.relation_types_enums.
OnlineOROfflineMethod
[source] Bases:
enum.Enum
An enumeration.
-
OFFLINE
= 'offline'
-
ONLINE
= 'online'
-
-
class
nlp_architect.data.cdc_resources.relations.relation_types_enums.
RelationType
[source] Bases:
enum.Enum
An enumeration.
-
EXACT_STRING
= 8
-
FUZZY_FIT
= 9
-
FUZZY_HEAD_FIT
= 10
-
NO_RELATION_FOUND
= 0
-
OTHER
= 21
-
REFERENT_DICT
= 18
-
SAME_HEAD_LEMMA
= 11
-
VERBOCEAN_MATCH
= 13
-
WIKIPEDIA_ALIASES
= 2
-
WIKIPEDIA_BE_COMP
= 7
-
WIKIPEDIA_CATEGORY
= 5
-
WIKIPEDIA_DISAMBIGUATION
= 3
-
WIKIPEDIA_PART_OF_SAME_NAME
= 4
-
WIKIPEDIA_REDIRECT_LINK
= 1
-
WIKIPEDIA_TITLE_PARENTHESIS
= 6
-
WITHIN_DOC_COREF
= 20
-
WORDNET_DERIVATIONALLY
= 14
-
WORDNET_PARTIAL_SYNSET_MATCH
= 15
-
WORDNET_SAME_SYNSET
= 17
-
WORD_EMBEDDING_MATCH
= 19
-
nlp_architect.data.cdc_resources.relations.verbocean_relation_extraction module
-
class
nlp_architect.data.cdc_resources.relations.verbocean_relation_extraction.
VerboceanRelationExtraction
(method: nlp_architect.data.cdc_resources.relations.relation_types_enums.OnlineOROfflineMethod = <OnlineOROfflineMethod.ONLINE: 'online'>, vo_file: str = None)[source] Bases:
nlp_architect.data.cdc_resources.relations.relation_extraction.RelationExtraction
-
extract_all_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → Set[nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType][source]
-
extract_sub_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight, relation: nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has the given relation between them
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
- relation – RelationType
Returns: - relation in case mentions has given relation or
RelationType.NO_RELATION_FOUND otherwise
Return type:
-
static
get_supported_relations
()[source] Return all supported relations by this class
Returns: List[RelationType]
-
is_verbocean_relation
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → bool[source] Check if input mentions has VerbOcean relation between them
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: bool
-
nlp_architect.data.cdc_resources.relations.wikipedia_relation_extraction module
-
class
nlp_architect.data.cdc_resources.relations.wikipedia_relation_extraction.
WikipediaRelationExtraction
(method: nlp_architect.data.cdc_resources.relations.relation_types_enums.WikipediaSearchMethod = <WikipediaSearchMethod.ONLINE: 'online'>, wiki_file: str = None, host: str = None, port: int = None, index: str = None, filter_pronouns: bool = True, filter_time_data: bool = True)[source] Bases:
nlp_architect.data.cdc_resources.relations.relation_extraction.RelationExtraction
-
static
extract_aliases
(pages1: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, pages2: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, titles1: Set[str], titles2: Set[str]) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has aliases relation
Parameters: - pages1 – WikipediaPages
- pages2 – WikipediaPage
- titles1 – Set[str]
- titles2 – Set[str]
Returns: RelationType.WIKIPEDIA_ALIASES or RelationType.NO_RELATION_FOUND
-
extract_all_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → Set[nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType][source] Try to find if mentions has anyone or more of the relations this class support
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: - One or more of: RelationType.WIKIPEDIA_BE_COMP,
RelationType.WIKIPEDIA_TITLE_PARENTHESIS, RelationType.WIKIPEDIA_DISAMBIGUATION, RelationType.WIKIPEDIA_CATEGORY, RelationType.WIKIPEDIA_REDIRECT_LINK, RelationType.WIKIPEDIA_ALIASES, RelationType.WIKIPEDIA_PART_OF_SAME_NAME
Return type: Set[RelationType]
-
static
extract_be_comp
(pages1: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, pages2: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, titles1: Set[str], titles2: Set[str]) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has be-comp/is-a relation
Parameters: - pages1 – WikipediaPages
- pages2 – WikipediaPage
- titles1 – Set[str]
- titles2 – Set[str]
Returns: RelationType.WIKIPEDIA_BE_COMP or RelationType.NO_RELATION_FOUND
-
static
extract_category
(pages1: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, pages2: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, titles1: Set[str], titles2: Set[str]) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has category relation
Parameters: - pages1 – WikipediaPages
- pages2 – WikipediaPage
- titles1 – Set[str]
- titles2 – Set[str]
Returns: RelationType.WIKIPEDIA_CATEGORY or RelationType.NO_RELATION_FOUND
-
static
extract_disambig
(pages1: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, pages2: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, titles1: Set[str], titles2: Set[str]) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has disambiguation relation
Parameters: - pages1 – WikipediaPages
- pages2 – WikipediaPage
- titles1 – Set[str]
- titles2 – Set[str]
Returns: RelationType.WIKIPEDIA_DISAMBIGUATION or RelationType.NO_RELATION_FOUND
-
static
extract_parenthesis
(pages1: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, pages2: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, titles1: Set[str], titles2: Set[str]) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has parenthesis relation
Parameters: - pages1 – WikipediaPages
- pages2 – WikipediaPage
- titles1 – Set[str]
- titles2 – Set[str]
Returns: RelationType.WIKIPEDIA_TITLE_PARENTHESIS or RelationType.NO_RELATION_FOUND
-
extract_sub_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight, relation: nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has the given relation between them
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
- relation – RelationType
Returns: - relation in case mentions has given relation or
RelationType.NO_RELATION_FOUND otherwise
Return type:
Get all WikipediaPages pages related with this mention string
Parameters: mention_str – str Returns: WikipediaPages
-
static
get_supported_relations
() → List[nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType][source] Return all supported relations by this class
Returns: List[RelationType]
-
static
is_both_data_or_time
(mention1: nlp_architect.common.cdc.mention_data.MentionDataLight, mention2: nlp_architect.common.cdc.mention_data.MentionDataLight) → bool[source] check if both phrases refers to time or date
Returns: bool
-
static
is_both_opposite_personal_pronouns
(phrase1: str, phrase2: str) → bool[source] check if both phrases refers to pronouns
Returns: bool
-
is_part_of_same_name
(pages1: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, pages2: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages) → bool[source] Check if input mentions has part of same name relation (eg: page1=John, page2=Smith)
Parameters: - pages1 – WikipediaPages
- pages2 – WikipediaPage
Returns: bool
-
static
is_redirect_same
(pages1: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages, pages2: nlp_architect.data.cdc_resources.data_types.wiki.wikipedia_pages.WikipediaPages) → bool[source] Check if input mentions has same wikipedia redirect page
Parameters: - pages1 – WikipediaPages
- pages2 – WikipediaPage
Returns: bool
-
static
nlp_architect.data.cdc_resources.relations.within_doc_coref_extraction module
-
class
nlp_architect.data.cdc_resources.relations.within_doc_coref_extraction.
WithinDocCoref
(wd_file: str)[source] Bases:
nlp_architect.data.cdc_resources.relations.relation_extraction.RelationExtraction
-
static
create_ment_id
(mention_x: nlp_architect.common.cdc.mention_data.MentionData, mention_y: nlp_architect.common.cdc.mention_data.MentionData) → str[source]
-
extract_all_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionData, mention_y: nlp_architect.common.cdc.mention_data.MentionData) → Set[nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType][source]
-
extract_sub_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionData, mention_y: nlp_architect.common.cdc.mention_data.MentionData, relation: nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has the given relation between them
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
- relation – RelationType
Returns: - relation in case mentions has given relation or
RelationType.NO_RELATION_FOUND otherwise
Return type:
-
extract_within_coref
(mention: nlp_architect.common.cdc.mention_data.MentionData) → List[str][source]
-
static
nlp_architect.data.cdc_resources.relations.word_embedding_relation_extraction module
-
class
nlp_architect.data.cdc_resources.relations.word_embedding_relation_extraction.
WordEmbeddingRelationExtraction
(method: nlp_architect.data.cdc_resources.relations.relation_types_enums.EmbeddingMethod = <EmbeddingMethod.GLOVE: 'glove'>, glove_file: str = None, elmo_file: str = None, cos_accepted_dist: float = 0.7)[source] Bases:
nlp_architect.data.cdc_resources.relations.relation_extraction.RelationExtraction
-
extract_all_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → Set[nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType][source]
-
extract_sub_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight, relation: nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has the given relation between them
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
- relation – RelationType
Returns: - relation in case mentions has given relation or
RelationType.NO_RELATION_FOUND otherwise
Return type:
-
static
get_supported_relations
() → List[nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType][source] Return all supported relations by this class
Returns: List[RelationType]
-
is_word_embed_match
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight)[source] Check if input mentions Word Embedding cosine distance below above 0.65
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: bool
-
nlp_architect.data.cdc_resources.relations.wordnet_relation_extraction module
-
class
nlp_architect.data.cdc_resources.relations.wordnet_relation_extraction.
WordnetRelationExtraction
(method: nlp_architect.data.cdc_resources.relations.relation_types_enums.OnlineOROfflineMethod = <OnlineOROfflineMethod.ONLINE: 'online'>, wn_file: str = None)[source] Bases:
nlp_architect.data.cdc_resources.relations.relation_extraction.RelationExtraction
-
extract_all_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight) → Set[nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType][source] Try to find if mentions has anyone or more of the relations this class support
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
Returns: - One or more of: RelationType.WORDNET_SAME_SYNSET_ENTITY,
RelationType.WORDNET_SAME_SYNSET_EVENT, RelationType.WORDNET_PARTIAL_SYNSET_MATCH, RelationType.WORDNET_DERIVATIONALLY
Return type: Set[RelationType]
-
static
extract_derivation
(page_x: nlp_architect.data.cdc_resources.data_types.wn.wordnet_page.WordnetPage, page_y: nlp_architect.data.cdc_resources.data_types.wn.wordnet_page.WordnetPage) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has derivation relation
Parameters: - page_x – WordnetPage
- page_y – WordnetPage
Returns: RelationType.WORDNET_DERIVATIONALLY or RelationType.NO_RELATION_FOUND
-
static
extract_partial_synset_match
(page_x: nlp_architect.data.cdc_resources.data_types.wn.wordnet_page.WordnetPage, page_y: nlp_architect.data.cdc_resources.data_types.wn.wordnet_page.WordnetPage) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has partial synset relation
Parameters: - page_x – WordnetPage
- page_y – WordnetPage
Returns: RelationType.WORDNET_PARTIAL_SYNSET_MATCH or RelationType.NO_RELATION_FOUND
-
static
extract_same_synset_entity
(page_x: nlp_architect.data.cdc_resources.data_types.wn.wordnet_page.WordnetPage, page_y: nlp_architect.data.cdc_resources.data_types.wn.wordnet_page.WordnetPage) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has same synset relation for entity mentions
Parameters: - page_x – WordnetPage
- page_y – WordnetPage
Returns: RelationType.WORDNET_SAME_SYNSET_ENTITY or RelationType.NO_RELATION_FOUND
-
extract_sub_relations
(mention_x: nlp_architect.common.cdc.mention_data.MentionDataLight, mention_y: nlp_architect.common.cdc.mention_data.MentionDataLight, relation: nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType) → nlp_architect.data.cdc_resources.relations.relation_types_enums.RelationType[source] Check if input mentions has the given relation between them
Parameters: - mention_x – MentionDataLight
- mention_y – MentionDataLight
- relation – RelationType
Returns: - relation in case mentions has given relation or
RelationType.NO_RELATION_FOUND otherwise
Return type:
-