Shex/Obsolete/Level 2

From Semantic Web Standards

Obsolete - please see ShEx Semantics

(Possible extention format) Semantics for SHEX

Just an idea no updating at the moment to this document.

The semantics extension is now only defined in the RDF serialization format.

Work in progress, todo

  1. add RDF property definitions to the level2 definition
  2. not happy/finished yet with the integration into the existing rdfs/owl or any other schema that at semantic meaning to classes and predicates.
    1. integrate rdf,rdfs,owl and skos defs

class semantics

Level 2 has an extra shape/class to define classes with a semantic meaning. It is still possible to define shapes that can be referenced by shape properties.

Note
It possible to manually add semantics to resource shape and not use se:Class def. 

The type definition for level 1 is automatically added. (see insert queries below)


For each class a rdfs:subClassOf can be defined. Also the type definition for level 1 is automatically added. (see insert queries below)


Written semantic meaning can be added to a class using the rdfs:label and rdfs:comment predicates.

TODO, extend or add more.


A class can be defined VIRTUAL, meaning that no instances of the class be created and should be one of its sub class types. A OrRuleGroup is automaticly inserted to enforce this in level 1. (see queries below)

Property semantics

Shape properties themself to not define any semantics, they are linked to an RDF property which defines its semantic meaning. List of properties for rdfs:Property to add semantics

  1. rdfs:subPropertyOf
  2. more to add

It possible define one more multiple default value(s) for a certain property. The multiplicity should be then defined as having an multiplicity of at least 1 or more.

RDF level 2 definition

The blue text indicate the Level 2 element, whereas the grey element indicate the automatically added triples needed for Level 1. See SPARQL construct queries/rules below that imply them.

@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rs:    <http://open-services.net/ns/core#> .
@prefix se:    <http://www.w3.org/2013/ShEx/Definition#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

se:occursRule a se:OrRuleGroup; #no obligation to be compatible with current SHEX language
  rs:occurs rs:Exactly-one;
  rs:property [ a se:EnumerationSetProperty;
    rs:occurs rs:Exactly-one;
    rs:name "occurs";
    rs:propertyDefinition rs:occurs;
    rs:allowedValue rs:Exactly-one, rs:One-or-many,rs:Zero-or-many,rs:Zero-or-one;
  ];
  rs:property [ a se:ValueProperty;
    rs:occurs rs:Exactly-one;
    rs:name "occurs";
    rs:propertyDefinition rs:occurs;
    rs:valueType xsd:integer;
  ];
  se:subGroup [ a se:AndRuleGroup;
    rs:occurs rs:Exactly-one;
    rs:property [ a se:ValueProperty;
      rs:occurs rs:Exactly-one;
      rs:name "occursmin";
      rs:propertyDefinition rs:occursmin;
      rs:valueType xsd:integer;
    ];
   rs:property [ a se:ValueProperty;
     rs:occurs rs:Exactly-one;
     rs:name "occursmax";
     rs:propertyDefinition rs:occursmax;
     rs:valueType xsd:integer;
   ];
 ].  

se:RuleGroup  a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:occursRule;#use of rule but its not a subclass
  se:isVirtual true;
  rs:property [ a se:ShapeProperty;
    rs:name "subGroup";
    rs:occurs rs:Zero-or-many;
    rs:propertyDefinition se:subGroup;
    rs:valueShape se:RuleGroup;
  ];
  rs:property [ a se:ShapeProperty;
    rs:name "property";
    rs:occurs rs:Zero-or-many;
    rs:propertyDefinition rs:property;
    rs:valueShape se:Property;
  ];
  rs:property [ a se:EnumerationSetProperty;
      rs:occurs rs:Exactly-one;
      rs:name "type";
      rs:propertyDefinition rdf:type;
      rs:allowedValue se:RuleGroup, se:OrRuleGroup, se:AndRuleGroup, rs:ResourceShape, se:Class;
  ];
  se:subGroup [ a se:OrRuleGroup ; #Define it as VIRTUAL, by forcing it to include one of its 'childs'
    rs:occurs        rs:Exactly-one; 
    se:subGroup        se:OrRuleGroup;
    se:subGroup        se:AndRuleGroup;
  ]. 

se:OrRuleGroup a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:RuleGroup;
  rdfs:subClassOf se:RuleGroup;
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "type";
    rs:propertyDefinition rdf:type;
    rs:allowedValue se:OrRuleGroup;
  ]. 

se:AndRuleGroup a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:RuleGroup;
  rdfs:subClassOf se:RuleGroup;
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "type";
    rs:propertyDefinition rdf:type;
    rs:allowedValue se:AndRuleGroup, rs:ResourceShape,se:Class;
  ]. 
  
rs:ResourceShape a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:AndRuleGroup;
  rdfs:subClassOf se:AndRuleGroup;
  rs:property [ a se:ValueProperty ;
    rs:occurs rs:Zero-or-one;
    rs:name "name";
    rs:propertyDefinition rs:name;
    rs:valueType xsd:string ;
  ];
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "type";
    rs:propertyDefinition rdf:type;
    rs:allowedValue rs:ResourceShape,se:Class;
  ]. 

se:Class a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:AndRuleGroup;
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "type";
    rs:propertyDefinition rdf:type;
    rs:allowedValue se:Class;
  ];  
  rdfs:subClassOf rdfs:Class;
  rdfs:subClassOf rs:ResourceShape;
  rs:property [ a se:EnumerationSetProperty;
    rs:occurs rs:Exactly-one;
    rs:name "occurs";
    rs:propertyDefinition rs:occurs;
    rs:allowedValue rs:Exactly-one;
  ];
  #properties to add semantic meaning to class
  rs:property [ a se:ShapeProperty ;
    rs:occurs rs:Zero-or-many;
    rs:name "subClassOf";
    rs:propertyDefinition rdfs:subClassOf;
    rs:valueShape se:Class; #no we force all class defs to also have a SHEX shape definition
  ];
  rs:property [ a se:ValueProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "isVirtual";
    rs:propertyDefinition se:isVirtual;
    rs:valueType xsd:boolean;
    rs:defaultValue false;
  ];
  rs:property [ a se:ValueProperty ;
    rs:occurs rs:Zero-or-one;
    rs:name "label";
    rs:propertyDefinition rdfs:label;
    rs:valueType xsd:string;
  ];
  rs:property [ a se:ValueProperty ;
    rs:occurs rs:Zero-or-one;
    rs:name "comment";
    rs:propertyDefinition rdfs:comment;
    rs:valueType xsd:string;
  ].   

se:Property a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:occursRule; #use of the rule group
  se:isVirtual true;
  rs:property [ a se:ValueProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "name";
    rs:propertyDefinition rs:name;
    rs:valueType xsd:string ;
  ];  
  rs:property [ a se:ShapeProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "propertyDefinition";
    rs:propertyDefinition rs:propertyDefinition;
    rs:valueShape rdfs:Property ;
  ];  
  rs:property [ a se:ShapeProperty ;
    rs:occurs rs:Zero-or-many;
    rs:name "constraint";
    rs:propertyDefinition se:constraint;
    rs:valueShape se:ConstraintRule ;
  ];  
  rs:property [ a se:StemProperty ;
    rs:occurs rs:Zero-or-many;
    rs:name "defaultValue";
    rs:propertyDefinition se:defaultValue;
    rs:rule ".";
  ]; 
  #define a constrain, the occurs prop can only be rs:Exactly-one or rs:One-or-Many when a se:defaultValue is given 
  se:constraint [ a se:ConstraintRule ;
    se:language se:sparql;
    se:rule "{?s se:defaultValue ?rpt . { ?s rs:occurs rs:Exactly-one . } UNION { ?s rs:occurs rs:One-or-Many . }} UNION { FILTER NOT EXISTS { ?s se:defaultValue ?rpt . }}"
  ]. 
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "type";
    rs:propertyDefinition rdf:type;
    rs:allowedValue se:Property, se:ShapeProperty, se:ValueProperty, se:EnumerationSetProperty, se:StemProperty;
  ];
  se:subGroup [ a se:OrRuleGroup ; #Define it as VIRTUAL, by forcing it to include one of its 'childs'
    rs:occurs        rs:Exactly-one; 
    se:subGroup        se:ShapeProperty;
    se:subGroup        se:ValueProperty;
    se:subGroup        se:EnumerationSetProperty;
    se:subGroup        se:StemProperty;
  ].

rdfs:Property a se:Class;
   rs:occurs rs:Exactly-one;
   rs:property [ a se:EnumerationSetProperty ;
     rs:occurs rs:Exactly-one;
     rs:name "type";
     rs:propertyDefinition rdf:type;
     rs:allowedValue rdfs:Property;
   ]; 
   rs:property [ a se:ShapeProperty ;
     rs:occurs rs:Zero-or-one;
     rs:name "subPropertyOf";
     rs:propertyDefinition rdfs:subPropertyOf;
     rs:valueShape rdfs:Propert ;
   ].
   
  
se:ShapeProperty a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:Property;
  rdfs:subClassOf se:Property;
  rs:property [ a se:ShapeProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "valueShape";
    rs:propertyDefinition rs:valueShape;
    rs:valueShape rs:ResourceShape ;
  ];  
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "type";
    rs:propertyDefinition rdf:type;
    rs:allowedValue se:ShapeProperty;
  ]. 

se:ValueProperty a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:Property;
  rdfs:subClassOf se:Property;
  rs:property [ a se:StemProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "valueType";
    rs:propertyDefinition rs:valueType;
    rs:rule "xsd:~";
  ];  
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:One-or-many;
    rs:name "type";
    rs:propertyDefinition rdf:type;
    rs:allowedValue se:ValueProperty;
  ]. 
  
se:EnumerationSetProperty a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:Property;
  rdfs:subClassOf se:Property;
  rs:property [ a se:StemProperty ;
    rs:occurs rs:One-or-many;
    rs:name "allowedValue";
    rs:propertyDefinition rs:allowedValue;
    rs:rule ".";
  ];  
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "type";
    rs:propertyDefinition rdf:type;
    rs:allowedValue se:EnumerationSetProperty;
  ].  

se:StemProperty a se:Class;
  rs:occurs rs:Exactly-one;
  se:subGroup se:Property;
  rdfs:subClassOf se:Property;
  rs:property [ a se:ValueProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "rule";
    rs:propertyDefinition se:rule;
    rs:valueType xsd:string ;
  ];    
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "type";
    rs:propertyDefinition rdf:type;
    rs:allowedValue se:StemProperty;
 ].

se:ConstraintRule a se:Class ;
  rs:occurs rs:Exactly-one;
  rs:property [ a se:EnumerationSetProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "language";
    rs:propertyDefinition se:language;
    rs:allowedValue se:js,se:sparql;
  ];
  rs:property [ a se:ValueProperty ;
    rs:occurs rs:Exactly-one;
    rs:name "rule";
    rs:propertyDefinition se:rule;
    rs:valueType xsd:string ;
  ].

SPARQL rules for level 1

These are the rules that add the elements needed to encode Level 2 into Level 1.

I am still thinking whether to add support into level 2 that allows for setting values and adding triples into 'parent' class instances.

Add the default rs:occurs to all resource shapes

INSERT
{
  ?class rs:occurs rs:Exactly-one;
}
WHERE 
{
  ?type rdfs:subClassOf* rs:ResourceShape .
  ?class a ?type .
}

When a se:subClass extends from another se:subClass, also include the parent shape expression

INSERT
{
  ?class se:subGroup ?parent .
}
WHERE 
{
  ?type rdfs:subClassOf* se:Class .
  ?class a ?type .
  ?class rdfs:subClassOf ?parent .
  ?parent a ?type .
} 

The encoding of the rdf:type and rdfs:subClassOf into Level 1 SHEX

INSERT 
{
  ?class rs:property _:prop .
   _:prop a se:EnumerationSetProperty ;
      rs:occurs rs:Exactly-one;
      rs:name "type";
      rs:propertyDefinition rdf:type;
      rs:allowedValue ?childs.
}
WHERE
{
   ?type rdfs:subClassOf* se:Class .
   ?class a ?type .
   ?childs rdfs:subClassOf* ?class .
   ?childs a ?type .
}

The encoding of VIRTUAL into level 1 SHEX

INSERT 
{
  ?class se:subGroup _:rule .
  _:rule  a se:OrRuleGroup ; 
    rs:occurs        rs:Exactly-one; 
    se:subGroup        ?childs .
}
WHERE
{
  ?type rdfs:subClassOf* se:Class .
  ?class a ?type .
  ?class se:isVirtual true .
  ?childs rdfs:subClassOf ?class .
  ?childs a ?type .
}