def is_redirect_same(pages1: WikipediaPages, pages2: WikipediaPages) -> bool: """ Check if input mentions has same wikipedia redirect page Args: pages1: WikipediaPages pages2: WikipediaPage Returns: bool """ for page1 in pages1.get_pages(): for page2 in pages2.get_pages(): if page1.pageid > 0 and page2.pageid > 0: if page1.pageid == page2.pageid: return True return False
def get_phrase_related_pages(self, mention_str: str) -> WikipediaPages: """ Get all WikipediaPages pages related with this mention string Args: mention_str: str Returns: WikipediaPages """ pages = self.pywiki_impl.get_pages(mention_str.strip()) ret_pages = WikipediaPages() if pages: for search_page in pages: if search_page.page_result.pageid != 0: ret_pages.add_page(search_page.page_result) return ret_pages
def extract_aliases(pages1: WikipediaPages, pages2: WikipediaPages, titles1: Set[str], titles2: Set[str]) -> RelationType: """ Check if input mentions has aliases relation Args: pages1: WikipediaPages pages2: WikipediaPage titles1: Set[str] titles2: Set[str] Returns: RelationType.WIKIPEDIA_ALIASES or RelationType.NO_RELATION_FOUND """ relation = RelationType.NO_RELATION_FOUND if bool(pages1.get_and_set_all_aliases() & titles2): relation = RelationType.WIKIPEDIA_ALIASES elif bool(pages2.get_and_set_all_aliases() & titles1): relation = RelationType.WIKIPEDIA_ALIASES return relation
def extract_disambig(pages1: WikipediaPages, pages2: WikipediaPages, titles1: Set[str], titles2: Set[str]) -> RelationType: """ Check if input mentions has disambiguation relation Args: pages1: WikipediaPages pages2: WikipediaPage titles1: Set[str] titles2: Set[str] Returns: RelationType.WIKIPEDIA_DISAMBIGUATION or RelationType.NO_RELATION_FOUND """ relation = RelationType.NO_RELATION_FOUND if bool(pages1.get_and_set_all_disambiguation() & titles2): relation = RelationType.WIKIPEDIA_DISAMBIGUATION elif bool(pages2.get_and_set_all_disambiguation() & titles1): relation = RelationType.WIKIPEDIA_DISAMBIGUATION return relation
def extract_category(pages1: WikipediaPages, pages2: WikipediaPages, titles1: Set[str], titles2: Set[str]) -> RelationType: """ Check if input mentions has category relation Args: pages1: WikipediaPages pages2: WikipediaPage titles1: Set[str] titles2: Set[str] Returns: RelationType.WIKIPEDIA_CATEGORY or RelationType.NO_RELATION_FOUND """ relation = RelationType.NO_RELATION_FOUND if bool(pages1.get_and_set_all_categories() & titles2): relation = RelationType.WIKIPEDIA_CATEGORY elif bool(pages2.get_and_set_all_categories() & titles1): relation = RelationType.WIKIPEDIA_CATEGORY return relation
def extract_be_comp(pages1: WikipediaPages, pages2: WikipediaPages, titles1: Set[str], titles2: Set[str]) -> RelationType: """ Check if input mentions has be-comp/is-a relation Args: pages1: WikipediaPages pages2: WikipediaPage titles1: Set[str] titles2: Set[str] Returns: RelationType.WIKIPEDIA_BE_COMP or RelationType.NO_RELATION_FOUND """ relation = RelationType.NO_RELATION_FOUND if bool(pages1.get_and_set_be_comp() & titles2): relation = RelationType.WIKIPEDIA_BE_COMP elif bool(pages2.get_and_set_be_comp() & titles1): relation = RelationType.WIKIPEDIA_BE_COMP return relation
def extract_parenthesis(pages1: WikipediaPages, pages2: WikipediaPages, titles1: Set[str], titles2: Set[str]) -> RelationType: """ Check if input mentions has parenthesis relation Args: pages1: WikipediaPages pages2: WikipediaPage titles1: Set[str] titles2: Set[str] Returns: RelationType.WIKIPEDIA_TITLE_PARENTHESIS or RelationType.NO_RELATION_FOUND """ relation = RelationType.NO_RELATION_FOUND if bool(pages1.get_and_set_parenthesis() & titles2): relation = RelationType.WIKIPEDIA_TITLE_PARENTHESIS elif bool(pages2.get_and_set_parenthesis() & titles1): relation = RelationType.WIKIPEDIA_TITLE_PARENTHESIS return relation