SPARQL中的幂(幂)和其他数学函数支持 [英] Power (exponentiation) and other math function support in SPARQL
问题描述
我正在尝试编写一个SPARQL查询,该查询要在某个对象的平方上进行过滤,但是我根本无法弄清楚如何对一个数字进行平方( x 2 )(当然,除了将其与自身相乘).我猜想一个叫math:sqrt()
的平方根函数可以工作,但似乎没有像math:pow
这样的东西存在.
I am trying to write a SPARQL query where I want to filter on the square of something, but I am simply unable to figure out how to square a number (x2) (except by multiplying it with itself, of course). I guessed a square root function called math:sqrt()
which works, yet nothing like math:pow
seems to exist.
如何在SPARQL中求某物的平方,更重要的是,在哪里可以读到它以及SPARQL中的其他数学函数(例如math:sqrt
)?
How do I get the square of something in SPARQL and, more importantly, where can I read about it and other math functions such as math:sqrt
in SPARQL?
注意:这与我以前的问题有关:反向Wikipedia地理标记查询.>
Note: This is related to my previous question: Reverse wikipedia geotagging lookup .
推荐答案
It's now a few years later and the SPARQL 1.1 Query Language has been published. It includes many more built-in functions than the original SPARQL query language. In addition to lots of functions on strings, RDF terms, &c., there are a number of numeric functions (the section numbers indicate the section in the linked standard):
- 17.4.4 Functions on Numerics
- 17.4.4.1 abs
- 17.4.4.2 round
- 17.4.4.3 ceil
- 17.4.4.4 floor
- 17.4.4.5 RAND
这里仍然没有square
功能,最快的实现方式将使用*
,因此 laalto的答案仍然站立. SPARQL支持的运算符在 17.3运算符映射和XPath中进行了描述.算术仍然只是+
,-
,*
和/
的集合.
There's still no square
function here, and the quickest way to implement that will be using *
, so laalto's answer still stands. The operators that SPARQL supports are described in 17.3 Operator Mapping, and for XPath arithmetic is still just the set of +
, -
, *
, and /
.
这篇关于SPARQL中的幂(幂)和其他数学函数支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!