All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.spin.rul Maven / Gradle / Ivy

Go to download

Corese is a Semantic Web Factory (triple store and SPARQL endpoint) implementing RDF, RDFS, SPARQL 1.1 Query and Update.

There is a newer version: 4.6.1
Show newest version





 .

template sp:named {
   st:kw( "from named")
   " " ?f st:nl() 
   
   ; separator = ""
}
where {
  ?in sp:fromNamed ?l
  ?l rdf:rest*/rdf:first ?f
}



]]>





 .

template sp:values {
  ?b
}
where {
  ?in sp:values ?b
}



]]>





 .

template st:main {
  ?in
  if (?t in (sp:Select, sp:Construct, sp:Ask, sp:Describe), "", ";")
  ; separator = "\n\n"
}
where {
  ?in a ?t 
  
  values ?t {
    sp:Select sp:Construct sp:Ask sp:Describe
    sp:SPARQLUpdate 
    sp:InsertData sp:DeleteData sp:Modify sp:DeleteWhere
    sp:Load sp:Drop sp:Clear sp:Create sp:Copy sp:Move sp:Add
   }
    
  filter( not exists { { ?a sp:query ?in } union { ?a rdf:first ?in } } )
}



]]>





 .

template st:start {

   st:call-template(st:main)

}
where {
}



]]>





 .

template sp:listnl {
  ?exp  
}
where {
  ?in rdf:rest*/rdf:first ?exp
}




]]>





 .

template sp:list {
  if(?b, "\n  ", "")
  ?exp  ; separator = " "
}
where {
  ?in rdf:rest*/rdf:first ?exp
  bind ( exists { ?exp sp:expression ?e } as ?b )
}




]]>





 .

template sp:arg {
  ?arg ; separator = ", " 
}
where {
  ?in ?p ?arg
    filter(strstarts(?p, sp:arg) || ?p = sp:expression)
}
# order by ?p
order by xsd:integer(substr(?p, 1 + strlen(sp:arg)))




]]>











 .

template sp:using {
   "using " ?f "\n" ; separator = ""
}
where {
  ?in sp:using/rdf:rest*/rdf:first ?f
}



]]>





 .

template sp:argin {
  ?arg ; separator = ", " 
}
where {
  ?in ?p ?arg
    filter(strstarts(?p, sp:arg) && ?p != sp:arg1)
}
# order by ?p
order by xsd:integer(substr(?p, 1 + strlen(sp:arg)))




]]>





", st:apply-templates(?in), ""),
	      concat("", 
		st:apply-templates(?in), ""))
    }
    
    function st:protect2(?in) {
      let (?t = st:turtle(?in)){
	if (strstarts(?t, "<"), 
	    replace(?t, "<", "<"),
	    ?t)
      }
    }
    
    function st:protect(?in) {
	xt:protect(st:turtle(?in))
    }
    
    function xt:protect(?s) {
        replace(replace(?s, "&", "&"), "<", "<")
    }
    
    function xt:pprotect(?s) {
        if (st:get(st:mode, st:html), xt:protect(?s), ?s)
    }
    
    function st:kw(?x) {
       if (st:get(st:mode, st:html), st:htmlkw(?x), st:stdkw(?x))
    }
    
    function st:htmlkw(?x) {
       concat("", str(?x), "")
    }

    function st:stdkw(?x) {
       str(?x)
    }	
    
    function st:namespace() {
      let (?p = st:prolog()){
	if (st:get(st:mode, st:html), 
	  replace(?p, "<", "<"), 
	  ?p)
      }
    }
]]>





 .

template sp:construct {
    "{" 
    box { 
      st:call-template(sp:listnl, ?temp) 
    }
    "}" 
}
where {
  ?in a sp:Construct ; 
     sp:templates ?temp 
}



]]>





 .

template sp:usingNamed {
   "using named " ?f "\n" ; separator = ""
}
where {
  ?in sp:usingNamed/rdf:rest*/rdf:first ?f
}



]]>





 .

template st:html {

  st:call-template-with(st:server, st:head)
  st:call-template(st:next)

  "

SPARQL

" st:call-template(st:button) st:call-template(st:sparql) st:call-template(st:button) st:call-template-with(st:server, st:tail) } where { filter (st:set(st:html, true)) } ]]>
. template sp:from { st:kw("from") " " ?f st:nl() ; separator = "" } where { ?in sp:from/rdf:rest*/rdf:first ?f } ]]> . template st:mode(?m) { st:call-template(st:main) } where { bind (st:set(st:mode, ?m) as ?mode) } ]]> . template { st:kw( "order by") " " st:call-template(sp:list, ?in) st:nl() } where { ?q sp:orderBy ?in } ]]> . template { "(" ?f " " xt:pprotect(?lab) " " ?r ")" } where { ?in a ?ope ; sp:arg1 ?f ; sp:arg2 ?r } values (?ope ?lab) { (sp:lt "<") (sp:gt ">") (sp:le "<=") (sp:ge ">=") (sp:eq "=") (sp:ne "!=") (sp:add "+") (sp:mul "*") (sp:divide "/") (sp:sub "-") (sp:and "&&") (sp:or "||") } ]]> . template{ "?" xsd:string(?var) } where { ?in sp:varName ?var filter(not exists { ?in sp:expression ?e }) } ]]> . template{ "(" ?e " as (" group { ?var ; separator = ", " } "))" } where { ?in sp:varList/rdf:rest*/rdf:first ?var ; sp:expression ?e } ]]> . template { st:kw("bind") " (" ?e " " st:kw("as") " " ?v ")" } where { ?in a sp:Bind ; sp:expression ?e ; sp:variable ?v } ]]> . template { st:kw( "values") " (" st:call-template(sp:list, ?var) ") {" box { ?list } "}" } where { ?in a sp:Values ; sp:variables ?var ; sp:values ?list } ]]> . template { "(" st:call-template(sp:list, ?val) ")" } where { ?x sp:values ?in ?in rdf:rest*/rdf:first ?val } ]]> . template { ?p1 "/" ?p2 } where { ?in a sp:SeqPath ; sp:path1 ?p1 ; sp:path2 ?p2 } ]]> . template { "" } where { ?q sp:where ?in filter(?in = rdf:nil) } ]]> . template { ?exp } where { ?x rdf:first ?in ?x rdf:rest ?r . ?r rdf:first [ a ?t ] filter(?t in (sp:Optional, sp:Minus)) ?in rdf:rest*/rdf:first ?exp } #default list is behind all other list templates pragma {st:template st:priority 1000} ]]> . template { "()" } where { ?x ?p ?in filter(?in = rdf:nil && ?p != rdf:rest) } #default list is behind all other list templates pragma {st:template st:priority 1000} ]]> . template { "! (" ?f ")" } where { ?in a sp:not ; sp:arg1 ?f } ]]> . template { "{" group { ?exp ; separator = "\n" } "}" } where { ?in rdf:rest*/rdf:first ?exp } # default list is behind all other list templates # after listoption pragma {st:template st:priority 1001} ]]> . template { st:namespace() st:kw("describe") " " st:call-template(sp:list, ?list) } where { ?in a sp:Describe ; sp:resultNodes ?list minus { ?in sp:where ?w } } ]]> . template { st:kw( "service") " " if (bound(?b), concat(st:kw( "silent"), " "), "") ?g ibox { st:nl() ?b } } where { ?in a sp:Service ; sp:serviceURI ?g ; sp:elements ?b optional { ?in sp:silent ?b } } ]]> . template { "{" ?q "}" } where { ?in a sp:SubQuery ; sp:query ?q } ]]> . template { ?e " " st:kw( str(?l)) " (" st:call-template(sp:argin, ?in) ")" } where { ?in a ?t ; sp:arg1 ?e } values (?t ?l) { (sp:in "in") (sp:IN "in") (sp:notIn "not in") } ]]> . template { st:kw( "minus") " {" box { st:call-template(sp:listnl, ?e) } "}" } where { ?in a sp:Minus ; sp:elements ?e } ]]> . template { st:kw( "having") " (" st:call-template(sp:list, ?in) ")\n" } where { ?q sp:having ?in } ]]> . template{ "(" ?e " as ?" xsd:string(?var) ")" } where { ?in sp:varName ?var ; sp:expression ?e } ]]> . template { st:kw("exists") " {" st:call-template(sp:listnl, ?b) "}" } where { ?in a sp:Exists ; sp:elements ?b } ]]> . template { st:kw( "optional") " {" box { st:call-template(sp:listnl, ?b) } "}" } where { ?in a sp:Optional ; sp:elements ?b } ]]> . template { st:kw( "group by") " " st:call-template(sp:list, ?in) st:nl() } where { ?q sp:groupBy ?in } ]]> . template { ?x " " ?p " " if (bound(?v), concat(":: ", ?v, " "), "") ?y " ." } where { ?in a sp:TriplePath ; sp:subject ?x ; sp:path ?p ; sp:object ?y optional { ?in sp:pathVariable ?v } } ]]> . template { ?e1 st:nl() st:kw( "union") st:nl() ?e2 } where { ?in a sp:Union ; sp:elements ?l ?l rdf:first ?e1 ; rdf:rest/rdf:first ?e2 } ]]> . template { ?in } where { ?q sp:where ?in filter(?in != rdf:nil) } ]]> . template { if (strstarts(?ope, sp:), strafter(?ope, sp:), ?ope) "(" if (bound(?d), "distinct ", "") st:call-template(sp:arg, ?in) if (! bound(?f) && ?ope in (sp:Count, sp:count, sp:COUNT), "*", "") if (bound(?s), concat(" ; separator = ", st:turtle(?s)), "") ")" } where { ?in a ?ope # ?ope matches any type, hence restrict this template to # SPIN blank nodes # otherwise c:John a foaf:Person would match this template filter(isBlank(?in)) { ?in sp:arg1 ?f } union { ?in sp:expression ?f } union # function with no arg: { filter not exists { ?in ?p ?v filter(?p not in (sp:distinct, rdf:type )) }} optional { ?in sp:distinct ?d } optional { ?in sp:separator ?s } filter( ?ope not in ( sp:undef, sp:lt, sp:gt, sp:le, sp:ge, sp:eq, sp:ne, sp:add, sp:mul, sp:divide, sp:sub, sp:in, sp:IN, sp:notIn, sp:Bind, sp:not, sp:and, sp:or) ) } ]]> . template { st:namespace() st:kw("ask") " {" box { st:call-template(sp:listnl, ?a) } "}" } where { ?in a sp:Ask ; sp:where ?a } ]]> . template { st:prolog() st:kw("construct") " " st:call-template(sp:construct, ?in) st:nl() st:kw("where") " {" box { st:call-template(sp:listnl, ?where) } "}" st:nl() ?group ?order if (bound(?l), concat(st:kw("limit"), " ", ?l, st:nl()), "") if (bound(?o), concat(st:kw("offset"), " ", ?o, st:nl()), "") ?having st:call-template(sp:values, ?in) } where { ?in a sp:Construct ; sp:where ?where optional { ?in sp:groupBy ?group } optional { ?in sp:orderBy ?order } optional { ?in sp:having ?having } optional { ?in sp:limit ?l } optional { ?in sp:offset ?o } } ]]> . template { st:kw("filter") " (" ?exp ")" } where { ?in a sp:Filter ; sp:expression ?exp } ]]> . template { "undef" } where { ?in a sp:Undef } ]]> . template { "(" ?p1 "|" ?p2 ")" } where { ?in a sp:AltPath ; sp:path1 ?p1 ; sp:path2 ?p2 } ]]> . template { ?x " " ?p " " ?y " ." } where { ?in sp:subject ?x ; sp:predicate ?p ; sp:object ?y } ]]> . template { st:kw( "desc") "(" st:call-template(sp:list, ?e) ")" } where { ?in a sp:Desc ; sp:expression ?e } ]]> . template { st:kw( "graph") " " ?g " {" box { if (?b = rdf:nil, "", st:call-template(sp:listnl, ?b)) } "}" } where { ?in a sp:NamedGraph ; sp:graphNameNode ?g ; sp:elements ?b } ]]> . template { "(" ?p ")" if (bound(?min) && ?min = 1, "+", if (bound(?max) && ?max = -1, "?", "*")) } where { ?in a sp:ModPath ; sp:subPath ?p optional { ?in sp:modMin ?min } optional { ?in sp:modMax ?max } } ]]> . template { st:prolog() st:kw("describe") " " st:call-template(sp:list, ?list) st:nl() "where {" box { st:call-template(sp:listnl, ?w) } "}" } where { ?in a sp:Describe ; sp:resultNodes ?list ; sp:where ?w } ]]> . template { xsd:string(?l) "(" ?p ")" } where { ?in a ?t ; sp:subPath ?p } values (?t ?l) { (sp:ReversePath "^") (sp:NegPath "!") } ]]> . template { if (! (exists {?x ?p ?in}), st:namespace(), "") st:kw("select") " " if (bound(?t), st:kw("distinct "), "") if (bound(?r), "reduced ", "") if (bound(?select), st:call-template(sp:list, ?select), "*") st:nl() st:call-template(sp:from, ?in) st:call-template(sp:named, ?in) st:kw("where") " {" box { st:call-template(sp:listnl, ?where) } "}" st:nl() ?group ?order ?having if (bound(?l), concat(st:kw("limit"), " ", ?l, st:nl()), "") if (bound(?o), concat(st:kw("offset"), " ", ?o, st:nl()), "") st:call-template(sp:values, ?in) } where { ?in a sp:Select ?in sp:where ?where optional { ?in sp:resultVariables ?select } optional { ?in sp:distinct ?t filter(?t = true) } optional { ?in sp:reduced ?r filter(?r = true) } optional { ?in sp:groupBy ?group } optional { ?in sp:orderBy ?order } optional { ?in sp:having ?having } optional { ?in sp:limit ?l } optional { ?in sp:offset ?o } } ]]> . template { ?u ; separator = ";\n" } where { ?in a sp:SPARQLUpdate ; sp:updates/rdf:rest*/rdf:first ?u } ]]> . template { st:prolog() "load " if (bound(?s), " silent ", "") ?d if (bound(?g), concat( " into graph ", ?g), "") } where { ?in a sp:Load ; sp:document ?d optional { ?in sp:into ?g } optional { ?in sp:silent ?s } } ]]> . template { st:prolog() if (bound(?g), concat("with ", ?g, "\n"), "") if (bound(?d), concat("delete {", st:call-template(sp:listnl, ?d), "} \n"), "") if (bound(?i), concat("insert {", st:call-template(sp:listnl, ?i), "} \n"), "") st:call-template(sp:using, ?in) st:call-template(sp:usingNamed, ?in) "where {" st:call-template(sp:listnl, ?w) "}" } where { ?in a sp:Modify ; sp:where ?w optional { ?in sp:graphIRI ?g } optional { ?in sp:deletePattern ?d } optional { ?in sp:insertPattern ?i } } ]]> . template { st:prolog() str(?l) " " if (bound(?s), "silent ", "") if (bound(?a), "all", "") if (bound(?d), "default", "") if (bound(?n), "named", "") if (bound(?g), concat("graph ", ?g), "") } where { ?in a ?t values (?t ?l) { (sp:Clear "clear") (sp:Drop "drop") } optional { ?in sp:graphIRI ?g } optional { ?in sp:silent ?s } optional { ?in sp:default ?d } optional { ?in sp:all ?a } optional { ?in sp:named ?n } } ]]> . template { st:prolog() str(?l) " " if (bound(?s), "silent ", "") if (?f = sp:default, "default", concat("graph ", ?f)) " to " if (?t = sp:default, "default", ?t) } where { ?in a ?tt values (?tt ?l) { (sp:Move "move") (sp:Add "add") (sp:Copy "copy") } ?in sp:from ?f ?in sp:to ?t optional { ?in sp:silent ?s } } ]]> . template { st:prolog() "insert data {" if (?d = rdf:nil, "", st:call-template(sp:listnl, ?d) ) "}" } where { ?in a sp:InsertData ; sp:data ?d } ]]> . template { st:prolog() "create " if (bound(?s), "silent ", "") if (bound(?d), "default", "") if (bound(?g), concat("graph ", ?g), "") } where { ?in a sp:Create optional { ?in sp:silent ?s } optional { ?in sp:default ?d } optional { ?in sp:graphIRI ?g } } ]]> . template { st:prolog() "delete data {" st:call-template(sp:listnl, ?d) "}" } where { ?in a sp:DeleteData ; sp:data ?d } ]]> . template { st:prolog() if (bound(?g), concat("with ", ?g, "\n"), "") "delete where {" st:call-template(sp:listnl, ?w) "}" } where { ?in a sp:DeleteWhere ; sp:where ?w optional { ?in sp:with ?g } } ]]>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy