Пример #1
0
def _get_transitive_types(resource: str, graph) -> set:
    resource_uri = clg_util.name2clg_resource(str(resource))
    clg_nodes = graph.get_nodes_for_resource(resource_uri)
    transitive_clg_nodes = (
        clg_nodes | {an
                     for n in clg_nodes
                     for an in graph.ancestors(n)}).difference(
                         {rdf_util.CLASS_OWL_THING})
    return {clg_util.clg_type2name(n) for n in transitive_clg_nodes}
Пример #2
0
 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]
Пример #3
0
 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
Пример #4
0
 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]
Пример #5
0
 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]