Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ owlrl*.tar.gz

# Mac
.DS_Store
/.venv/
14 changes: 13 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This package is a Python library that also contains a couple of scripts:
Installation
------------

This package requires RDFLib 7.1.3 as its only dependency and it can be installed from the Python Package index in the usual way:
This package requires RDFLib 7.5.0 or newer. It can be installed from the Python Package index in the usual way:

::

Expand All @@ -40,6 +40,10 @@ or

poetry add owlrl

Optional: run the closure against an `Oxigraph <https://pyoxigraph.readthedocs.io/>`_ in-memory store by installing the extra::

pip install owlrl[oxigraph]


Use
---
Expand All @@ -54,6 +58,14 @@ For details on RDFS, see the `RDF Semantics Specification`_; for OWL 2 RL, see t
View the **OWL-RL documentation** online: http://owl-rl.readthedocs.io/


Oxigraph store (optional)
~~~~~~~~~~~~~~~~~~~~~~~~~

After installing the ``oxigraph`` extra (see **Installation** above), you may pass a `PyOxigraph <https://pyoxigraph.readthedocs.io/>`_ ``Store`` into ``owlrl.DeductiveClosure(...).expand(...)`` and related closure entry points wherever you would normally pass an RDFLib ``Graph`` or ``Dataset``. Inferred triples can still be written to a separate named graph on that store via the ``destination`` argument, as with RDFLib.

This integration is provided for **compatibility** (for example, keeping the rest of an application on Oxigraph) rather than for speed. Converting terms to and from RDFLib objects removes most of the performance benefit of Oxigraph, and this project still uses RDFLib types and logic internally for all inference steps.


License
-------
This software is released under the W3C© SOFTWARE NOTICE AND LICENSE. See `LICENSE.txt <LICENSE.txt>`_.
Expand Down
2 changes: 1 addition & 1 deletion owlrl/AxiomaticTriples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Axiomatic triples to be (possibly) added to the final graph.

**Requires**: `RDFLib`_, 4.0.0 and higher.
**Requires**: `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

Expand Down
64 changes: 40 additions & 24 deletions owlrl/Closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
The generic superclasses for various rule based semantics and the possible extensions.

**Requires**: `RDFLib`_, 4.0.0 and higher.
**Requires**: `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

Expand All @@ -25,11 +25,13 @@
__contact__ = "Ivan Herman, ivan@w3.org"
__license__ = "W3C® SOFTWARE NOTICE AND LICENSE, http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231"

from typing import Union
from typing import Union, Any

import rdflib
from rdflib.namespace import RDF
from rdflib import BNode, Literal, Graph, Dataset

from owlrl.graph_abstraction import DataGraph
from .Namespaces import ERRNS

try:
Expand Down Expand Up @@ -91,59 +93,73 @@ class Core:
"""

# noinspection PyUnusedLocal
def __init__(self, graph: Graph, axioms, daxioms, rdfs: bool = False, destination: Union[None, Graph] = None):
def __init__(self, graph: Union[DataGraph,Graph,Any], axioms, daxioms, rdfs: bool = False, destination: Union[DataGraph,Graph,Any] = None):
"""
The parameter descriptions here are from the old documentation.

@param graph: the RDF graph to be extended
@type graph: Graph
@type graph: DataGraph
@param axioms: whether axioms should be added or not
@type axioms: boolean
@param daxioms: whether datatype axioms should be added or not
@type daxioms: boolean
@param rdfs: whether RDFS inference is also done (used in subclassed only)
@type rdfs: boolean
@param destination: the destination graph to which the results are written. If None, use the source graph.
@type destination: Graph
@param destination: the destination graph to which the results are written. If None, use the source datagraph.
@type destination: DataGraph
"""
self._debug = debugGlobal

# Calculate the maximum 'n' value for the '_i' type predicates (see Horst's paper)
n = 1
maxnum = 0
cont = True
while cont:
cont = False
predicate = RDF[("_%d" % n)]
for (s, p, o) in graph.triples((None, predicate, None)):
# there is at least one if we got here
maxnum = n
n += 1
cont = True
self.IMaxNum = maxnum
if isinstance(graph, (Dataset, ConjunctiveGraph)):
graph.default_union = True

if isinstance(graph, DataGraph):
graph.default_union = True
elif not isinstance(graph, Graph):
# Wrap a RDFlib Graph and Oxigraph Store in a DataGraph abstraction layer
graph = DataGraph(graph)
graph.default_union = True

self.graph = graph
if isinstance(self.graph, (Dataset, ConjunctiveGraph)):
self.graph.default_union = True

if destination is None:
if isinstance(graph, (Dataset, ConjunctiveGraph)):
self.destination = graph.default_context
else:
self.destination = graph
elif isinstance(destination, DataGraph):
self.destination = destination
else:
if isinstance(destination, (str, rdflib.URIRef)):
if isinstance(graph, (Dataset, ConjunctiveGraph)):
if isinstance(graph, (Dataset, ConjunctiveGraph, DataGraph)):
self.destination = graph.get_context(destination)
else:
raise ValueError("URIRef destinations are only supported for Datasets and ConjunctiveGraphs")
raise ValueError(
"URIRef or string destinations are only supported for Dataset, "
"ConjunctiveGraph, or Oxigraph/DataGraph instances"
)
else:
# destination is a rdflib Graph
source_store = self.graph.store
dest_store = destination.store
if source_store is not dest_store:
raise ValueError("The source and destination graphs share the same backing store")
raise ValueError("The source and destination graphs must share the same backing store")
self.destination = destination

# Calculate the maximum 'n' value for the '_i' type predicates (see Horst's paper)
n = 1
maxnum = 0
cont = True
while cont:
cont = False
predicate = RDF[("_%d" % n)]
for (s, p, o) in graph.triples((None, predicate, None)):
# there is at least one if we got here
maxnum = n
n += 1
cont = True
self.IMaxNum = maxnum

self.axioms = axioms
self.daxioms = daxioms

Expand Down
2 changes: 1 addition & 1 deletion owlrl/CombinedClosure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
triples concerning the container membership properties). Using this closure class the
OWL 2 RL implementation becomes a full extension of RDFS.

**Requires**: `RDFLib`_, 4.0.0 and higher.
**Requires**: `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

Expand Down
2 changes: 1 addition & 1 deletion owlrl/DatatypeHandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
python datatype (or return the original string if this is not possible) which will be used, e.g.,
for comparisons (equalities). If the lexical value constraints are not met, exceptions are raised.

**Requires**: `RDFLib`_, 4.0.0 and higher.
**Requires**: `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

Expand Down
2 changes: 1 addition & 1 deletion owlrl/OWLRL.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
removed from the graph before serialization to produce 'standard' RDF (which is o.k. for RL, too, because the
consequent triples are all right, generalized triples might have had a role in the deduction steps only).

**Requires**: `RDFLib`_, 4.0.0 and higher.
**Requires**: `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

Expand Down
2 changes: 1 addition & 1 deletion owlrl/OWLRLExtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
1. self restriction 1: :code:`?z owl:hasSelf ?x. ?x owl:onProperty ?p. ?y rdf:type ?z. => ?y ?p ?y.`
2. self restriction 2: :code:`?z owl:hasSelf ?x. ?x owl:onProperty ?p. ?y ?p ?y. => ?y rdf:type ?z.`

**Requires**: `RDFLib`_, 4.0.0 and higher.
**Requires**: `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

Expand Down
2 changes: 1 addition & 1 deletion owlrl/RDFSClosure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
introductory text).


**Requires**: `RDFLib`_, 4.0.0 and higher.
**Requires**: `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

Expand Down
2 changes: 1 addition & 1 deletion owlrl/RestrictedDatatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
- checking whether a facet is of a datatype that is allowed for that facet
- handling of non-literals in the facets (ie, if the resource is defined to be of type literal, but whose value is defined via a separate :code:`owl:sameAs` somewhere else)

**Requires**: `RDFLib`_, 4.0.0 and higher.
**Requires**: `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

Expand Down
2 changes: 1 addition & 1 deletion owlrl/XsdDatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Lists of XSD datatypes and their mutual relationships

**Requires**: `RDFLib`_, 4.0.0 and higher.
**Requires**: `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

Expand Down
8 changes: 4 additions & 4 deletions owlrl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@


**Requires**:
* `RDFLib`_, 4.0.0 and higher.
* `RDFLib`_, 7.5.0 and higher.

.. _RDFLib: https://github.com/RDFLib/rdflib

* `rdflib_jsonld`_
* Optional: `PyOxigraph`_ (install with ``pip install owlrl[oxigraph]``) to use an Oxigraph store as the graph backend.

.. _rdflib_jsonld: https://github.com/RDFLib/rdflib-jsonld
.. _PyOxigraph: https://pyoxigraph.readthedocs.io/

**License**: This software is available for use under the `W3C Software License`_

Expand All @@ -155,7 +155,7 @@
"""

# Examples: LangString is disjoint from String
__version__ = "7.1.4"
__version__ = "7.5.0"
__author__ = "Ivan Herman"
__contact__ = "Ivan Herman, ivan@w3.org"
__license__ = "W3C® SOFTWARE NOTICE AND LICENSE, http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231"
Expand Down
Loading