Пример #1
0
    def crawl_graph(self):
        ret = {}
        for ontology_property,p,o in self.graph.triples((None, None, RDF.Property)):
            for s,p,domain_class in self.graph.triples((ontology_property, RDFS.domain, None)):
                domain_class = Resource(self.graph, domain_class)
                for domain_subclass in domain_class.transitive_subjects(RDFS.subClassOf):
                    if domain_subclass.identifier not in ret:
                        ret[domain_subclass.identifier] = {'down':[], 'up':[]}
                    for s,p,range_class in self.graph.triples((ontology_property, RDFS.range, None)):
                        ret[domain_subclass.identifier]['down'].append({
                            'ontology_property':ontology_property,
                            'ontology_classes':self.get_subclasses(range_class)
                        })

            for s,p,range_class in self.graph.triples((ontology_property, RDFS.range, None)):
                range_class = Resource(self.graph, range_class)
                for range_subclass in range_class.transitive_subjects(RDFS.subClassOf):
                    if range_subclass.identifier not in ret:
                        ret[range_subclass.identifier] = {'down':[], 'up':[]}
                    for s,p,o in self.graph.triples((ontology_property, RDFS.domain, None)):
                        ret[range_subclass.identifier]['up'].append({
                            'ontology_property':ontology_property,
                            'ontology_classes':self.get_subclasses(o)
                        })
        return ret
Пример #2
0
    def crawl_graph(self):
        ret = {}
        for ontology_property,p,o in self.graph.triples((None, None, RDF.Property)):
            for s,p,domain_class in self.graph.triples((ontology_property, RDFS.domain, None)):
                domain_class = Resource(self.graph, domain_class)
                for domain_subclass in domain_class.transitive_subjects(RDFS.subClassOf):
                    if domain_subclass.identifier not in ret:
                        ret[domain_subclass.identifier] = {'down':[], 'up':[]}
                    for s,p,range_class in self.graph.triples((ontology_property, RDFS.range, None)):
                        ret[domain_subclass.identifier]['down'].append({
                            'ontology_property':ontology_property,
                            'ontology_classes':self.get_subclasses(range_class)
                        })

            for s,p,range_class in self.graph.triples((ontology_property, RDFS.range, None)):
                range_class = Resource(self.graph, range_class)
                for range_subclass in range_class.transitive_subjects(RDFS.subClassOf):
                    if range_subclass.identifier not in ret:
                        ret[range_subclass.identifier] = {'down':[], 'up':[]}
                    for s,p,o in self.graph.triples((ontology_property, RDFS.domain, None)):
                        ret[range_subclass.identifier]['up'].append({
                            'ontology_property':ontology_property,
                            'ontology_classes':self.get_subclasses(o)
                        })
        return ret
Пример #3
0
 def get_subclasses(self, ontology_class):
     if ontology_class not in self.subclass_cache:
         ontology_class_resource = Resource(self.graph, ontology_class)
         self.subclass_cache[ontology_class] = [
             subclass.identifier for subclass in
             ontology_class_resource.transitive_subjects(RDFS.subClassOf)
         ]
     return self.subclass_cache[ontology_class]
Пример #4
0
 def get_subclasses(self, ontology_class):
     if ontology_class not in self.subclass_cache:
         ontology_class_resource = Resource(self.graph, ontology_class)
         self.subclass_cache[ontology_class] = [subclass.identifier for subclass in ontology_class_resource.transitive_subjects(RDFS.subClassOf)]
     return self.subclass_cache[ontology_class]