Closed VladimirAlexiev closed 4 years ago
cc @rdstn
Note to self: edit "The following sub-sections define two such algorithms: ..."
Ok, I'll leave 2 examples (one of reference/full shapes, the other of literals/patterns).
I wish you asked me to cut down on examples when I sent the markdown to the mlist. I've spent time to format them as w3c html that will now be lost.
need a formal spec of both the syntax and the semantics... gray and the blue boxes
Cheers!
Yes I could have told you earlier, but I was assuming you look at existing sections for the expected style and content. This is a "formal" spec, and while some W3C groups also produce introductory tutorials, this is (for better or for worse) not one of them.
Would it be acceptable to define this based on other structures in SHACL?
I was thinking something along the lines of: "sh:targetShape provides a set of targets generated by a NodeShape where this set is equal to the set of targets found invalid by the same NodeShape if it were negated and provided with a set of all subjects and all objects as targets".
In my head this approach seems correct.
Yes we can and should define this using existing terms. Something like "The target nodes of a target shape TS
are all the subjects and objects from the data graph that conform to TS
." and similar for the syntax definition.
(There is no need to limit this to node shapes but also property shapes, because people could then write X sh:targetShape [ sh:path P ; sh:hasValue V ]. )
Hi @HolgerKnublauch, hope it's ok now: Defined syntax (gray box), semantics (blue box), cut down to 5 examples in one yellow-green box.
@hmottestad and @rdstn: Note that following Holger's suggestion, shapeTarget now allows PropertyShape or NodeShape. Using a PropertyShape is a great shortcut for the common case of using a single property+object. @hmottestad would your implementation support this?
Here are the 5 examples for easier reference:
# 1. Norwegians must have exactly one norwegianID
ex:NorwegianShape a sh:NodeShape;
sh:targetShape [sh:path ex:nationality; sh:hasValue ex:Norway];
sh:property [sh:path ex:norwegianID; sh:minCount 1; sh:maxCount 1];
.
# 2. Instances in namespace "company" must have appropriate class and dc:type
ex:CompanyShape a sh:NodeShape;
sh:targetShape [
sh:nodeKind sh:IRI;
sh:pattern "^https://company-graph.example.com/resource/company/";
];
sh:class ex:Company;
sh:property [sh:path dc:type; sh:in ("conglomerate" "collective" "enterprise")];
.
# 3. All langStrings must have one of a predefind set of languages
ex:langStringShape a sh:NodeShape;
sh:targetShape [sh:datatype rdf:langString];
sh:languageIn ("en" "bg");
.
# 4. Steve is very popular, so everyone who knows at least three people must know Steve
ex:Personshape a sh:NodeShape;
sh:targetShape [sh:path foaf:knows; sh:minCount 3];
sh:property [sh:path foaf:knows; sh:hasValue ex:Steve];
.
# 5. Parties (defined as foaf:Organization with appropriate dc:type) must stick to one of two politics
ex:PartyShape a sh:NodeShape;
sh:targetShape [a sh:NodeShape;
sh:property [sh:path rdf:type; sh:hasValue foaf:Organization];
sh:property [sh:path dc:type; sh:hasValue "political-party"]];
sh:property [sh:path ex:politics; sh:in ("Democrat" "Republican"); sh:minCount 1; sh:maxCount 1];
.
# 2. Instances in namespace "company" must have appropriate class and dc:type
ex:CompanyShape a sh:NodeShape;
sh:targetShape [
sh:nodeKind sh:IRI;
sh:pattern "^https://company-graph.example.com/resource/company/";
];
sh:class ex:Company;
sh:property [sh:path dc:type; sh:in ("conglomerate" "collective" "enterprise")];
.
I believe this should have a minCount too.
I've created a new namespace for this under Eclipse RDF4J and I have a PR open here: https://github.com/eclipse/rdf4j/pull/2418
I hope it's ok that I more of less copied over the changes from this PR.
Makes sense. I guess we can close this PR here then?
@HolgerKnublauch you can close this now :)
cc @HolgerKnublauch. @hmottestad if accepted, this affects https://github.com/eclipse/rdf4j/pull/2229