# Auto-generated from iotic-rdf-ontology repository, iotics/iotics. Edits will be overwritten!

PREFIX geo:     <http://www.opengis.net/ont/geosparql#>
PREFIX iotics:    <http://data.iotics.com/iotics#>
PREFIX rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:    <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sf:      <http://www.opengis.net/ont/sf#>
PREFIX sh:      <http://www.w3.org/ns/shacl#>
PREFIX xsd:     <http://www.w3.org/2001/XMLSchema#>
# Copyright (c) 2022 Iotic Labs Ltd. All rights reserved.

###############################################################################
# IOTICS Resource Ontology - Validation Shapes                                #
###############################################################################



iotics:DefaultLocatedTwinShape
    a sh:NodeShape ;
    sh:description "Twins can have an optional default single-point location"@en ;
    sh:targetClass iotics:DigitalTwin ;
    sh:property [
        # subclass of geo:hasGeometry
        sh:path geo:hasDefaultGeometry ;
        sh:and (
            # subclass of geo:Geometry
            [ sh:class sf:Point ]
            [ sh:node iotics:WKTPointLocatedShape ]
        ) ;
        sh:minCount 0 ;
        sh:maxCount 1 ;
    ] .

iotics:WKTPointLocatedShape
    a sh:NodeShape ;
    sh:property [
        # subclass of geo:hasSerialization
        sh:path geo:asWKT ;
        sh:datatype geo:wktLiteral ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] .

iotics:NamedPointShape
    a sh:NodeShape ;
    sh:description "Points must have exactly one name, which must be a string with at least one non-whitespace character"@en ;
    sh:targetClass iotics:Point ;
    sh:property [
        sh:path iotics:pointName ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:minLength  1 ;
        sh:pattern "\\S" ;
    ] .

iotics:LabelShape
    sh:description "Labels must be no longer than 128 chars, cannot start or end with whitespace, and must have unique languages."@en ;
    sh:datatype xsd:string ;
    sh:pattern "^\\S(.{0,126}\\S)?$" ;
    sh:uniqueLang true ;
    .

iotics:LabelledShape
    a sh:NodeShape ;
    sh:description "Labels must be between 1 and 128 characters long, and cannot start or end with whitespace."@en ;
    sh:targetClass iotics:DigitalTwin, iotics:Point ;
    sh:property [
        sh:path rdfs:label ;
        sh:node iotics:LabelShape
    ] .

iotics:CommentedShape
    a sh:NodeShape ;
    sh:description "Comments must be between 1 and 1024 characters long, and cannot start or end with whitespace. Newlines are ok."@en ;
    sh:targetClass iotics:DigitalTwin, iotics:Point, iotics:Value ;
    sh:property [
        sh:path rdfs:comment ;
        sh:datatype xsd:string ;
        sh:pattern "(?s)^\\S(.{0,1022}\\S)?$" ;
        sh:uniqueLang true;
    ] .

iotics:ValueShape
    a sh:NodeShape ;
    sh:description """Values must have exactly one valueKey property with the same restrictions as a label, and most one valueUnit
        property that is a URI not longer than 128 characters."""@en ;
    sh:targetClass iotics:Value ;
    sh:property [
        sh:path iotics:valueKey ;
        sh:node iotics:LabelShape ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] ;
    sh:property [
        sh:path iotics:valueUnit ;
        sh:datatype xsd:anyURI ;
        sh:maxCount 1 ;
        sh:maxLength 128 ;
    ] .

iotics:UUIDShape
    a sh:NodeShape ;
    sh:description "Point URIs must be properly-formatted UUIDs."@en ;
    sh:targetClass iotics:Point ;
    sh:pattern "^urn:uuid:?P<uuid>([a-f0-9]{8})-([a-f0-9]{4})-([a-f0-9]{4})-([a-f0-9]{4})-([a-f0-9]{12}))$" ;
    .

iotics:IdentityShape
    a sh:NodeShape ;
    sh:description "IOTICS Decentralized Identity Document"@en ;
    sh:targetClass iotics:DigitalTwin, iotics:User ;
    sh:pattern "^did:iotics:iot[A-Za-z0-9]{33}$" ;
    .


iotics:AllowListShape
    a sh:NodeShape ;
    sh:description "Allow list values must be either the special values allowAll and allowNone, or they must be an identity." ;
    sh:xone (
        [
            sh:property [
                sh:path sh:allows ;
                sh:in ( iotics:allowAll iotics:allowNone ) ;
                sh:maxCount 1 ;
            ]
        ]
        [
            sh:property [
                sh:path sh:allows ;
                sh:node iotics:IdentityShape ;
            ]
        ]
    ) .

iotics:NetworkAllowListShape
    a sh:NodeShape ;
    sh:description "The identities allowed by the network must refer to Hosts. The default is None."@en ;
    sh:targetClass iotics:NetworkEndpoint ;
    sh:node iotics:AllowListShape ;
    sh:property [
        sh:path sh:allows ;
        sh:not [
            sh:and (
                [ sh:node iotics:IdentityShape ]
                [ sh:not [sh:class iotics:HostTwin ] ]
            )
        ]
    ] ;
    sh:rule [
        a sh:TripleRule ;
        sh:subject sh:this ;
        sh:predicate iotics:allows ;
        sh:object iotics:allowNone ;
        sh:condition [
            sh:property [
                sh:path iotics:allows ;
                sh:maxCount 0 ;
            ]
        ]
    ] .

iotics:ApiAllowListShape
    a sh:NodeShape ;
    sh:description "The identities allowed by the API must refer to Users or Twins. The default is All. Only Hosts have this"@en ;
    sh:targetClass sh:APIEndpoint ;
    sh:node iotics:AllowListShape ;
    sh:property [
        sh:path [ sh:inversePath iotics:hasEndpoint ] ;
        sh:class iotics:HostTwin ;
    ] ;
    sh:property [
        sh:path sh:allows ;
        sh:not [
            sh:and (
                [ sh:node iotics:IdentityShape ]
                [ sh:not [sh:class iotics:User ] ]
                [ sh:not [sh:class iotics:DigitalTwin] ]
            )
        ]
    ] ;
    sh:rule [
        a sh:TripleRule ;
        sh:subject sh:this ;
        sh:predicate iotics:allows ;
        sh:object iotics:allowAll ;
        sh:condition [
            sh:property [
                sh:path iotics:allows ;
                sh:maxCount 0 ;
            ]
        ]
    ] .


# Copyright (c) 2021 Iotic Labs Ltd. All rights reserved.

###############################################################################
# IOTICS Resource Ontology                                                    #
###############################################################################



## Base ontology for IOTICS Digital Twins and the data they share.

iotics:DigitalTwin
    a rdfs:Class ;
    rdfs:label "IOTICS Digital Twin"@en ;
    rdfs:comment "A virtual representation of a real asset, device, concept or person in an IOTICSpace"@en ;
    .

iotics:HostTwin
    a rdfs:Class ;
    rdfs:subClassOf iotics:DigitalTwin ;
    rdfs:label "IOTICS Host Twin"@en ;
    rdfs:comment "The Digital Twin of an IOTICS Host"@en ;
    .

iotics:advertises
    a rdf:Property ;
    rdfs:label "Advertises"@en ;
    rdfs:comment "This property lists (advertises) what mechanisms (points) the Digital Twin has to interact with other Twins"@en ;
    rdfs:domain iotics:DigitalTwin ;
    rdfs:range iotics:Point ;
    .

iotics:createdAt
    a rdf:Property ;
    rdfs:label "createdAt"@en ;
    rdfs:comment "The date on which a IOTICS Digital Twin was created"@en ;
    rdfs:domain iotics:DigitalTwin ;
    rdfs:range xsd:dateTime
    .

iotics:updatedAt
    a rdf:Property ;
    rdfs:label "updatedAt"@en ;
    rdfs:comment """The date on which an IOTICS Digital Twin, or any of its feeds
        or inputs was updated, including updates which do not otherwise modify the
        Digital Twin, its feeds or inputs"""@en ;
    rdfs:domain iotics:DigitalTwin ;
    rdfs:range xsd:dateTime ;
    .

iotics:Point
    a rdfs:Class ;
    rdfs:label "IOTICS Point"@en ;
    rdfs:comment """A means by which an IOTICS Digital Twin may interact with other twins, either outbound or inbound.
        Metadata describing the payload of the point is available when the point is described and therefore separate to the
        payload data. Interactions with the point are brokered and secured according to policies controlled by the twin."""@en ;
    .

iotics:pointName
    # we need to capture here the restructions:
    # - a twin can't have two different feeds with the same pointName
    # - a feed can't have two or more  pointName properties
	a rdf:Property ;
    rdfs:label "IOTICS Point name"@en ;
    rdfs:comment "The name of the point. This must be unique per Digital Twin."@en ;
	rdfs:domain iotics:Point ;
	rdfs:range xsd:string ;
	.

iotics:Feed
    a rdfs:Class ;
    rdfs:subClassOf iotics:Point ;
    rdfs:label "IOTICS Data Feed"@en ;
    rdfs:comment """A feed of data advertised by an IOTICS Digital Twin, used by the twin to broadcast values.
        Authorised twins following this feed receive data when published"""@en ;
    .

iotics:storesLast
    a rdf:Property ;
    rdfs:label "Stores last published payload"@en ;
    rdfs:comment "Whether most recent published payload might be available on this feed."@en ;
    rdfs:domain iotics:Feed ;
    rdfs:range xsd:boolean ;
    .

iotics:Input
    a rdfs:Class ;
    rdfs:subClassOf iotics:Point ;
    rdfs:label "IOTICS Input"@en ;
    rdfs:comment """By advertising an input, an IOTICS Digital Twin allows authorised twins to send messages whose meaning
    might be described by the properties of the input itself and of its payload.
    For example, inputs can be used to send commands to change the state of the underlying asset or to send messages
    that can be interpreted by the twin to implement request/response exchanges."""@en ;
    .

iotics:Value
    a rdfs:Class ;
    rdfs:label "IOTICS Payload Value"@en ;
    rdfs:comment "A semantic description of a Value used by Points when communicating data"@en ;
    .

iotics:valueKey
    a rdf:Property ;
    rdfs:subPropertyOf rdfs:label ;
    rdfs:label "Value Key"@en ;
    rdfs:comment "Unique identifier for this Value among those offered by its Point."@en ;
    rdfs:domain iotics:Value ;
    .

iotics:valueType
    a rdf:Property ;
    rdfs:label "Value Type"@en ;
    rdfs:comment "The xsd datatype of the Value, e.g. xsd:decimal. See https://www.w3.org/TR/rdf11-concepts/#xsd-datatypes"@en ;
    rdfs:domain iotics:Value ;
    # is there a way to restrct the range to some ontology that captures the xsd data types?
    .

iotics:valueUnit
    a rdf:Property ;
    rdfs:label "Value Unit"@en ;
    rdfs:comment "The unit of the value, e.g. obo:UO_0000027 representing Celsius degrees"@en ;
    rdfs:domain iotics:Value ;
    .

iotics:presents
    a rdf:Property ;
    rdfs:label "Presents"@en ;
    rdfs:comment """The property defining what values compose the payload of this point. For example, a feed for a weather station
        may have a payload with two values representing temperature and pressure defined as iotics:Value resources."""@en ;
    rdfs:domain iotics:Point ;
    rdfs:range iotics:Value ;
    .

iotics:hasEndpoint
    a rdf:Property ;
    rdfs:label "has Endpoint"@en ;
    rdfs:comment "Relates twins to their endpoints"@en ;
    rdfs:domain iotics:Twin ;
    rdfs:range iotics:Endpoint ;
    .

iotics:Endpoint
    a rdfs:Class ;
    rdfs:label "Endpoint"@en ;
    rdfs:comment "A means of interacting with a Twin"@en ;
    .

iotics:ApiEndpoint
    a rdfs:Class;
    rdfs:subClassOf iotics:Endpoint;
    .

iotics:NetworkEndpoint
    a rdfs:Class ;
    rdfs:subClassOf iotics:Endpoint ;
    .

iotics:allows
    a rdf:Property ;
    rdfs:label "Allows"@en ;
    rdfs:comment "Relates endpoints to the identities allowed to access them"@en ;
    rdfs:domain iotics:Endpoint ;
    # range handled via SHACL
    .

iotics:AllowListValue
    a rdfs:Class ;
    rdfs:label "Allow list value"@en ;
    rdfs:comment "Values indicating that all or no resources are allowed access via the network or API"@en ;
    .

iotics:allowAll
    a iotics:AllowListValue ;
    rdfs:label "Allow All"@en ;
    .

iotics:allowNone
    a iotics:AllowListValue ;
    rdfs:label "Allow None"@en ;
    .

iotics:User
    # Taken from Tim's concepts document, since this is now used in the ApiAllowListShape. What else can we say about it?
    rdf:type rdfs:Class ;
    rdfs:label "User"@en ;
    rdfs:comment "An Identity of type User"@en ;
    .