def get_entity_graph() -> CaLiGraph: """Retrieve CaLiGraph with all entities extracted from listings.""" graph = get_axiom_graph() listing.get_page_entities( graph) # extract entities from listings all over Wikipedia graph.enable_listing_resources( ) # finally, enable use of the extracted listing resources in the graph return graph
def get_altlabels(self, item: str) -> set: """Return alternative labels for a CaLiGraph resource.""" if not clg_util.is_clg_resource(item): return set() if not self._resource_altlabels and self.use_listing_resources: for res, res_data in listing.get_page_entities(self).items(): self._resource_altlabels[clg_util.name2clg_resource( res)].update(res_data['labels']) return self._resource_altlabels[item]
def get_resource_provenance(self, resource: str) -> set: """Return provenance information of a resource (i.e. which categories and lists have been used to extract it).""" if not self._resource_provenance: for node in self.nodes: for cat in self.get_category_parts(node): for res in cat_store.get_resources(cat): self._resource_provenance[ clg_util.dbp_resource2clg_resource(res)].add(cat) if self.use_listing_resources: for res, res_data in listing.get_page_entities(self).items(): self._resource_provenance[clg_util.name2clg_resource( res)].update({ dbp_util.name2resource(o) for o in res_data['origins'] }) return self._resource_provenance[resource]
def get_resources_from_listings(self, node: str) -> set: if not self._node_listing_resources: for res, res_data in listing.get_page_entities(self).items(): res_nodes = { clg_util.name2clg_type(t) for t in res_data['types'] } res_nodes.update({ n for o in res_data['origins'] for n in self.get_nodes_for_part(dbp_util.name2resource(o)) }) res_uri = clg_util.name2clg_resource(res) for n in res_nodes: self._node_listing_resources[n].add(res_uri) return self._node_listing_resources[node]
def get_all_relations(self) -> set: """Return all relations in CaLiGraph.""" if not self._resource_relations: # add relations from axioms for node in self.nodes: for pred, val in self.get_axioms(node): self._resource_relations.update({ (res, pred, val) for res in self.get_resources(node) }) # add relations from listings if self.use_listing_resources: for res, res_data in listing.get_page_entities(self).items(): res_uri = clg_util.name2clg_resource(res) self._resource_relations.update( (res_uri, clg_util.name2clg_type(p), clg_util.name2clg_resource(o)) for p, o in res_data['out']) self._resource_relations.update( (clg_util.name2clg_resource(s), clg_util.name2clg_type(p), res_uri) for p, s in res_data['in']) return self._resource_relations