
webapp.data.query.draw.rq Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of corese-server Show documentation
Show all versions of corese-server Show documentation
Corese is a Semantic Web Factory (triple store and SPARQL endpoint) implementing RDF, RDFS, SPARQL 1.1
Query and Update.
The newest version!
#
# Service as a function
#
# http://localhost:8080/srv/tutorial/funcall?uri=http://localhost:8080/data/query/draw.rq/draw¶m=("Artificial Intelligence")
#
prefix fun: <>
prefix skos:
prefix org:
prefix hsc:
prefix dc:
prefix de:
prefix d3:
@public {
function fun:draw(?text) {
xt:print('funcall draw:', ?text) ;
xt:print('context', xt:context()) ;
let (?ctx = us:createContext(),
?g = us:graph(?text)) {
us:setClass(?ctx);
us:display(?g)
}
}
function us:createContext() {
set (?context = xt:map());
xt:set(?context, st:class, xt:map());
xt:set(?context, st:group, xt:map());
return (?context)
}
function us:context() {
return (?context)
}
#
# Public function us:graph is evaluated within the (virtual) query of this program
# because it has a construct where inside
# whereas fun:draw and us:display are evaluated within calling query (funcall.rq template query)
# hence us:graph and us:display do not share the same context (it is a bug)
# this is why we need to manage a specific context
#
function us:setClass(?context) {
map (lambda((?key, ?val)) { st:setclass(?key, ?val) }, xt:get(?context, st:class)) ;
map (lambda((?key, ?val)) { st:setgroup(?key, ?val) }, xt:get(?context, st:group))
}
function us:display(?g) {
reduce(rq:concat,
maplist(st:apply-templates-with-graph,
xt:list(d3:frame, st:hturtle),
?g))
}
function fun:drawlist(?text, ?date) {
xt:print('funcall drawlist:', ?text, ?date) ;
#let (?glist = maplist(us:graph, ?text, xt:list(?date))) {
let (?glist = maplist(us:graph, ?text, ?date)) {
reduce(rq:concat, maplist(us:display, ?glist))
}
}
function us:graph(?text) {
xt:print('query draw:', ?text) ;
let (?g =
construct {
?name us:interestedIn ?topic
?x skos:altLabel ?name
}
where {
service {
select distinct ?text ?date ?topic ?name ?x where {
values (?text) { (UNDEF ) }
?sam skos:altLabel "CRISAM"
?x org:unitOf ?sam ; skos:altLabel ?name
?s hsc:structure ?x .
?s hsc:person ?p .
?p foaf:name ?n
?doc dc:creator ?s
?doc de:subject ?topic
?doc dc:issued ?dd
#filter (year(?dd) = ?date)
filter regex(?topic, ?text, "i")
}
}
bind (us:result(?topic, ?name) as ?tmp)
} )
{
xt:print("graph size:", xt:size(?g)) ;
return (?g)
}
}
function us:result(?topic, ?name) {
xt:set(xt:get(us:context(), st:class), ?topic, "main") ;
xt:set(xt:get(us:context(), st:class), ?name, "other") ;
xt:set(xt:get(us:context(), st:group), ?topic, "topic") ;
xt:set(xt:get(us:context(), st:group), ?name, "team")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy