def clean_for_merged_wikipedia_node_to_constraint_node(self, node): # todo: doing this background property_dict = dict(node) clean_property_dict = {} clean_property_dict["site:enwiki"] = property_dict["site:enwiki"] title_from_url = clean_property_dict["site:enwiki"].split("/")[-1] clean_property_dict["name"] = wiki_title(title_from_url) return clean_property_dict
def wikiLinks(text, language="it"): """ This function will get an string as a parameter and will return a list of all found entities. """ listOfLinks = [] obj = tagme.Annotation_mentions(text) for namedIdentity in obj.keys(): norm_title = tagme.normalize_title(namedIdentity) wikiTitle = tagme.wiki_title(norm_title) url = tagme.title_to_uri(wikiTitle, lang=language) listOfLinks.append(url) return listOfLinks
def create_wikipedia_item_entity_by_url(self, url): if url.startswith("https://en.wikipedia.org/") == False: return None accessor = DefaultGraphAccessor(self) node = accessor.get_node_by_wikipedia_link(url) if node is None: property_dict = { "name": wiki_title(url.split("/")[-1]), "url": url, "site:enwiki": url } if "(" in property_dict["name"]: alias = [(property_dict["name"].split(" ("))[0]] property_dict["alias"] = alias node = NodeBuilder().add_entity_label().add_label( "wikipedia").add_property(**property_dict).build() self.graph.merge(node) _logger.info("create wikipedia node" + str(property_dict)) return node
("Italy", "BAD ENTITY NAME")]) print(resp) for rel in resp.relatedness: print(rel) # Access the relatedness response as a dictionary. resp_dict = dict(resp) print("Relatedness between Italy and Germany: ", resp_dict[("Italy", "Germany")]) # Find relatedness between one pair of entities, by wikipedia id resp = tagme.relatedness_wid((31717, 534366)) print(resp) for rel in resp.relatedness: print(rel) # Find relatedness between pairs of entities, by wikipedia id resp = tagme.relatedness_wid([(534366, 534366 + a) for a in range(1010)]) print(resp) for rel in resp.relatedness: print(rel) if __name__ == "__main__": tagme.GCUBE_TOKEN = sys.argv[1] assert tagme.normalize_title(" barack Obama ") == "Barack_Obama" assert tagme.title_to_uri( " barack Obama ") == "https://en.wikipedia.org/wiki/Barack_Obama" assert tagme.wiki_title("Barack_Obama") == ("Barack Obama") main()