Skip to content

factppgraph

FaCTPPGraph

Class for running the FaCT++ reasoner (using OwlApiInterface) and postprocessing the resulting inferred ontology.

Parameters

graph : owlapi.Graph instance The graph to be inferred.

base_iri property writable

Base iri of inferred ontology.

inferred property readonly

The current inferred graph.

namespaces property readonly

Namespaces defined in the original graph.

add_base_annotations(self)

Copy base annotations from original graph to the inferred graph.

Source code in ontopy/factpluspluswrapper/factppgraph.py
def add_base_annotations(self):
    """Copy base annotations from original graph to the inferred graph."""
    base = self.base_iri
    inferred = self.inferred
    for s, p, o in self.graph.triples(
            (self.asserted_base_iri(), None, None)):
        if p == OWL.versionIRI:
            version = o.rsplit('/', 1)[-1]
            o = URIRef('%s/%s' % (base, version))
        inferred.add((base, p, o))

asserted_base_iri(self)

Returns the base iri or the original graph.

Source code in ontopy/factpluspluswrapper/factppgraph.py
def asserted_base_iri(self):
    """Returns the base iri or the original graph."""
    return URIRef(dict(self.graph.namespaces()).get('', '').rstrip('#/'))

clean_ancestors(self)

Remove redundant rdfs:subClassOf relations in inferred graph.

Source code in ontopy/factpluspluswrapper/factppgraph.py
def clean_ancestors(self):
    """Remove redundant rdfs:subClassOf relations in inferred graph."""
    inferred = self.inferred
    for s in inferred.subjects(RDF.type, OWL.Class):
        if isinstance(s, URIRef):
            parents = set(p for p in inferred.objects(s, RDFS.subClassOf)
                          if isinstance(p, URIRef))
            if len(parents) > 1:
                for parent in parents:
                    ancestors = set(inferred.transitive_objects(
                        parent, RDFS.subClassOf))
                    for p in parents:
                        if p != parent and p in ancestors:
                            t = s, RDFS.subClassOf, p
                            if t in inferred:
                                inferred.remove(t)

clean_base(self)

Remove all relations s? a owl:Ontology where s? is not base_iri.

Source code in ontopy/factpluspluswrapper/factppgraph.py
def clean_base(self):
    """Remove all relations `s? a owl:Ontology` where `s?` is not
    `base_iri`.
    """
    inferred = self.inferred
    for s, p, o in inferred.triples((None, RDF.type, OWL.Ontology)):
        inferred.remove((s, p, o))
    inferred.add((self.base_iri, RDF.type, OWL.Ontology))

inferred_graph(self)

Returns the postprocessed inferred graph.

Source code in ontopy/factpluspluswrapper/factppgraph.py
def inferred_graph(self):
    """Returns the postprocessed inferred graph."""
    self.add_base_annotations()
    self.set_namespace()
    self.clean_base()
    self.remove_nothing_is_nothing()
    self.clean_ancestors()
    return self.inferred

raw_inferred_graph(self)

Returns the raw non-postprocessed inferred ontology as a rdflib graph.

Source code in ontopy/factpluspluswrapper/factppgraph.py
def raw_inferred_graph(self):
    """Returns the raw non-postprocessed inferred ontology as a rdflib
    graph."""
    return OwlApiInterface().reason(self.graph)

remove_nothing_is_nothing(self)

Remove superfluid relation in inferred graph:

owl:Nothing rdfs:subClassOf owl:Nothing

Source code in ontopy/factpluspluswrapper/factppgraph.py
def remove_nothing_is_nothing(self):
    """Remove superfluid relation in inferred graph:

        owl:Nothing rdfs:subClassOf owl:Nothing
    """
    t = OWL.Nothing, RDFS.subClassOf, OWL.Nothing
    inferred = self.inferred
    if t in inferred:
        inferred.remove(t)

set_namespace(self)

Override namespace of inferred graph with the namespace of the original graph.

Source code in ontopy/factpluspluswrapper/factppgraph.py
def set_namespace(self):
    """Override namespace of inferred graph with the namespace of the
    original graph.
    """
    inferred = self.inferred
    for k, v in self.namespaces.items():
        inferred.namespace_manager.bind(k, v, override=True, replace=True)

FactPPError

Postprocessing error after reasoning with FaCT++.

Back to top