DataType Node

A DataType Node specifies the constraints for a literal value.

Key-value table

In the following the basic attributes that a DataType Node can have are listed:

Example

{
  "@type": "sh:PropertyShape",
  "sh:path": "schema:address",
  "sh:or": [
    {
      "sh:datatype": "xsd:string",
      "sh:defaultValue": "Innsbruck 6020"
    }
  ]  
}

Advanced Constraints

Advanced constraints are introduced with this DS version. They can be used in DataType nodes for specific datatypes. Some of these constraints can have multiple entries; if that is the case, then an array is used to wrap the values.

See https://docs.google.com/spreadsheets/d/1AFD21lB_zQkns_3aeDLIFW1E-C36eJ3DogcnOb2vD7g/edit#gid=1009977856

Value Range Constraint Components

SHACL reference: https://www.w3.org/TR/shacl/#core-components-range

These constraint components dictate a value range that the value of a literal value must have. The datatype for this value must be the same as the datatype of the constrained literal. Datatypes that are allowed to have these constraints are: Date, DateTime, Time, Number, Float, and Integer.

Example:

{
    "sh:datatype": "xsd:integer",
    "sh:minExclusive": 0,
    "sh:maxInclusive": 10
}
{
    "sh:datatype": "xsd:date",
    "sh:minExclusive": "2010-10-10"
}

String based Constraint Components

SHACL reference: https://www.w3.org/TR/shacl/#core-components-string

These constraint components are meant for literals having the datatype string (and their sub-datatypes in some cases).

Example of a DataType Node as range for schema:description:

{
    "sh:datatype": "xsd:string",
    "sh:minLength": 20,
    "sh:maxLength": 200,
    "sh:languageIn": [
      "en",
      "de"
    ],
    "sh:uniqueLang": true
}

Example of a DataType Node as range for schema:telephone:

{
  "sh:datatype": "xsd:string",
  "sh:pattern": [
    "^\\s*\\+?\\s*([0-9][\\s-]*){9,}$"
  ]
}

Property Value Pair Constraint Components

SHACL reference: https://www.w3.org/TR/shacl/#core-components-property-pairs

These constraints are explained in Property.md since they are expressed on a property-level, and not on a data-type-level.

Other Constraint Components

SHACL reference: https://www.w3.org/TR/shacl/#core-components-others

These constraints can be used on any data type.

Example:

{
  "sh:path": "schema:City",
  "sh:or":[
    {
      "sh:datatype": "xsd:string",
      "sh:in": [
        "Innsbruck",
        "Wien",
        "Salzburg"
      ],
      "sh:hasValue": [
        "Innsbruck"
      ]
    }
  ]
}

Datatype Mapping

Mapping Functions between XSD datatypes and schema.org datatypes:

(Other datatypes are ignored for now, since they are not used in practice)

function schemaToXsd(dataType) {
    switch (dataType) {
        case "schema:Text":
            return "xsd:string";
        case "schema:Boolean":
            return "xsd:boolean";
        case "schema:Date":
            return "xsd:date";
        case "schema:DateTime":
            return "xsd:dateTime";
        case "schema:Time":
            return "xsd:time";
        case "schema:Number":
            return "xsd:double";
        case "schema:Float":
            return "xsd:float";
        case "schema:Integer":
            return "xsd:integer";
        case "schema:URL":
            return "xsd:anyURI";
    }
}
function xsdToSchema(dataType) {
    switch (dataType) {
        case "xsd:string":
            return "schema:Text";
        case "xsd:boolean" :
            return "schema:Boolean";
        case "xsd:date" :
            return "schema:Date";
        case "xsd:dateTime":
            return "schema:DateTime";
        case "xsd:time":
            return "schema:Time";
        case "xsd:double":
            return "schema:Number";
        case "xsd:float":
            return "schema:Float";
        case "xsd:integer":
            return "schema:Integer";
        case "xsd:anyURI":
            return "schema:URL";
    }
}

Last updated