XsdDatatypes.py

  1# -*- coding: utf-8 -*-
  2#
  3"""
  4Lists of XSD datatypes and their mutual relationships
  5
  6**Requires**: `RDFLib`_, 4.0.0 and higher.
  7
  8.. _RDFLib: https://github.com/RDFLib/rdflib
  9
 10**License**: This software is available for use under the `W3C Software License`_.
 11
 12.. _W3C Software License: http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
 13
 14**Organization**: `World Wide Web Consortium`_
 15
 16.. _World Wide Web Consortium: http://www.w3.org
 17
 18**Author**: `Ivan Herman`_
 19
 20.. _Ivan Herman: http://www.w3.org/People/Ivan/
 21
 22"""
 23__author__ = "Ivan Herman"
 24__contact__ = "Ivan Herman, ivan@w3.org"
 25__license__ = "W3C® SOFTWARE NOTICE AND LICENSE, http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231"
 26
 27# noinspection PyPep8Naming
 28from .RDFS import RDFNS as ns_rdf
 29from .RDFS import Literal
 30from .RDFS import XMLLiteral
 31from .RDFS import HTMLLiteral
 32from .RDFS import LangString
 33
 34# noinspection PyPep8Naming
 35from rdflib.namespace import XSD as ns_xsd
 36
 37# The basic XSD types used everywhere; this means not the complete set of day/month types
 38_Common_XSD_Datatypes = [
 39    ns_xsd["integer"],
 40    ns_xsd["decimal"],
 41    ns_xsd["nonNegativeInteger"],
 42    ns_xsd["nonPositiveInteger"],
 43    ns_xsd["negativeInteger"],
 44    ns_xsd["positiveInteger"],
 45    ns_xsd["long"],
 46    ns_xsd["int"],
 47    ns_xsd["short"],
 48    ns_xsd["byte"],
 49    ns_xsd["unsignedLong"],
 50    ns_xsd["unsignedInt"],
 51    ns_xsd["unsignedShort"],
 52    ns_xsd["unsignedByte"],
 53    ns_xsd["float"],
 54    ns_xsd["double"],
 55    ns_xsd["string"],
 56    ns_xsd["normalizedString"],
 57    ns_xsd["token"],
 58    ns_xsd["language"],
 59    ns_xsd["Name"],
 60    ns_xsd["NCName"],
 61    ns_xsd["NMTOKEN"],
 62    ns_xsd["boolean"],
 63    ns_xsd["hexBinary"],
 64    ns_xsd["base64Binary"],
 65    ns_xsd["anyURI"],
 66    ns_xsd["dateTimeStamp"],
 67    ns_xsd["dateTime"],
 68    ns_xsd["time"],
 69    ns_xsd["date"],
 70    Literal,
 71    XMLLiteral,
 72    HTMLLiteral,
 73    LangString,
 74]
 75
 76# RDFS Datatypes: the basic ones plus the complete set of day/month ones
 77RDFS_Datatypes = _Common_XSD_Datatypes + [
 78    ns_xsd["gYearMonth"],
 79    ns_xsd["gMonthDay"],
 80    ns_xsd["gYear"],
 81    ns_xsd["gDay"],
 82    ns_xsd["gMonth"],
 83]
 84
 85# OWL RL Datatypes: the basic ones plus plain literal
 86OWL_RL_Datatypes = _Common_XSD_Datatypes + [ns_rdf["PlainLiteral"]]
 87
 88# XSD Datatype subsumptions
 89_Common_Datatype_Subsumptions = {
 90    ns_xsd["dateTimeStamp"]: [ns_xsd["dateTime"]],
 91    ns_xsd["integer"]: [ns_xsd["decimal"]],
 92    ns_xsd["long"]: [ns_xsd["integer"], ns_xsd["decimal"]],
 93    ns_xsd["int"]: [ns_xsd["long"], ns_xsd["integer"], ns_xsd["decimal"]],
 94    ns_xsd["short"]: [
 95        ns_xsd["int"],
 96        ns_xsd["long"],
 97        ns_xsd["integer"],
 98        ns_xsd["decimal"],
 99    ],
100    ns_xsd["byte"]: [
101        ns_xsd["short"],
102        ns_xsd["int"],
103        ns_xsd["long"],
104        ns_xsd["integer"],
105        ns_xsd["decimal"],
106    ],
107    ns_xsd["nonNegativeInteger"]: [ns_xsd["integer"], ns_xsd["decimal"]],
108    ns_xsd["positiveInteger"]: [
109        ns_xsd["nonNegativeInteger"],
110        ns_xsd["integer"],
111        ns_xsd["decimal"],
112    ],
113    ns_xsd["unsignedLong"]: [
114        ns_xsd["nonNegativeInteger"],
115        ns_xsd["integer"],
116        ns_xsd["decimal"],
117    ],
118    ns_xsd["unsignedInt"]: [
119        ns_xsd["unsignedLong"],
120        ns_xsd["nonNegativeInteger"],
121        ns_xsd["integer"],
122        ns_xsd["decimal"],
123    ],
124    ns_xsd["unsignedShort"]: [
125        ns_xsd["unsignedInt"],
126        ns_xsd["unsignedLong"],
127        ns_xsd["nonNegativeInteger"],
128        ns_xsd["integer"],
129        ns_xsd["decimal"],
130    ],
131    ns_xsd["unsignedByte"]: [
132        ns_xsd["unsignedShort"],
133        ns_xsd["unsignedInt"],
134        ns_xsd["unsignedLong"],
135        ns_xsd["nonNegativeInteger"],
136        ns_xsd["integer"],
137        ns_xsd["decimal"],
138    ],
139    ns_xsd["nonPositiveInteger"]: [ns_xsd["integer"], ns_xsd["decimal"]],
140    ns_xsd["negativeInteger"]: [
141        ns_xsd["nonPositiveInteger"],
142        ns_xsd["integer"],
143        ns_xsd["decimal"],
144    ],
145    ns_xsd["normalizedString"]: [ns_xsd["string"]],
146    ns_xsd["token"]: [ns_xsd["normalizedString"], ns_xsd["string"]],
147    ns_xsd["language"]: [ns_xsd["token"], ns_xsd["normalizedString"], ns_xsd["string"]],
148    ns_xsd["Name"]: [ns_xsd["token"], ns_xsd["normalizedString"], ns_xsd["string"]],
149    ns_xsd["NCName"]: [
150        ns_xsd["Name"],
151        ns_xsd["token"],
152        ns_xsd["normalizedString"],
153        ns_xsd["string"],
154    ],
155    ns_xsd["NMTOKEN"]: [
156        ns_xsd["Name"],
157        ns_xsd["token"],
158        ns_xsd["normalizedString"],
159        ns_xsd["string"],
160    ],
161}
162
163# RDFS Datatype subsumptions: at the moment, there is no extra to XSD
164RDFS_Datatype_Subsumptions = _Common_Datatype_Subsumptions
165
166# OWL Datatype subsumptions: at the moment, there is no extra to XSD
167OWL_Datatype_Subsumptions = _Common_Datatype_Subsumptions