w3c / shacl

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

RDF-star and SPARQL-star support for SHACL #15

Closed Helpys closed 9 months ago

Helpys commented 2 years ago

Support the Function and Operator Definitions of SPARQL-star in the SPARQL-based Constraints of SHACL.

Function and Operator Definitions:

TRIPLE
SUBJECT
PREDICATE
OBJECT
isTRIPLE

Reference: https://www.w3.org/2021/12/rdf-star.html https://www.w3.org/TR/shacl

afs commented 2 years ago

From the short discussion on: https://github.com/w3c/rdf-star/issues/122

1/ RDF-star introduces an kind of RDF term - the quoted triple (was called "embedded triple"). A new object value for sh:nodeKind is needed.

2/ It would be convenient to navigate quoted triples in a similar manner to sh:property navigates triples.

sh:subject, sh:predicate, sh:object (the "isTriple" function is sh:nodeKind sh:QuotedTriple).

then, for example:

:x sh:targetSubjectOf :source ;
   sh:subject [ sh:hasValue <http://example/s> ] ;
   .

to validate

 << <http://example/s> :p :o>> :source :z .

3/ Targets for quoted triples.

4/ Support for annotation syntax From : @pchampin https://lists.w3.org/Archives/Public/public-rdf-star/2021Jul/0006.html

e.g.

     :alice :workingFor :acme {| :since "2013"^^xsd:gYear |}.

for

     :alice :workingFor :acme .
    << :alice :workingFor :acme . >> {| :since "2013"^^xsd:gYear |}.

@pchampin suggests It would be nice to be able to constrain that pattern in an equally concise way in SHACL, something like:

    ex:PersonShape
        a sh:NodeShape ;
        sh:targetClass ex:Person ;
        sh:property [
            sh:path ex:workingFor ;
            sh:class ex:Company ;
            _shx:annotation_ [
                sh:path ex:since ;
                sh:datatype xsd:gYear ;
            ]
        ] .
afs commented 2 years ago

@Helpys Do you have some specific use cases in mind?

Helpys commented 2 years ago

With the specific use case in mind, the content to evaluate is wrapped in a twice-nested triple: << << ex:InvalidCountry ex:germanLabel "Switzerland"@en >> ex:accordingTo ex:employee22 >> ex:date "1971-07-07"^^xsd:date .

The idea was to use the sh:sparql sh:selectnode, to "unfold" the triple an evaluate the used language: SELECT ?o WHERE { ?tt ex:date ?date BIND(SUBJECT(?tt) as ?t) BIND(SUBJECT(?t) as ?s) BIND(PREDICATE(?t) as ?p) BIND(OBJECT(?t) as ?o) FILTER (!isLiteral(?o) || !langMatches(lang(?o), "de")) }

TallTed commented 2 years ago

@afs -- Re: https://github.com/w3c/shacl/issues/15#issuecomment-1149552402, given the quoted triple (was called "embedded triple") (in "1/"), it seems that in "2/", "convenient to navigate embedded triples" should instead be "convenient to navigate quoted triples", no?

afs commented 2 years ago

Changed - that text was taken directly from the RDF-star issue which at the time was using embedded.

HolgerKnublauch commented 2 years ago

FYI the properties sh:subject, sh:predicate and sh:object are already used by the triple rules of SHACL Advanced Features, so fresh names might be better. Maybe sh:tripleSubject or sh:subjectNode (similar to sh:node) or sh:subjectShape?

0m1n0 commented 1 year ago

Hello, I am very interested and I also read other discussions (e.g. https://github.com/w3c/rdf-star/issues/122).

I tried with DASH Reification Support for SHACL using SHACL Playground on the following two types of data: :

Validation seems to work only on URI-Encoded tiples and not on rdf:Statement. I also found the same problem on Stack Overflow: SHACL validation using dash:reifiableBy where @HolgerKnublauch answered.

If SHACL is not yet adapted to RDF-star, I would prefer to use rdf:Statement. Moreover, once the data is validated, it is easier to convert it to RDF-star via SPARQL's DELETE and INSERT clauses: Convert standard reification to RDF-star.

HolgerKnublauch commented 1 year ago

I don't believe the (old) SHACL Playground supports reification in either way. I only implemented that for TopBraid really.

HolgerKnublauch commented 9 months ago

Will be continued with #23 - it is currently unclear what specific decisions the RDF 1.2 group is taking related to reification.