diff --git a/docs/source/Closure.rst b/docs/source/Closure.rst index 755344c..fd054b3 100644 --- a/docs/source/Closure.rst +++ b/docs/source/Closure.rst @@ -5,4 +5,4 @@ Closure :members: :undoc-members: :inherited-members: - :show-inheritance: \ No newline at end of file + :show-inheritance: diff --git a/docs/source/owlrl.rst b/docs/source/OWLRL.rst similarity index 72% rename from docs/source/owlrl.rst rename to docs/source/OWLRL.rst index 48099de..5254ab1 100644 --- a/docs/source/owlrl.rst +++ b/docs/source/OWLRL.rst @@ -1,7 +1,7 @@ -owlrl +OWLRL ===== -.. automodule:: owlrl +.. automodule:: owlrl.OWLRL :members: :undoc-members: :inherited-members: diff --git a/docs/source/OWLRLExtras.rst b/docs/source/OWLRLExtras.rst index f7fd678..185257c 100644 --- a/docs/source/OWLRLExtras.rst +++ b/docs/source/OWLRLExtras.rst @@ -5,4 +5,6 @@ OWLRLExtras :members: :undoc-members: :inherited-members: - :show-inheritance: \ No newline at end of file + :show-inheritance: + +.. autofunction:: owlrl.OWLRLExtras._strToRational \ No newline at end of file diff --git a/docs/source/XsdDatatypes_source.rst b/docs/source/XsdDatatypes_source.rst index e12f920..da661ed 100644 --- a/docs/source/XsdDatatypes_source.rst +++ b/docs/source/XsdDatatypes_source.rst @@ -4,4 +4,4 @@ XsdDatatypes.py --------------- .. literalinclude:: ../../owlrl/XsdDatatypes.py - :linenos: \ No newline at end of file + :linenos: diff --git a/docs/source/_static/.gitkeep b/docs/source/_static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/source/conf.py b/docs/source/conf.py index b8565be..994aeb3 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -66,8 +66,8 @@ # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None +# Usually you set "language" from the command lihttps://rdflib.readthedocs.io/en/stable/ne for these cases. +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -194,4 +194,8 @@ # -- Options for intersphinx extension --------------------------------------- # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {"https://docs.python.org/": None} +intersphinx_mapping = { + "python": ("https://docs.python.org/", None), + "rdflib": ("https://rdflib.readthedocs.io/en/stable/", None) +} + diff --git a/docs/source/index.rst b/docs/source/index.rst index ed42f1a..25f648b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -22,7 +22,8 @@ OWL-RL Documentation :maxdepth: 2 :caption: Modules - owlrl + stubs/owlrl.__index__ + stubs/owlrl.DeductiveClosure AxiomaticTriples Closure CombinedClosure @@ -33,3 +34,10 @@ OWL-RL Documentation RestrictedDatatype XsdDatatypes +.. toctree:: + :maxdepth: 1 + :caption: Reference Source + + AxiomaticTriples_source + DatatypeHandling_source + XsdDatatypes_source \ No newline at end of file diff --git a/docs/source/stubs/owlrl.Closure.rst b/docs/source/stubs/owlrl.Closure.rst deleted file mode 100644 index 6884823..0000000 --- a/docs/source/stubs/owlrl.Closure.rst +++ /dev/null @@ -1,22 +0,0 @@ -owlrl.Closure -============= - -.. automodule:: owlrl.Closure - - - - - - - - .. rubric:: Classes - - .. autosummary:: - - Core - - - - - - \ No newline at end of file diff --git a/docs/source/stubs/owlrl.DeductiveClosure.rst b/docs/source/stubs/owlrl.DeductiveClosure.rst index 69bbbf7..f9824c7 100644 --- a/docs/source/stubs/owlrl.DeductiveClosure.rst +++ b/docs/source/stubs/owlrl.DeductiveClosure.rst @@ -7,7 +7,10 @@ owlrl.DeductiveClosure .. automethod:: __init__ - + .. automethod:: expand + .. automethod:: use_improved_datatypes_conversions + .. automethod:: use_rdflib_datatypes_conversions + .. autoattribute:: improved_datatype_generic .. rubric:: Methods @@ -24,8 +27,6 @@ owlrl.DeductiveClosure .. rubric:: Attributes - .. autosummary:: - - ~DeductiveClosure.improved_datatype_generic + .. autosummary:: improved_datatype_generic \ No newline at end of file diff --git a/docs/source/stubs/owlrl.rst b/docs/source/stubs/owlrl.__index__.rst similarity index 57% rename from docs/source/stubs/owlrl.rst rename to docs/source/stubs/owlrl.__index__.rst index cbc5e90..d5a81bb 100644 --- a/docs/source/stubs/owlrl.rst +++ b/docs/source/stubs/owlrl.__index__.rst @@ -7,23 +7,21 @@ owlrl .. rubric:: Functions - .. autosummary:: - - convert_graph - interpret_owl_imports - return_closure_class + .. autofunction:: convert_graph + .. autofunction:: interpret_owl_imports + .. autofunction:: return_closure_class + - .. rubric:: Classes .. autosummary:: DeductiveClosure - - + + diff --git a/owlrl/Closure.py b/owlrl/Closure.py index 6cfd747..414b75c 100755 --- a/owlrl/Closure.py +++ b/owlrl/Closure.py @@ -53,7 +53,7 @@ class Core: There are some methods that are implemented in the subclasses only, ie, this class cannot be used by itself! :param graph: The RDF graph to be extended. - :type graph: :class:`rdflib.Graph` + :type graph: :class:`rdflib.graph.Graph` :param axioms: Whether axioms should be added or not. :type axioms: bool @@ -65,13 +65,13 @@ class Core: :type rdfs: bool :param destination: The destination graph to which the results are written. If None, use the source graph. - :type destination: :class:`rdflib.Graph` + :type destination: :class:`rdflib.graph.Graph` :var IMaxNum: Maximal index of :code:`rdf:_i` occurrence in the graph. :type IMaxNum: int :var graph: The real graph. - :type graph: :class:`rdflib.Graph` + :type graph: :class:`rdflib.graph.Graph` :var axioms: Whether axioms should be added or not. :type axioms: bool @@ -96,7 +96,7 @@ def __init__(self, graph: Graph, axioms, daxioms, rdfs: bool = False, destinatio The parameter descriptions here are from the old documentation. @param graph: the RDF graph to be extended - @type graph: rdflib.Graph + @type graph: Graph @param axioms: whether axioms should be added or not @type axioms: boolean @param daxioms: whether datatype axioms should be added or not @@ -104,7 +104,7 @@ def __init__(self, graph: Graph, axioms, daxioms, rdfs: bool = False, destinatio @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: rdflib.Graph + @type destination: Graph """ self._debug = debugGlobal @@ -248,7 +248,7 @@ def store_triple(self, t): added any new triple, and the full processing can stop. :param t: The triple to be added to the graph, unless it is already there - :type t: tuple (s,p,o) + :type t: tuple """ (s, p, o) = t if not isinstance(p, Literal) and not (t in self.destination or t in self.graph): @@ -261,7 +261,7 @@ def closure(self): """ Generate the closure the graph. This is the real 'core'. - The processing rules store new triples via the separate method :func:`.Core.store_triple` which stores + The processing rules store new triples via the separate method :func:`owlrl.Closure.Core.store_triple` which stores them in the :code:`added_triples` array. If that array is empty at the end of a cycle, it means that the whole process can be stopped. diff --git a/owlrl/DatatypeHandling.py b/owlrl/DatatypeHandling.py index 19b3531..765396c 100755 --- a/owlrl/DatatypeHandling.py +++ b/owlrl/DatatypeHandling.py @@ -684,7 +684,7 @@ def _strToPlainLiteral(v): def use_Alt_lexical_conversions(): """ Registering the datatypes item for RDFLib, ie, bind the dictionary values. The 'bind' method of RDFLib adds - extra datatypes to the registered ones in RDFLib, though the table used here (I.e., :py:data:`.AltXSDToPYTHON`) actually + extra datatypes to the registered ones in RDFLib, though the table used here (I.e., :code:`AltXSDToPYTHON`) actually overrides all of the default conversion routines. The method also add a Decimal entry to the :code:`PythonToXSD` list of RDFLib. """ diff --git a/owlrl/OWLRLExtras.py b/owlrl/OWLRLExtras.py index 64c3734..ebb2b7e 100755 --- a/owlrl/OWLRLExtras.py +++ b/owlrl/OWLRLExtras.py @@ -100,7 +100,7 @@ def _strToRational(v): class OWLRL_Extension(RDFS_OWLRL_Semantics): """ Additional rules to OWL 2 RL. The initialization method also adds the :code:`owl:rational` datatype to the set of - allowed datatypes with the :py:func:`._strToRational` function as a conversion between the literal form and a Rational. The + allowed datatypes with the :func:`owlrl.OWLRLExtras._strToRational` function as a conversion between the literal form and a Rational. The :code:`xsd:decimal` datatype is also set to be a subclass of :code:`owl:rational`. Furthermore, the restricted datatypes are extracted from the graph using a separate method in a different module (:py:func:`.RestrictedDatatype.extract_faceted_datatypes`), and all those datatypes are also added to the set of allowed @@ -227,7 +227,7 @@ def one_time_rules(self): def add_axioms(self): """ - Add the :class:`.OWLRL_Extension.extra_axioms`, related to the self restrictions. + Add the :class:`owlrl.OWLRLExtras.OWLRL_Extension.extra_axioms`, related to the self restrictions. This method is invoked only once at the beginning, and prior of, the forward chaining process. """ RDFS_OWLRL_Semantics.add_axioms(self) for t in self.extra_axioms: diff --git a/owlrl/RestrictedDatatype.py b/owlrl/RestrictedDatatype.py index ac45d78..9b921df 100644 --- a/owlrl/RestrictedDatatype.py +++ b/owlrl/RestrictedDatatype.py @@ -57,7 +57,7 @@ import re from rdflib.namespace import OWL, RDF, RDFS, XSD -from rdflib import Literal as rdflibLiteral +from rdflib import Literal as rdflibLiteral, Graph from .DatatypeHandling import AltXSDToPYTHON from functools import reduce @@ -197,7 +197,7 @@ def _match(r, l): ####################################################################################################### -def extract_faceted_datatypes(core, graph): +def extract_faceted_datatypes(core, graph: Graph): """ Extractions of restricted (i.e., faceted) datatypes from the graph. @@ -205,7 +205,7 @@ def extract_faceted_datatypes(core, graph): :type core: :class:`.Closure.Core` :param graph: RDFLib graph. - :type graph: :class:`RDFLib.Graph` + :type graph: :class:`rdflib.graph.Graph` :return: List of :class:`.RestrictedDatatype` instances. :rtype: list diff --git a/owlrl/__init__.py b/owlrl/__init__.py index 8f86445..db4c871 100755 --- a/owlrl/__init__.py +++ b/owlrl/__init__.py @@ -26,7 +26,7 @@ The main entry point to the package is via the :class:`.DeductiveClosure` class. This class should be initialized to control the parameters of the deductive closure; the forward chaining is done via the -L{expand} method. +L{expand} method. The simplest way to use the package from an RDFLib application is as follows:: graph = Graph() # creation of an RDFLib graph @@ -48,7 +48,7 @@ expand function does not change any state. For convenience, a second entry point to the package is provided in the form of a function called -:func:`.convert_graph`, that expects a directory with various options, including a file name. The function +:func:`owlrl.convert_graph`, that expects a directory with various options, including a file name. The function parses the file, creates the expanded graph, and serializes the result into RDF/XML or Turtle. This function is particularly useful as an entry point for a CGI call (where the HTML form parameters are in a directory) and is easy to use with a command line interface. The package distribution contains an example for both. @@ -87,13 +87,6 @@ methods that are executed only once either at the beginning or at the end of the full processing cycle. Adding axiomatic triples is handled separately, which allows a finer user control over these features. -Literals must be handled separately. Indeed, the functionality relies on 'extended' RDF graphs, that allows literals -to be in a subject position, too. Because RDFLib does not allow that, processing begins by exchanging all literals in -the graph for bnodes (identical literals get the same associated bnode). Processing occurs on these bnodes; at the end -of the process all these bnodes are replaced by their corresponding literals if possible (if the bnode occurs in a -subject position, that triple is removed from the resulting graph). Details of this processing is handled in the -separate :class:`.Literals.LiteralProxies` class. - The OWL specification includes references to datatypes that are not in the core RDFS specification, consequently not directly implemented by RDFLib. These are added in a separate module of the package. @@ -102,8 +95,10 @@ ------------------------------------- The current distribution of RDFLib is fairly poor in handling datatypes, particularly in checking whether a lexical form -of a literal is "proper" as for its declared datatype. A typical example is:: +of a literal is "proper" as for its declared datatype. A typical example is :: + "-1234"^^xsd:nonNegativeInteger + which should not be accepted as valid literal. Because the requirements of OWL 2 RL are much stricter in this respect, an alternative set of datatype handling (essentially, conversions) had to be implemented (see the :py:mod:`.XsdDatatypes` module). @@ -233,15 +228,13 @@ def interpret_owl_imports(iformat, graph): Interpret the owl import statements. Essentially, recursively merge with all the objects in the owl import statement, and remove the corresponding triples from the graph. - This method can be used by an application prior to expansion. It is *not* done by the the :class:`.DeductiveClosure` + This method can be used by an application prior to expansion. It is *not* done by the :class:`.DeductiveClosure` class. - :param iformat: Input format; can be one of :code:`AUTO`, :code:`TURTLE`, or :code:`RDFXML`. :code:`AUTO` means that - the suffix of the file name or URI will decide: '.ttl' means Turtle, RDF/XML otherwise. + :param iformat: Input format; can be one of :code:`AUTO`, :code:`TURTLE`, or :code:`RDFXML`. :code:`AUTO` means that the suffix of the file name or URI will decide: '.ttl' means Turtle, RDF/XML otherwise. :type iformat: str - :param graph: The RDFLib Graph instance to parse into. - :type graph: :class:`RDFLib.Graph` + :type graph: :class:`rdflib.graph.Graph` """ while True: # 1. collect the import statements: @@ -330,7 +323,7 @@ class DeductiveClosure: :type datatype_axioms: bool :var improved_datatype_generic: Whether the improved set of lexical-to-Python conversions should be used for datatype handling *in general*, I.e., not only for a particular instance and not only for inference purposes. Default: False. - :type improved_Datatype_generic: bool + :type improved_datatype_generic: bool """ # This is the original set of param definitions in the class definition @@ -380,6 +373,8 @@ def __init__( if not isinstance(closure_class, type): raise ValueError("The closure type argument must be a class reference") else: + + self.closure_class = closure_class self.axiomatic_triples = axiomatic_triples self.datatype_axioms = datatype_axioms