w3c / shacl

SHACL Community Group (Post-REC activitities)
32 stars 5 forks source link

add shacl-af sec 3.3 NodeShape Targets #3

Closed VladimirAlexiev closed 4 years ago

VladimirAlexiev commented 4 years ago

cc @HolgerKnublauch. @hmottestad if accepted, this affects https://github.com/eclipse/rdf4j/pull/2229

VladimirAlexiev commented 4 years ago

cc @rdstn

VladimirAlexiev commented 4 years ago

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!

HolgerKnublauch commented 4 years ago

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.

hmottestad commented 4 years ago

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.

HolgerKnublauch commented 4 years ago

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 ]. )

VladimirAlexiev commented 4 years ago

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. Target by property and object (property shape)
  2. Target by namespace (node shape)
  3. Target by datatype (node shape)
  4. Target by cardinality (property shape)
  5. Target by conjunction of properties (node shape)
# 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];
.
hmottestad commented 4 years ago
# 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.

hmottestad commented 4 years ago

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.

HolgerKnublauch commented 4 years ago

Makes sense. I guess we can close this PR here then?

hmottestad commented 4 years ago

https://rdf4j.org/shacl/extensions.html

hmottestad commented 4 years ago

@HolgerKnublauch you can close this now :)