
query.method.rq Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of corese-gui Show documentation
Show all versions of corese-gui Show documentation
Corese is a Semantic Web Factory (triple store and SPARQL endpoint)
implementing RDF, RDFS, SPARQL 1.1 Query and Update, Shacl. STTL. LDScript.
The newest version!
#
# Method definition and method call
#
@test
select *
(method(us:area, ?x) as ?a)
(method(us:perimeter, ?x) as ?p)
where {
?x a ?t
filter strstarts(?t, us:)
}
@type dt:literal
function us:area(?x) {
xt:display("area: ", ?x) ;
return (0)
}
function us:area(?x) {
xt:display("area: ", ?x) ;
return (0)
}
function us:perimeter(?x) {
xt:display("perimeter: ", ?x) ;
return (0)
}
@type us:Composite
function us:area(?x) {
method(us:compose, ?x, us:area)
}
@type us:Composite
function us:perimeter(?x) {
method(us:compose, ?x, us:perimeter)
}
@type us:Composite
function us:compose(?x, ?fun) {
let (select * (sum(method(?fun, ?e)) as ?sum)
where { ?x us:member/rdf:rest*/rdf:first ?e }) {
?sum
}
}
@type us:Rectangle
function us:area(?x) {
method(us:compose, ?x, lambda(?w, ?l) { ?w * ?l })
}
@type us:Rectangle
function us:perimeter(?x) {
method(us:compose, ?x, lambda(?w, ?l) { 2 * (?w + ?l) })
}
@type us:Rectangle
function us:compose(?x, ?fun) {
let (select * where { ?x us:width ?w ; us:length ?l }) {
funcall(?fun, ?w, ?l)
}
}
@type us:Square
function us:area(?x) {
method(us:compose, ?x, us:size, lambda(?s) { ?s * ?s })
}
@type us:Square
function us:perimeter(?x) {
method(us:compose, ?x, us:size, lambda(?s) { 4 * ?s })
}
@type us:Circle
function us:area(?x) {
method(us:compose, ?x, us:radius, lambda(?r) { 3.1416 * ?r * ?r })
}
@type us:Circle
function us:perimeter(?x) {
method(us:compose, ?x, us:radius, lambda(?r) { 2 * 3.1416 * ?r})
}
@type us:Figure
function us:compose(?x, ?p, ?fun) {
let (select * where { ?x ?p ?s }) {
funcall(?fun, ?s)
}
}
function us:graph() {
let (?g = construct {
us:square a us:Square ; us:size 5 .
us:rect a us:Rectangle ; us:width 3 ; us:length 4 .
us:circ a us:Circle ; us:radius 3 .
us:comp1 a us:Composite ; us:member (us:square us:rect us:circ) .
us:comp2 a us:Composite ; us:member (us:comp1) .
us:Rectangle rdfs:subClassOf us:Figure .
us:SquareCircle rdfs:subClassOf us:Figure .
us:Square rdfs:subClassOf us:SquareCircle .
us:Circle rdfs:subClassOf us:SquareCircle .
} where {} ) {
?g
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy