w3c / N3

W3C's Notation 3 (N3) Community Group

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@if/@then/@else Keywords

AdamSobieski opened this issue · comments

With respect to the proposed language-integrated semantic templates, we could consider using a ?kb parameter and then would be able to use proposed @if/@then/@else keywords to yield one of two graphs depending on whether the provided knowledgebase contains an indicated subgraph.

@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  
{  
    @if ?kb holds
    {
        ?x rdf:type foaf:Person .
        ?y rdf:type foaf:Person .
        ?x owl:differentFrom ?y .
    }
    @then
    {  
        ?x foaf:knows ?y .  
        ?y foaf:knows ?x .  
    }
    @else { }
} .

the above example intends to express a semantic template which conditionally yields one of two graphs depending on whether a provided graph, ?kb, holds an indicated subgraph.

Any thoughts on these proposed N3 keywords? Thank you.


See also: w3c-cg/planning#27 (comment)

I believe @josd added a log:ifthenelse builtin a few days ago to eye, but I'm a bit unsure how to use it.

In general (beyond templates), I think this may fit into a lightweight "imperative programming" layer on top of N3.

@tduval-unifylogic recently brought Adenine (paper, tutorial) to my attention, which did this back in 2002 with methods, for loops, etc. It seems that methods correspond to the overall idea of templates.

Has this been inspired by the pol:when, pol:then in the Policy work here?

Yes indeed and some other cases like

For an example of how log:ifThenElseIn works, see https://github.com/eyereasoner/Notation3-By-Example/blob/main/log/ifThenElseIn.n3
Just like with log:forAllIn the object can be either the so called reasoner scope or a formula.

Re surfaces, there is now a W3C RDF Surfaces Community Group and a living document RDF Surfaces Primer