How to get the arithmetic result of a comment in TopBraid Composer?

61 views Asked by At

In TopBraid Composer, I save all my SPARQL queries as Comments in separate instances. I want to calculate their value and I want that value in a separate instance. For example, my SPARQL queries is 2 * 3 and when I run it, the result is 6. Here my comment contain "2 * 3".

What I want is the result "6" to be displayed in a separate instance. I will use the value of that instance in some other calculation, say "6 (of this) * 4" = 24. Please let me know if there is any way to deal with it.

It will save us from writing and arranging so many inner queries. All we would need is write simple queries and connect them through this method and the final query will get us the result. Thank you so much.

1

There are 1 answers

1
scotthenninger On

SPARQL is pretty good about casting to basic XML schema types, so you can simply cast these to xs:integer - as an example:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xs: <http://www.w3.org/2001/XMLSchema#>
SELECT ?product
WHERE {
   <x> rdfs:comment ?c1 .
   <y> rdfs:comment ?c2 .
   BIND (xs:integer(?c1) * xs:integer(?c2) AS ?product)
}