RDFClosure.RestrictedDatatype

Package RDFClosure :: Module RestrictedDatatype |
[hide private]
[frames] | no frames]

# Module RestrictedDatatype

source code

Module to datatype restrictions, ie, data ranges.

The module implements the following aspects of datatype restrictions:

- a new datatype is created run-time and added to the allowed and accepted datatypes; literals are checked whether they abide to the restrictions
- the new datatype is defined to be a 'subClass' of the restricted datatype
- literals of the restricted datatype and that abide to the restrictions defined by the facets are also assigned to be of the new type

The last item is important to handle the following structures:

    ex:RE a owl:Restriction ;
           owl:onProperty ex:p ;
           owl:someValuesFrom [
                   a rdfs:Datatype ;
                   owl:onDatatype xsd:string ;
                   owl:withRestrictions (
                           [ xsd:minLength "3"^^xsd:integer ]
                           [ xsd:maxLength "6"^^xsd:integer ]
                   )
           ]
    .
    ex:q ex:p "abcd"^^xsd:string.

In the case above the system can then infer that `ex:q` is also of type `ex:RE`.

Datatype restrictions are used by the OWL RL Extensions extension class.

The implementation is not 100% complete. Some things that an ideal implementation should do are not done yet like:

- 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 'owl:sameAs' somewhere else)

Requires: RDFLib, 4.0.0 and higher

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

Organization: World Wide Web Consortium

Author: Ivan Herman

Contact: Ivan Herman, ivan@w3.org

Classes | [hide private]
| RestrictedDatatypeCore An 'abstract' superclass for datatype restrictions.
| RestrictedDatatype Implementation of a datatype with facets, ie, datatype with restrictions.

Functions | [hide private]
_lit_to_value(dt, v) This method is used to convert a string to a value with facet checking. | source code
boolean |
_lang_range_check(range, lang) Implementation of the extended filtering algorithm, as defined in point 3.3.2, of RFC 4647, on matching language ranges and language tags. | source code
extract_faceted_datatypes(core, graph) Extractions of restricted (ie, faceted) datatypes from the graph. | source code

Variables | [hide private]
| __author__ = ``'``Ivan Herman``'``
| __license__ = ``u'``W3C® SOFTWARE NOTICE AND LICENSE, http://www.w``...``
| MIN_MAX = `0`
| LENGTH = `1`
| LENGTH_AND_PATTERN = `2`
| LENGTH_PATTERN_LRANGE = `3`
| Datatypes_per_facets = ``{`0`:` `[`rdflib.term.URIRef(u'http://www.w3`...``
| facetable_datatypes = ``[`rdflib.term.URIRef(u'http://www.w3.org/`...``
| AllDifferent = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/`...``
| AllDisjointClasses = `rdflib.term.URIRef(u'http://www.w3.org/20`...``
| AllDisjointProperties = `rdflib.term.URIRef(u'http://www.w3.org`...``
| Annotation = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/ow`...``
| AnnotationProperty = `rdflib.term.URIRef(u'http://www.w3.org/20`...``
| AsymmetricProperty = `rdflib.term.URIRef(u'http://www.w3.org/20`...``
| Axiom = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#Axi`...``
| BottomDataProperty = `rdflib.term.URIRef(u'http://www.w3.org/20`...``
| BottomObjectProperty = `rdflib.term.URIRef(u'http://www.w3.org/`...``
| DataRange = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl`...``
| DatatypeProperty = `rdflib.term.URIRef(u'http://www.w3.org/2002`...``
| DeprecatedClass = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| DeprecatedProperty = `rdflib.term.URIRef(u'http://www.w3.org/20`...``
| FunctionalProperty = `rdflib.term.URIRef(u'http://www.w3.org/20`...``
| InverseFunctionalProperty = `rdflib.term.URIRef(u'http://www.w3`...``
| IrreflexiveProperty = `rdflib.term.URIRef(u'http://www.w3.org/2`...``
| NamedIndividual = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| NegativePropertyAssertion = `rdflib.term.URIRef(u'http://www.w3`...``
| Nothing = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#N`...``
| OWLClass = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#`...``
| OWLNS = `Namespace(u'http://www.w3.org/2002/07/owl#')`
| OWLpredicate = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/`...``
| OWLsubject = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/ow`...``
| ObjectProperty = `rdflib.term.URIRef(u'http://www.w3.org/2002/0`...``
| Ontology = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#`...``
| OntologyProperty = `rdflib.term.URIRef(u'http://www.w3.org/2002`...``
| ReflexiveProperty = `rdflib.term.URIRef(u'http://www.w3.org/200`...``
| Restriction = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/o`...``
| SelfRestriction = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| SymmetricProperty = `rdflib.term.URIRef(u'http://www.w3.org/200`...``
| Thing = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#Thi`...``
| TopDataProperty = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| TopObjectProperty = `rdflib.term.URIRef(u'http://www.w3.org/200`...``
| TransitiveProperty = `rdflib.term.URIRef(u'http://www.w3.org/20`...``
| __package__ = ``'``RDFClosure``'``
| allValuesFrom = `rdflib.term.URIRef(u'http://www.w3.org/2002/07`...``
| annotatedProperty = `rdflib.term.URIRef(u'http://www.w3.org/200`...``
| annotatedSource = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| annotatedTarget = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| assertionProperty = `rdflib.term.URIRef(u'http://www.w3.org/200`...``
| backwardCompatibleWith = `rdflib.term.URIRef(u'http://www.w3.or`...``
| cardinality = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/o`...``
| complementOf = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/`...``
| datatypeComplementOf = `rdflib.term.URIRef(u'http://www.w3.org/`...``
| deprecated = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/ow`...``
| differentFrom = `rdflib.term.URIRef(u'http://www.w3.org/2002/07`...``
| disjointClasses = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| disjointUnionOf = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| disjointWith = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/`...``
| distinctMembers = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| equivalentClass = `rdflib.term.URIRef(u'http://www.w3.org/2002/`...``
| equivalentProperty = `rdflib.term.URIRef(u'http://www.w3.org/20`...``
| hasKey = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#ha`...``
| hasSelf = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#h`...``
| hasValue = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#`...``
| imports = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#i`...``
| incompatibleWith = `rdflib.term.URIRef(u'http://www.w3.org/2002`...``
| intersectionOf = `rdflib.term.URIRef(u'http://www.w3.org/2002/0`...``
| inverseOf = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl`...``
| maxCardinality = `rdflib.term.URIRef(u'http://www.w3.org/2002/0`...``
| maxQualifiedCardinality = `rdflib.term.URIRef(u'http://www.w3.o`...``
| members = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#m`...``
| minCardinality = `rdflib.term.URIRef(u'http://www.w3.org/2002/0`...``
| minQualifiedCardinality = `rdflib.term.URIRef(u'http://www.w3.o`...``
| onClass = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#o`...``
| onDataRange = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/o`...``
| onDatatype = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/ow`...``
| onProperties = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/`...``
| onProperty = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/ow`...``
| oneOf = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#one`...``
| priorVersion = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/`...``
| propertyChainAxiom = `rdflib.term.URIRef(u'http://www.w3.org/20`...``
| propertyDisjointWith = `rdflib.term.URIRef(u'http://www.w3.org/`...``
| qualifiedCardinality = `rdflib.term.URIRef(u'http://www.w3.org/`...``
| sameAs = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#sa`...``
| someValuesFrom = `rdflib.term.URIRef(u'http://www.w3.org/2002/0`...``
| sourceIndividual = `rdflib.term.URIRef(u'http://www.w3.org/2002`...``
| targetIndividual = `rdflib.term.URIRef(u'http://www.w3.org/2002`...``
| targetValue = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/o`...``
| unionOf = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#u`...``
| versionIRI = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/ow`...``
| versionInfo = `rdflib.term.URIRef(u'http://www.w3.org/2002/07/o`...``
| withRestrictions = `rdflib.term.URIRef(u'http://www.w3.org/2002`...``

Imports: re, ns_owl, Datatype, type, ns_rdf, rdflibLiteral, ns_xsd, AltXSDToPYTHON, Namespace, rdflib

Function Details | [hide private]

### _lit_to_value(dt, v) | source code
This method is used to convert a string to a value with facet checking. RDF Literals are converted to Python values using this method; if there is a problem, an exception is raised (and caught higher up to generate an error message). The method is the equivalent of all the methods in the DatatypeHandling module, and is registered to the system run time, as new restricted datatypes are discovered. (Technically, the registration is done via a `lambda v: _lit_to_value(self,v)` setting from within a RestrictedDatatype instance) Parameters: `dt` (RestrictedDatatype) - faceted datatype `v` - literal to be converted and checked Raises: `ValueError` - invalid literal value

### _lang_range_check(range, lang) | source code
Implementation of the extended filtering algorithm, as defined in point 3.3.2, of RFC 4647, on matching language ranges and language tags. Needed to handle the `rdf:PlainLiteral` datatype. Parameters: `range` - language range `lang` - language tag Returns: boolean

### extract_faceted_datatypes(core, graph) | source code
Extractions of restricted (ie, faceted) datatypes from the graph. Parameters: `core` (Closure.Core) - the core closure instance that is being handled `graph` - RDFLib graph Returns: array of RestrictedDatatype instances

Variables Details | [hide private]

  ### __license__ Value:
      u'W3C® SOFTWARE NOTICE AND LICENSE, http://www.w3.org/Consortium/Legal
      /2002/copyright-software-20021231'

  ### Datatypes_per_facets Value:
      {0: [rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#rational'),
           rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#decimal'),
           rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'),
           rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#nonNegative
      Integer'),
           rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#nonPositive
      Integer'),
           rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#positiveInt
      ...

  ### facetable_datatypes Value:
      [rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#rational'),
       rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#decimal'),
       rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'),
       rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#nonNegativeInte
      ger'),
       rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#nonPositiveInte
      ger'),
       rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#positiveInteger
      ...

  ### AllDifferent Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#AllDifferent')

  ### AllDisjointClasses Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#AllDisjointClasses'
      )

  ### AllDisjointProperties Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#AllDisjointProperti
      es')

  ### Annotation Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#Annotation')

  ### AnnotationProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#AnnotationProperty'
      )

  ### AsymmetricProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#AsymmetricProperty'
      )

  ### Axiom Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#Axiom')

  ### BottomDataProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#BottomDataProperty'
      )

  ### BottomObjectProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#BottomObjectPropert
      y')

  ### DataRange Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#DataRange')

  ### DatatypeProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#DatatypeProperty')

  ### DeprecatedClass Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#DeprecatedClass')

  ### DeprecatedProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#DeprecatedProperty'
      )

  ### FunctionalProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#FunctionalProperty'
      )

  ### InverseFunctionalProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#InverseFunctionalPr
      operty')

  ### IrreflexiveProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#IrreflexiveProperty
      ')

  ### NamedIndividual Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#NamedIndividual')

  ### NegativePropertyAssertion Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#NegativePropertyAss
      ertion')

  ### Nothing Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#Nothing')

  ### OWLClass Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#Class')

  ### OWLpredicate Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#predicate')

  ### OWLsubject Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#subject')

  ### ObjectProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#ObjectProperty')

  ### Ontology Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#Ontology')

  ### OntologyProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#OntologyProperty')

  ### ReflexiveProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#ReflexiveProperty')

  ### Restriction Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#Restriction')

  ### SelfRestriction Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#SelfRestriction')

  ### SymmetricProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#SymmetricProperty')

  ### Thing Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#Thing')

  ### TopDataProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#TopDataProperty')

  ### TopObjectProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#TopObjectProperty')

  ### TransitiveProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#TransitiveProperty'
      )

  ### allValuesFrom Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#allValuesFrom')

  ### annotatedProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#annotatedProperty')

  ### annotatedSource Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#annotatedSource')

  ### annotatedTarget Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#annotatedTarget')

  ### assertionProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#assertionProperty')

  ### backwardCompatibleWith Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#backwardCompatibleW
      ith')

  ### cardinality Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#cardinality')

  ### complementOf Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#complementOf')

  ### datatypeComplementOf Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#datatypeComplementO
      f')

  ### deprecated Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#deprecated')

  ### differentFrom Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#differentFrom')

  ### disjointClasses Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#disjointClasses')

  ### disjointUnionOf Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#disjointUnionOf')

  ### disjointWith Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#disjointWith')

  ### distinctMembers Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#distinctMembers')

  ### equivalentClass Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#equivalentClass')

  ### equivalentProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#equivalentProperty'
      )

  ### hasKey Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#hasKey')

  ### hasSelf Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#hasSelf')

  ### hasValue Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#hasValue')

  ### imports Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#imports')

  ### incompatibleWith Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#incompatibleWith')

  ### intersectionOf Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#intersectionOf')

  ### inverseOf Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#inverseOf')

  ### maxCardinality Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#maxCardinality')

  ### maxQualifiedCardinality Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#maxQualifiedCardina
      lity')

  ### members Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#members')

  ### minCardinality Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#minCardinality')

  ### minQualifiedCardinality Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#minQualifiedCardina
      lity')

  ### onClass Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#onClass')

  ### onDataRange Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#onDataRange')

  ### onDatatype Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#onDatatype')

  ### onProperties Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#onProperties')

  ### onProperty Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#onProperty')

  ### oneOf Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#oneOf')

  ### priorVersion Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#priorVersion')

  ### propertyChainAxiom Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#propertyChainAxiom'
      )

  ### propertyDisjointWith Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#propertyDisjointWit
      h')

  ### qualifiedCardinality Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#qualifiedCardinalit
      y')

  ### sameAs Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#sameAs')

  ### someValuesFrom Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#someValuesFrom')

  ### sourceIndividual Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#sourceIndividual')

  ### targetIndividual Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#targetIndividual')

  ### targetValue Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#targetValue')

  ### unionOf Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#unionOf')

  ### versionIRI Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#versionIRI')

  ### versionInfo Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#versionInfo')

  ### withRestrictions Value:
      rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#withRestrictions')