
webapp.data.demo.system.event.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!
#
# Server Event Function
# Current graph is SPARQL endpoint graph
# SPARQLRestAPI getVisitor().beforeRequest(request)
#
# Agent
# /agent?action=sparql&query=select where
# getVisitor().message(request)
#
prefix fun:
prefix ff1:
prefix ff:
#@public @import
select * where { }
#
# @init function called by Parameter after Parameter graph load processing
# We can set application specific parameters
# PRAGMA: for this @init function the current graph is the Parameter graph
# whereas for other @event function it is the current graph of the query at stake
#
@public @initParam
function us:initParam() {
xt:print("@initParam");
us:initialize()
}
@public @initServer
function us:initServer(url) {
xt:print("@initServer", url);
xt:print(xt:graph())
}
# current graph is Parameter graph
@public
function us:initialize() {
xt:print(xt:turtle(xt:graph()));
let (select * where { [] cos:name ?name }) {
xt:print("start agent:", ?name)
}
}
@public @insert
function us:insert(path, atriple) {
xt:print("@insert", atriple);
}
@public @beforeRequest
function us:beforeRequest(dt:HttpServletRequest request, q) {
xt:print("@beforeRequest");
us:trace(request);
xt:print(q)
}
@public @afterRequest
function us:afterRequest(dt:HttpServletRequest request, q, amap) {
xt:print("@afterRequest");
xt:print("result:", amap);
}
@public
function us:trace(dt:HttpServletRequest request) {
for (name in fun:list(java:getHeaderNames(request))) {
xt:print("header:", name, "=", java:getHeader(request, name));
} ;
for (name in fun:list(java:getParameterNames(request))) {
xt:print("param:", name, "=", java:getParameter(request, name));
} ;
xt:print("path:", java:getContextPath(request));
xt:print("method:", java:getMethod(request));
}
@public
function us:tracemore(dt:HttpServletRequest request) {
for (name in fun:list(java:getAttributeNames(request))) {
xt:print("attribute:", name, "=", java:getAttribute(request, name));
} ;
for (name in coalesce(fun:list(java:getCookies(request)), xt:list())) {
xt:print("cookie:", name);
} ;
let (cn = java:getServletContext(request)) {
for (name in fun:list(java:getAttributeNames(cn))) {
xt:print("context:", name, "=", java:getAttribute(cn, name));
}
}
}
#
# SPARQL endpoint Agent receive a message: /agent?action=test¶m=123
# getVisitor().message(request)
#
@public @message
function us:messenger(dt:HttpServletRequest request) {
xt:print("@message");
us:processor(request)
}
#
# /agent?action=name
# call function us:name(request)
#
@public
function us:processor(request) {
let (name = java:getParameter(request, "action")) {
coalesce(funcall (concat(us:, name), request),
us:default(request))
}
}
#
# agent?action=notify
#
@public
function us:notify(request) {
#xt:print("notify:", request) ;
#us:trace(request);
let (subject = coalesce(java:getParameter(request, "subject"), "undef"),
predicate = coalesce(java:getParameter(request, "predicate"), "undef"),
object = coalesce(java:getParameter(request, "object") ,"undef")) {
xt:print("notify:", subject, predicate, object)
}
}
#
# agent?action=namedgraph&url=uri&name=uri
#
@public
function us:namedgraph(request) {
xt:print("namedgraph:", request) ;
us:trace(request);
let (url = xt:expand(java:getParameter(request, "url")),
name = coalesce(xt:expand(java:getParameter(request, "name")), url),
g = xt:load(url)) {
xt:print("load:", name, url);
java:start(g);
xt:namedgraph(name, g);
return (name)
}
}
#
# agent?action=entailment
#
@public
function us:entailment(request) {
xt:print("entailment:", request) ;
xt:entailment();
return(request)
}
#
# agent?action=parse&query=select where
#
@public
function us:parse(request) {
xt:print("parse:", request) ;
us:trace(request);
let (q = coalesce(java:getParameter(request, "query"), "select * where {?s ?p ?o} limit 10"),
ast = coalesce(xt:parse(q), "parse error")) {
xt:print("ast:", ast);
return (ast)
}
}
#
# agent?action=sparql&query=select where
#
@public
function us:sparql(request) {
xt:print("sparql:", request) ;
us:trace(request);
let (q = coalesce(java:getParameter(request, "query"), "select * where {?s ?p ?o} limit 10"),
ft = coalesce(java:getParameter(request, "format"), "xml"),
amap = xt:sparql(q),
res = funcall(us:format(ft), amap)) {
xt:print("query:", q);
#xt:print("query:", java:getQuery(amap));
#xt:print("ast:", xt:ast(java:getQuery(amap)));
xt:print(res);
return (res)
}
}
#
# agent?action=shacl
#
@public
function us:shacl(request) {
xt:print("shacl:", request) ;
us:trace(request);
let (shacl = coalesce(java:getParameter(request, "shacl"), <../../shape/shape4shape.ttl>),
rdf = coalesce(java:getParameter(request, "rdf"), <../../shape/shacl-test.ttl>),
g = xt:load(shacl),
gg = xt:load(rdf, g),
res = xt:focus(gg, sh:shacl()),
pp = xt:turtle(res)) {
xt:print(pp);
return(pp)
}
}
#
# agent?action=tordf
# draft generate RDF representation of HTTP request
#
@public
function us:tordf(request) {
xt:print("tordf:", request) ;
us:trace(request);
let (?g =
construct {
?req ?pred ?value ; ?hpred ?hvalue
}
where {
bind (uuid() as ?req)
values ?request {undef}
values ?name { unnest(fun:list(java:getParameterNames(?request))) }
bind ( uri(concat(us:, ?name)) as ?pred)
bind ( java:getParameter(?request, ?name) as ?value)
values ?hname { unnest(fun:list(java:getHeaderNames(?request))) }
bind ( uri(concat(us:, ?hname)) as ?hpred)
bind ( java:getHeader(?request, ?hname) as ?hvalue)
},
res = xt:turtle(?g)) {
xt:print(res);
return (res)
}
}
@public
function us:format(ft) {
if (ft = "xml", xt:xml,
if (ft = "json", xt:json,
if (ft = "rdf", xt:rdf,
xt:content)))
}
@public
function us:test(request) {
xt:print("test:", request) ;
# Linked Function ff:foo: run server with option -lf
# ff:foo(request)
}
@public
function us:debug(request) {
xt:print("debug:", request)
}
#
# There is no function to process request action
#
@public
function us:default(request) {
us:trace(request);
xt:print("undefined action:", request);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy