ShEx Examples
Obsolete - please see ShEx Primer
Shape Expressions examples
In the following examples we omit prefix declarations assuming that we are employing the namespaces defined in prefix.cc
Standard examples
The following examples work in all the implementations.
Issues/Users Example
In this example we define the shapes of Issues and Users as:
<IssueShape> { # A Issue shape :state ( :unassigned :assigned ), # has a state with 2 possible values :reportedBy @<UserShape>, # is reported by a user :reportedOn xsd:date, # is reported on a date ( :reproducedBy @<UserShape> # can optionally have 2 properties , :reproducedOn xsd:date # reproducedBy/On )?, :related @<IssueShape>* # is related to several other issues } <UserShape> { # A user shape can have either ( foaf:name xsd:string # name or | foaf:givenName xsd:string+ , # several given names and foaf:familyName xsd:string # family name ), foaf:mbox shex:IRI ? # mbox Optional, any IRI }
Example with conjunction
A concept that has a rdfs:label and a rdfs:comment and any other triples.
<concept> { rdfs:label . , rdfs:comment . , . . * # this declaration could be omitted if we employ open semantics }
Example with disjunction
A concept that has either rdfs:label or skos:prefLabel and any other triple
<concept> { ( rdfs:label . | rdfs:comment . ), . . * # this line could be omitted if we use open semantics }
Example with xsd:string
A concept that has rdfs:label and a value of type xsd:string
<concept { rdfs:label xsd:string }
Example with some specific values
A concept that has a label with the values "cat" or "dog"
<concept> { rdfs:label ("car" "dog") }
Example with lists
A concept that has as values a list of integers
:a { :p @<listOfInt> } <listOfInt> { rdf:first xsd:integer , ( rdf:rest (rdf:nil) | rdf:rest @<listOfInt>) }
Open/Closed semantics of shapes
Example of a single arc
A concept that has only rdfs:label and does not have any other property.
<concept> { rdfs:label . }
It validates an object with that single property. Try it
But using the closed semantics it does not validate an object with more than that property.
The shape can be opened using . . *
<concept> { rdfs:label . , . . * }
Proposed Extensions examples
The following examples only work in some implementations
Example with language tags
A concept that has rdfs:label an English or an Spanish literal
<concept> { rdfs:label ( @en @es ) }
Regular expressions
A concept that has a label that contains the string "papapa"
<concept> { rdfs:label ( /pa{3}/ )