webapp.data.query.function.rq Maven / Gradle / Ivy
The newest version!
#
# Functions shared by server STTL transformations
# javascript:trans() defined in webapp/js/server.js
#
@export package {
function st:isAjax(){
st:get(st:protocol, st:ajax)
}
function st:protocol(?uri) {
if (st:isAjax()) {
concat("javascript:trans(\"", str(?uri), "\")")
}
else { str(?uri) }
}
# take st:include (("mode" st:mode)) into account
# to generate hyperlink
# &mode= st:get(st:mode)
function st:link(?uri) {
concat(
st:get(st:service),
"?uri=", encode_for_uri(?uri),
if (coalesce(isURI(st:get(st:profile)), false),
concat("&profile=", st:qname(st:get(st:profile))),
if (coalesce(isURI(st:get(st:transform)), false),
concat("&transform=", st:qname(st:get(st:transform))),
"") ),
st:include()
)
}
function st:link123(?uri) {
concat(
st:get(st:service),
"?uri=", encode_for_uri(?uri),
coalesce(
concat("&profile=", st:qname(st:get(st:profile))),
concat("&transform=", st:qname(st:get(st:transform))),
""),
st:include()
)
}
# take st:include (("mode" st:mode)) into account
# to generate hyperlink
# &mode= st:get(st:mode)
function st:link(?uri, ?profile) {
concat(st:get(st:service),
"?uri=", encode_for_uri(?uri),
"&profile=", st:qname(?profile)
,st:include()
)
}
function st:plink(?uri) {
st:protocol(st:link(?uri))
}
function st:plink(?uri, ?profile) {
st:protocol(st:link(?uri, ?profile))
}
function st:qname(?uri){
kg:qname(?uri)
}
#
# st:param [ st:include (("mode" st:mode)) ]
# "&mode=" st:get(st:mode)
#
function st:include(){
coalesce(
reduce(rq:concat, maplist(
lambda((?name, ?val)) {
coalesce(let (?value = st:get(?val)) {
concat("&", ?name, "=",
if (isURI(?value), st:qname(?value), ?value))
}, "")
},
st:get(st:include))),
"")
}
function st:include2(){
coalesce(
loop ((?name, ?val) in coalesce(st:get(st:include), xt:list())) {
coalesce(
let (?value = st:get(?val)) {
concat("&", ?name, "=",
if (isURI(?value), st:qname(?value), ?value))
},"")
},
"")
}
#
# try to get specific profile for uri from profile.ttl
# st:lodprofile (( st:dbpedia ))
# otherwise use st:profile
#
function st:pplink(?uri) {
st:plink(?uri, coalesce(st:getprofile(?uri), st:get(st:profile)))
}
# ?arg = st:mode
function st:include(?arg){
coalesce(
let (?m = st:get(?arg)) { bound(?m) } &&
mapany (rq:equal, ?arg, st:get(st:include)),
false)
}
# search list st:lodprofile ((namespace profile))
function st:getprofile(?uri){
let ((?ns, ?prof) = mapfind(st:match, ?uri, st:get(st:lodprofile)))
{ ?prof }
}
# ?decl = (namespace profile)
function st:match(?x, ?decl){
let (?ns = xt:get(?decl, 0)){
strstarts(?x, ?ns) || coalesce(?ns = "*", false)
}
}
# ____________________________________________________
#
# Generate a HTML table
# call user defined us:cell() to generate cells
#
function st:table(?table){
st:format(
"\n%s
\n",
apply(rq:concat, maplist(st:row, xt:iota(xt:size(?table)), ?table)))
}
function st:row(?n, ?row){
st:format("%s %s \n",
?n,
mapfun(rq:concat, st:cell, ?row))
}
function st:cell(?elem){
st:format(
"%s \n",
?elem)
}
#
# Generate a list of sublist with ?nc elements in each sublist
# Use case: generate a HTML table.
#
function st:split(?l, ?n){
xt:split(?l, ?n)
}
function xt:split(?list, ?nc){
let (?size = xt:size(?list),
?nr = xt:div(?size, ?nc),
?table = xt:list(),
?jlist = xt:iota(0, ?nc - 1),
?max = if (xt:mod(?size, ?nc) = 0, ?nr - 1, ?nr)){
for (?i in xt:iota(0, ?max)){
let (?row = xt:list(), ?nb = ?i * ?nc){
for (?j in ?jlist){
let (?k = ?nb + ?j){
if (?k < ?size){
xt:add(xt:get(?list, ?k), ?row)
}
}
} ;
xt:add(?row, ?table)
}
} ;
?table
}
}
# ____________________________________________________
function st:getFormat(?dir, ?name) {
uri(concat(st:get(st:server), "/data/format/", ?dir, "/", ?name))
}
function st:server(?name){
st:call-template-with(st:server, ?name)
}
function st:head(){
if (st:isAjax(), "",
st:server(st:dohead))
}
function st:tail(){
if (st:isAjax(), "",
st:server(st:dotail))
}
function st:bstyle(){
if (st:isAjax(),
st:server(st:bstyle), "")
}
function st:sstyle(){
st:server(st:sstyle)
}
function st:submit(){
if (st:isAjax()){ st:server(st:submit) }
else { "" }
}
function st:change(){
st:server(st:change)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy