<samples9298996> rdf:type bf:Text ; rdf:type bf:Work ; bf:title "Oliver Twist." ; bf:class <id.loc.gov/…/PZ3> ; bf:creator [ rdf:type bf:Person ; bf:label "Dickens, Charles, 1812-1870." ; ] . <id.loc.gov/…/PZ3> rdf:type bf:LCC ; bf:label "PZ3.D55O165PR4567" .
<samples9298996> rdf:type bf:Text ; rdf:type bf:Work ; bf:title "Oliver Twist." ; bf:class <id.loc.gov/…/PZ3> ; bf:creator [ rdf:type bf:Person ; bf:label "Dickens, Charles, 1812-1870." ; ] . <id.loc.gov/…/PZ3> rdf:type bf:LCC ; bf:label "PZ3.D55O165PR4567" .
<Work> EXTRA rdf:type { rdf:type [bf:Work] ? ; bf:title LITERAL ; bf:class @<Classification> * ; bf:creator @<Person> OR @<Organization> + ; bf:derivedFrom IRI * ; } <Classification> [<http://id.loc.gov/…/>~] AND EXTRA rdf:type { rdf:type [bf:LCC] ? ; bf:label LITERAL ; }
validating samples9298996bad as Work: validating http://...oliverTwist: Error validating http://...oliverTwist as nodeKind literal: iri found when literal expected
inst:Alice @ school:Enrollee, inst:Bob @ school:Enrollee, inst:Claire @ school:Enrollee, inst:Don @ school:Enrollee
{FOCUS, foaf:age, _} @ school:Enrollee
Useful data needs consistent structure:
Detect and correct errors:
@prefix : <http://www.w3.org/2012/12/rdf-val/SOTA-ex#> . @prefix foaf: <http://xmlns.com/foaf/0.1/'> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . <issue7> a :Issue , :SecurityIssue ; :state :unassigned ; :reportedBy <user6> , <user2> ; # cardinality 1 :reportedOn "2012-12-31T23:57:00"^^xsd:dateTime ; :assignedTo <user2>, <user1> ; :assignedOn "2012-11-31T23:57:00"^^xsd:dateTime ; # reproduced before being reported :related <issue4>, <issue3>, <issue2> . # referenced issues not included <issue4> # a ??? missing type arc :state :unsinged ; # misspelled # :reportedBy ??? - missing :reportedOn "2012-12-31T23:57:00"^^xsd:dateTime . <user2> a foaf:Person ; foaf:givenName "Alice" ; foaf:familyName "Smith" ; foaf:phone <tel:+1.555.222.2222> ; foaf:mbox <mailto:alice@example.com> . <user6> a foaf:Agent ; # should be foaf:Person foaf:givenName "Bob" ; # foaf:familyName "???" - missing foaf:phone <tel:+.555.222.2222> ; # malformed tel: URL foaf:mbox <mailto:alice@example.com> .
<Work> EXTRA rdf:type { rdf:type [bf:Work] ? ; bf:title LITERAL ; bf:class @<Classification> * ; bf:creator @<Person> OR @<Organization> + ; bf:derivedFrom IRI * ; } <Classification> [<http://id.loc.gov/…/>~] AND EXTRA rdf:type { rdf:type [bf:LCC] ? ; bf:label LITERAL ; }
<Work> EXTRA rdf:type { rdf:type [bf:Work] ? ; bf:title LITERAL ; bf:class @<Classification> * ; bf:creator @<Person> OR @<Organization> + ; bf:derivedFrom IRI * ; } <Classification> [<http://id.loc.gov/…/>~] AND EXTRA rdf:type { rdf:type [bf:LCC] ? ; bf:label LITERAL ; }
<Work> EXTRA rdf:type { rdf:type [bf:Work] ? ; bf:title LITERAL ; bf:class @<Classification> * ; bf:creator @<Person> OR @<Organization> + ; bf:derivedFrom IRI * ; } <Classification> [<http://id.loc.gov/…/>~] AND EXTRA rdf:type { rdf:type [bf:LCC] ? ; bf:label LITERAL ; }
<samples9298996> rdf:type bf:Text ; rdf:type bf:Work ; bf:title "Oliver Twist." ; bf:class <id.loc.gov/…/PZ3> ; bf:creator [ rdf:type bf:Person ; bf:label "Dickens, Charles, 1812-1870." ; ] . <id.loc.gov/…/PZ3> rdf:type bf:LCC ; bf:label "PZ3.D55O165PR4567" .
A <Work> must have exactly one bf:title with value LITERAL:
<Work> { bf:title LITERAL ; }
<samples9298996> bf:title "Oliver Twist." . <samples9298996bad> bf:title <http://...oliverTwist> .try it
validating samples9298996bad as Work: validating http://...oliverTwist: Error validating http://...oliverTwist as nodeKind literal: iri found when literal expected
Permit some data to have a type arc identifying it as a <Work>:
<Work> { rdf:type [bf:Work] ? ; bf:label LITERAL ; }
[]
s denote a value set.?
' code means min: 0, max: 1 (like regular expressions).<samples9298996> a bf:Work ; bf:title "Oliver Twist." . <samples9298996b> a bf:Work ; bf:title "Oliver Twist." . <samples9298996bad> a bf:Krow ; bf:title "Oliver Twist" .try it
validating samples9298996bad as Work: validating http://bibframe.org/vocab/Krow: Error validating http://bibframe.org/vocab/Krow as values [<http://bibframe.org/vocab/Work>]: value http://bibframe.org/vocab/Krow not found in set [<http://bibframe.org/vocab/Work>]
Add a reference to another shape:
<Work> { rdf:type [bf:Work] ? ; bf:label LITERAL ; bf:class @<Classification> * ; } <Classification> { rdf:type [bf:LCC] ? ; bf:label LITERAL ; }
*
' code means min: 0, max: * (like regular expressions).<samples9298996> bf:title "Oliver Twist." ; bf:class <http://id.loc.gov/…/PZ3> . <http://id.loc.gov/…/PZ3> a bf:LCC ; bf:label "PZ3.D55O165PR4567" . <samples9298996b> bf:title "Oliver Twist." ; bf:class [ bf:label "PZ3.D55O165PR4567" ]. <samples9298996bad> bf:title "Oliver Twist." ; bf:class [ a bf:LCD ; bf:label "PZ3.D55O165PR4567" ].try it
validating samples9298996bad as Work: validating _:b1: validating http://bibframe.org/vocab/LCD:, Error validating http://bibframe.org/vocab/LCD as values: [<http://bibframe.org/vocab/LCC>]}: value <http://bibframe.org/vocab/LCD> not found in set [<http://bibframe.org/vocab/LCC>]
Or a reference to an authority:
<Work> { rdf:type [bf:Work] ? ; bf:label LITERAL ; bf:class @<Classification> * ; } <Classification> [<http://id.loc.gov/…/>~]
[]
s denote a value set.<samples9298996> bf:title "Oliver Twist." ; bf:class <http://id.loc.gov/…/PZ3> . <samples9298996bad> bf:title "Oliver Twist." ; bf:class <http://id.loc.gov/authorities/PZ3> . <samples9298996badb> bf:title "Oliver Twist." ; bf:class [ bf:label "PZ3.D55O165PR4567" ].try it
validating samples9298996bad as Work: validating <http://id.loc.gov/authorities/PZ3>: NodeConstraintError: expected to match [<http://id.loc.gov/authorities/classification/>~]
validating samples9298996bad as Work: validating _:b0: NodeConstraintError: expected to match [<http://id.loc.gov/authorities/classification/>~]
Or a reference to a structure identifed by and authority:
<Work> { rdf:type [bf:Work] ? ; bf:label LITERAL ; bf:class @<Classification> * ; } <Classification> [<http://id.loc.gov/…/>~] AND { rdf:type [bf:LCC] ? ; bf:label LITERAL ; }
()
s.<samples9298996> bf:title "Oliver Twist." ; bf:class <http://id.loc.gov/…/PZ3> . <http://id.loc.gov/…/PZ3> a bf:LCC ; bf:label "PZ3.D55O165PR4567" . <samples9298996bad> bf:title "Oliver Twist." ; bf:class <http://id.loc.gov/authorities/PZ3> . <http://id.loc.gov/authorities/PZ3> a bf:LCC ; bf:label "PZ3.D55O165PR4567" . <samples9298996badb> bf:title "Oliver Twist." ; bf:class <http://id.loc.gov/…/PZ3999> .try it
validating samples9298996bad as Work: validating >http://id.loc.gov/authorities/PZ3>: validating <http://id.loc.gov/authorities/PZ3> as Classification: NodeConstraintError: expected to match [<http://id.loc.gov/…/>~]
validating samples9298996bad as Work: validating <http://id.loc.gov/…/PZ3999>: validating <http://id.loc.gov/…/PZ3999> as Classification: Missing property: <http://bibframe.org/vocab/label>
You may accept multiple forms of creator.
<Work> { rdf:type [bf:Work] ? ; bf:label LITERAL ; bf:class . * ; bf:creator @<Person> OR @<Organization> + ; } <Person> { rdf:type [bf:Person] ? ; bf:label LITERAL ; } <Organization> { EXTRA rdf:type rdf:type [bf:Organization] ; bf:label LITERAL ; org:member @<Person> OR @<Organization> * }
<samples9298996> bf:title "Oliver Twist." ; bf:creator [ rdf:type bf:Person ; bf:label "Dickens, Charles, 1812-1870." ] . <wp-55-45-1> bf:title "Nixon blasts 'false charges'" ; bf:creator <WP> . <WP> rdf:type bf:Organization , bf:Newpaper ; bf:label "Washington Post" ; org:member <BobWoodward>, <CarlBernstein> . <BobWoodward> bf:label "Bob Woodward" . <CarlBernstein> bf:label "Carl Bernstein" .try it
IMPORT <User.shex> :Employee { &:name ; schema:worksFor @:Company } :Company { schema:employee @:Employee ; schema:founder @:Person ; }
PREFIX : <http://a.example/ns#>
PREFIX schema: <http://schema.org/>
:Person {
$:name ( schema:name .
| schema:givenName . ; schema:familyName .
) ;
schema:email .
}
Start with a general rule about a structure:
<ObservationShape> { … :component { :code . ; :value . } * }
An observation contains N components, each with a code and a value.
Use that structure in a derivative shape:
<ObservationShape> { … :component { :code . ; :value . } * }
<BP> -<ObservationShape> { … :component { :code [ "systolic" ] ; :value . }; :component { :code [ "diastolic" ] ; :value . } }
An BP observation contains 2 components with codes for systolic and diastolic.
Use that structure in turn in an extended shape:
<ObservationShape> { … :component { :code . ; :value . } * }
<BP> -<ObservationShape> { … :component { :code [ "systolic" ] ; :value . }; :component { :code [ "diastolic" ] ; :value . } }
<PostureBP> &<BP> { … :component { :code [ "posture" ] ; :value . }; }
An PostureBP observation has an additional components with a code for posture.
HIGH { value: 1, low: 1, high: 1 } LOW { value: 1, low: 0, high: 1 } <EventShape> { HIGH schema:startDate @<Date> OR @<DateTime> ; LOW schema:endDate @<Date> OR @<DateTime> ; LOW schema:actor @<Person> } <Person> { LOW schema:name xsd:string }
# Shape Expression for Diseases in Wikidata PREFIX wd: <http://www.wikidata.org/entity/> PREFIX p: <http://www.wikidata.org/prop/> PREFIX ps: <http://www.wikidata.org/prop/statement/> PREFIX pq: <http://www.wikidata.org/prop/qualifier/> PREFIX pr: <http://www.wikidata.org/prop/reference/> PREFIX prov: <http://www.w3.org/ns/prov#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX do: <http://purl.obolibrary.org/obo/DOID_> start = @<wikidata-disease> <wikidata-disease> { p:P31 { # instance of disease ps:P31 [ wd:Q12136 ]; # instance of disease $<has-do-reference> prov:wasDerivedFrom @<do-reference>; } ; p:P279 { # subclass of ps:P279 @<wikidata-disease>; &<has-do-reference> } * ; p:P2888 EXTRA prov:wasDerivedFrom { # exact match ps:P2888 [ do:~ ]; prov:wasDerivedFrom @<do-reference> ? } + ; } <do-reference> { # stated in pr:P248 @<version-disease-ontology> ; # retrieved pr:P813 xsd:dateTime ; # Disease ontology ID pr:P699 @<disease-ontology-id> ; } <disease-ontology-id> LITERAL /^DOID:[0-9]+$/ <version-disease-ontology> { # edition or translation of Disease Ontology p:P629 { ps:P629 [ wd:Q5282129 ] } ; }
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX prov: <http://www.w3.org/ns/prov#> PREFIX p: <http://www.wikidata.org/prop/> PREFIX pr: <http://www.wikidata.org/prop/reference/> PREFIX ps: <http://www.wikidata.org/prop/statement/> start = @<wikidata_item> <wikidata_item> { p:P1748 { ps:P1748 LITERAL ; prov:wasDerivedFrom @<reference> }+ } <reference> { pr:P248 IRI ; pr:P813 xsd:dateTime ; pr:P699 LITERAL }
Endpoint: https://query.wikidata.org/bigdata/namespace/wdq/sparql Query: SELECT ?item ?itemLabel WHERE { ?item wdt:P279* wd:Q12078 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } LIMIT 10
<MedicationRequest> { :status @<code> AND {fhir:value ["active" "on-hold" "cancelled" "completed"]}?; :intent @<code> AND {fhir:value ["proposal" "plan" "order" "instance-order"]}; ( :medicationCodeableConcept @<CodeableConcept> | :medicationReference @<MedicationReference> ); :subject ( @<PatientReference> OR @<GroupReference> ); :requester @<MedicationRequest.requester>; :reasonCode @<CodeableConcept>*; :reasonReference ( { fhir:link @<Condition> } OR { fhir:link @<Observation> } )*; :dispenseRequest { :dispenseRequest.numberOfRepeatsAllowed @<positiveInt>?; :dispenseRequest.quantity @<SimpleQuantity>?; :dispenseRequest.performer @<Reference>? } :substitution @<MedicationRequest.substitution>?; } # Any restrictions on medication substitution <MedicationRequest.substitution> CLOSED { fhir:Element.id @<string>?; # xml:id (or equivalent in JSON) fhir:Element.extension @<Extension>*; # Additional Content defined by # implementations fhir:BackboneElement.modifierExtension @<Extension>*; # Extensions that cannot be ignored :substitution.allowed @<boolean>; # Whether substitution is allowed or # not :substitution.reason @<CodeableConcept>?; # Why should (not) substitution be # made fhir:index xsd:integer? # Relative position in a list } # Who/What requested the Request <MedicationRequest.requester> CLOSED { fhir:Element.id @<string>?; # xml:id (or equivalent in JSON) fhir:Element.extension @<Extension>*; # Additional Content defined by # implementations fhir:BackboneElement.modifierExtension @<Extension>*; # Extensions that cannot be ignored :requester.agent # Who ordered the initial # medication(s) ( @<PractitionerReference> OR @<OrganizationReference> OR @<PatientReference> OR @<RelatedPersonReference> OR @<DeviceReference> ); :requester.onBehalfOf @<Reference>?; # Organization agent is acting for fhir:index xsd:integer? # Relative position in a list }
(data:sourceURL IRI; data:contentType xsd:string)?
foaf:name LITERAL | foaf:givenName LITERAL; foaf:familyName LITERAL
<Person> { foaf:knows @<Person> }
fhir:component { fhir:code [sct:systolic]; fhir:value xsd:integer };
fhir:component { fhir:code [sct:diastolic]; fhir:value xsd:integer };
compare to
A User with a name and mbox
PREFIX foaf: <http://xmlns.com/foaf/> <UserShape> { (foaf:name LITERAL | foaf:givenName LITERAL+, foaf:familyName LITERAL), foaf:mbox IRI }
A User with a name and mbox
PREFIX foaf: <http://xmlns.com/foaf/> <UserShape> { (foaf:name LITERAL | foaf:givenName LITERAL+, foaf:familyName LITERAL), foaf:mbox IRI }
A User with a name and mbox
PREFIX foaf: <http://xmlns.com/foaf/> <UserShape> { (foaf:name LITERAL | foaf:givenName LITERAL+, foaf:familyName LITERAL), foaf:mbox IRI }
compare with other schema languages...
(element foaf:name { xsd:string } | (element foaf:givenName { xsd:string }+, element foaf:familyName { xsd:string })), element foaf:mbox { xsd:anyURI }
(N|(G+F))M
NM
GFM
GGGFM
<xs:complexType name="UserContent"> <xs:sequence> <xs:choice> <xs:element name="name" type="xs:string"/> <xs:sequence> <xs:element maxOccurs="unbounded" name="givenName" type="xs:string"/> <xs:element name="familyName" type="xs:string"/> </xs:sequence> </xs:choice> <xs:element name="mbox" type="xs:anyURI"/> </xs:sequence> </xs:complexType>
<MedicationRequest> { :status @<code>; :intent @<code>; ( :medicationCodeableConcept @<CodeableConcept> | :medicationReference @<MedicationRef> ); :subject ( @<PatientRef> OR @<GroupRef> ); :requester { :requester.agent ( @<PractitionerRef> OR @<PatientRef> ); :requester.onBehalfOf @<Ref>?; :reasonCode @<CodeableConcept>*; :reasonReference ( { fhir:link @<Condition> } OR { fhir:link @<Observation> } )*; :dispenseRequest { # backbone element :dispenseRequest.numberOfRepeatsAllowed @<positiveInt>?; :dispenseRequest.quantity @<SimpleQuantity>?; :dispenseRequest.performer @<Reference>? }; }