w3c / N3

W3C's Notation 3 (N3) Community Group
47 stars 18 forks source link

@requires Keyword #112

Open AdamSobieski opened 1 year ago

AdamSobieski commented 1 year ago

With respect to language-integrated semantic templates, we could consider using a named graph parameter, ?kb, and using something like a proposed @requires keyword to guard the input arguments. Proposed here is an N3 language keyword, @requires, for describing guards on input arguments.

@prefix list:  <http://www.w3.org/2000/10/swap/list#> .  
@prefix log:   <http://www.w3.org/2000/10/swap/log#> .  
@prefix ex:    <http://example.org/#> .  
@prefix graph: <http://www.w3.org/2000/10/swap/graph#> .  
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . 
@prefix owl:   <http://www.w3.org/2002/07/owl#> . 

ex:ng??(?kb ?x ?y) :graph  
{  
    @requires ?kb holds
    {
        ?x rdf:type foaf:Person .
        ?y rdf:type foaf:Person .
        ?x owl:differentFrom ?y .
    } .  
    ?x foaf:knows ?y .  
    ?y foaf:knows ?x .  
} .  

As envisioned, if the @requires subgraph is not contained in the knowledgebase, ?kb, the semantic template returns an empty graph.

There could also be a corresponding @requires ?kb not holds { ... } syntax.

Any thoughts on this proposed N3 keyword? Thank you.


See also: https://github.com/w3c-cg/planning/discussions/27#discussioncomment-4388356

william-vw commented 1 year ago

This could be implemented (currently unsure) using a combination of log:semantics (to retrieve the KB), log:conclusion or log:inferences (to get its deductive closure / inferences), and log:includes to check whether they adhere to the given constraints. See here for more on these builtins.