def finalize(self):
        """Write add type information
        pred in self._predicates --> pred a owl:ObjectProperty .
        cls in self._classes --> cls a owl:Class .
        sup, sub in self._cls_hierarchy --> sub rdfs:subClassOf sup .
        i, cls in self._type_defs --> i a cls .
        p, cls in self._domains --> p rdfs:domain cls .
        p, cls in self._ranges --> p rdfs:range cls .
        """
        owl_ObjectProperty = OWL.term('ObjectProperty')
        owl_Class = OWL.term('Class')
        owl_FunctionalProperty = OWL.term('FunctionalProperty')
        rdfs_subClassOf = RDFS.term('subClassOf')
        rdfs_domain = RDFS.term('domain')
        rdfs_range = RDFS.term('range')

        for pred in self._predicates:
            self._g.add((self._pred_uri(pred), a, owl_ObjectProperty))

        for cls in self._classes:
            self._g.add((self._cls_uri(cls), a, owl_Class))

        for super_cls, sub_clss in self._cls_hierarchy.items():
            for sub_cls in sub_clss:
                self._g.add((
                    self._cls_uri(sub_cls),
                    rdfs_subClassOf,
                    self._cls_uri(super_cls)))

        for inst, classes in self._type_defs.items():
            for cls in classes:
                self._g.add((self._res_uri(inst), a, self._cls_uri(cls)))

        for pred, clss in self._domains.items():
            for cls in clss:
                self._g.add(
                    (self._pred_uri(pred), rdfs_domain, self._cls_uri(cls)))

        for pred, clss in self._ranges.items():
            for cls in clss:
                self._g.add(
                    (self._pred_uri(pred), rdfs_range, self._cls_uri(cls)))

        for preds in self._nary_property_preds.values():
            for pred in preds:
                self._g.add((self._pred_uri(pred), a, owl_FunctionalProperty))
コード例 #2
0
import inspect
import os

from rdflib import Graph, RDFS, RDF, OWL
from itertools import chain

owl_class = OWL.term('Class')
owl_obj_property = OWL.term('ObjectProperty')
owl_data_property = OWL.term('DatatypeProperty')
rdf_type = RDF.term('type')
rdfs_domain = RDFS.term('domain')
rdfs_range = RDFS.term('range')
rdfs_subClassOf = RDFS.term('subClassOf')


def create_onto_py_URIs(file, form='turtle', add_imports=True):
    g = Graph()
    root = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe())))
    root += '/OwlFiles/'
    g.parse(root + file, format=form)
    file_content = ''
    if add_imports:
        file_content = "# Auto generated file #\n" \
                        "from rdflib import Graph,URIRef\n" \
                        "import os\n" \
                        "import inspect\n\n\n" \

    file_content += "graph = Graph()\n" \
                    "root = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))\n" \
                    "root += '/OwlFiles/'\n" \
from rdflib import Graph
from rdflib import Literal
from rdflib import OWL
from rdflib import RDF
from rdflib import RDFS
from rdflib import URIRef
from rdflib import XSD

from utils import write_graph

a = RDF.term('type')
rdfs_domain = RDFS.term('domain')
rdfs_range = RDFS.term('range')
rdfs_subClassOf = RDFS.term('subClassOf')
xsd_double = XSD.term('double')
owl_Class = OWL.term('Class')
owl_DatatypeProperty = OWL.term('DatatypeProperty')
owl_FunctionalProperty = OWL.term('FunctionalProperty')


class Iris2RDFConverter(object):
    """
    Attribute Information:

    1. sepal length in cm
    2. sepal width in cm
    3. petal length in cm
    4. petal width in cm
    5. class:
    -- Iris Setosa
    -- Iris Versicolour
コード例 #4
0
ファイル: consts.py プロジェクト: mullikine/pySHACL
# -*- coding: utf-8 -*-
import rdflib

from rdflib.namespace import Namespace
from rdflib import RDFS, RDF, OWL

SH = Namespace('http://www.w3.org/ns/shacl#')

# Classes
RDF_Property = RDF.term('Property')
RDF_List = RDF.term('List')
RDFS_Resource = RDFS.term('Resource')
RDFS_Class = RDFS.term('Class')
OWL_Ontology = OWL.term("Ontology")
OWL_Class = OWL.term("Class")
OWL_DatatypeProperty = OWL.term("DatatypeProperty")
SH_NodeShape = SH.term('NodeShape')
SH_PropertyShape = SH.term('PropertyShape')
SH_ValidationResult = SH.term('ValidationResult')
SH_ValidationReport = SH.term('ValidationReport')
SH_Violation = SH.term('Violation')
SH_Info = SH.term('Info')
SH_Warning = SH.term('Warning')
SH_IRI = SH.term('IRI')
SH_BlankNode = SH.term('BlankNode')
SH_Literal = SH.term('Literal')
SH_BlankNodeOrIRI = SH.term('BlankNodeOrIRI')
SH_BlankNodeORLiteral = SH.term('BlankNodeOrLiteral')
SH_IRIOrLiteral = SH.term('IRIOrLiteral')
SH_SPARQLFunction = SH.term('SPARQLFunction')
SH_SPARQLRule = SH.term('SPARQLRule')