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
34import rdflib
35# noinspection PyPep8Naming
36from rdflib.namespace import XSD as ns_xsd
37
38#: The basic XSD types used everywhere; this means not the complete set of day/month types
39_Common_XSD_Datatypes = [
40    ns_xsd['integer'], ns_xsd['decimal'], ns_xsd['nonNegativeInteger'], ns_xsd['nonPositiveInteger'],
41    ns_xsd['negativeInteger'], ns_xsd['positiveInteger'], ns_xsd['long'], ns_xsd['int'], ns_xsd['short'],
42    ns_xsd['byte'], ns_xsd['unsignedLong'], ns_xsd['unsignedInt'], ns_xsd['unsignedShort'],
43    ns_xsd['unsignedByte'], ns_xsd['float'], ns_xsd['double'], ns_xsd['string'], ns_xsd['normalizedString'],
44    ns_xsd['token'], ns_xsd['language'], ns_xsd['Name'], ns_xsd['NCName'], ns_xsd['NMTOKEN'],
45    ns_xsd['boolean'], ns_xsd['hexBinary'], ns_xsd['base64Binary'], ns_xsd['anyURI'],
46    ns_xsd['dateTimeStamp'], ns_xsd['dateTime'], ns_xsd['time'], ns_xsd['date'],
47    Literal, XMLLiteral, HTMLLiteral, LangString
48]
49
50#: RDFS Datatypes: the basic ones plus the complete set of day/month ones
51RDFS_Datatypes = _Common_XSD_Datatypes + [ns_xsd['gYearMonth'], ns_xsd['gMonthDay'], ns_xsd['gYear'],
52                                          ns_xsd['gDay'], ns_xsd['gMonth']]
53
54#: OWL RL Datatypes: the basic ones plus plain literal
55OWL_RL_Datatypes = _Common_XSD_Datatypes + [ns_rdf['PlainLiteral']]
56
57#: XSD Datatype subsumptions
58_Common_Datatype_Subsumptions = {
59    ns_xsd['dateTimeStamp']: [ns_xsd['dateTime']],
60    ns_xsd['integer']: [ns_xsd['decimal']],
61    ns_xsd['long']: [ns_xsd['integer'], ns_xsd['decimal']],
62    ns_xsd['int']: [ns_xsd['long'], ns_xsd['integer'], ns_xsd['decimal']],
63    ns_xsd['short']: [ns_xsd['int'], ns_xsd['long'], ns_xsd['integer'], ns_xsd['decimal']],
64    ns_xsd['byte']: [ns_xsd['short'], ns_xsd['int'], ns_xsd['long'], ns_xsd['integer'], ns_xsd['decimal']],
65
66    ns_xsd['nonNegativeInteger']: [ns_xsd['integer'], ns_xsd['decimal']],
67    ns_xsd['positiveInteger']: [ns_xsd['nonNegativeInteger'], ns_xsd['integer'], ns_xsd['decimal']],
68    ns_xsd['unsignedLong']: [ns_xsd['nonNegativeInteger'], ns_xsd['integer'], ns_xsd['decimal']],
69    ns_xsd['unsignedInt']: [ns_xsd['unsignedLong'], ns_xsd['nonNegativeInteger'], ns_xsd['integer'], ns_xsd['decimal']],
70    ns_xsd['unsignedShort']: [ns_xsd['unsignedInt'], ns_xsd['unsignedLong'], ns_xsd['nonNegativeInteger'],
71                              ns_xsd['integer'], ns_xsd['decimal']],
72    ns_xsd['unsignedByte']: [ns_xsd['unsignedShort'], ns_xsd['unsignedInt'], ns_xsd['unsignedLong'],
73                             ns_xsd['nonNegativeInteger'], ns_xsd['integer'], ns_xsd['decimal']],
74
75    ns_xsd['nonPositiveInteger']: [ns_xsd['integer'], ns_xsd['decimal']],
76    ns_xsd['negativeInteger']: [ns_xsd['nonPositiveInteger'], ns_xsd['integer'], ns_xsd['decimal']],
77
78    ns_xsd['normalizedString']: [ns_xsd["string"]],
79    ns_xsd['token']: [ns_xsd['normalizedString'], ns_xsd["string"]],
80    ns_xsd['language']: [ns_xsd['token'], ns_xsd['normalizedString'], ns_xsd["string"]],
81    ns_xsd['Name']: [ns_xsd['token'], ns_xsd['normalizedString'], ns_xsd["string"]],
82    ns_xsd['NCName']: [ns_xsd['Name'], ns_xsd['token'], ns_xsd['normalizedString'], ns_xsd["string"]],
83    ns_xsd['NMTOKEN']: [ns_xsd['Name'], ns_xsd['token'], ns_xsd['normalizedString'], ns_xsd["string"]],
84}
85
86#: RDFS Datatype subsumptions: at the moment, there is no extra to XSD
87RDFS_Datatype_Subsumptions = _Common_Datatype_Subsumptions
88
89#: OWL Datatype subsumptions: at the moment, there is no extra to XSD
90OWL_Datatype_Subsumptions = _Common_Datatype_Subsumptions