[英]optimizing a SPARQL query when using a custom function in Jena
I have the following SPARQL query on a Owl Ontology, using Jena:我使用 Jena 在 Owl Ontology 上有以下 SPARQL 查询:
SELECT ?label ?distance
WHERE {
?wpt rdf:type inav:Waypoint .
?wpt inav:Label ?label .
?ac rdf:type inav:Aircraft .
?ac inav:Label "myAircraft" .
?wpt inav:hasExactGeometry ?geom .
?geom inav:asWKT ?wkt .
?ac inav:hasExactGeometry ?geom2 .
?geom2 inav:asWKT ?wkt2 .
BIND (geof:distance(?wkt, ?wkt2, <http://www.opengis.net/def/uom/OGC/1.0/nauticalMile>) as ?distance)
}
ORDER BY ASC(?distance )
LIMIT 1
The idea is that:这个想法是:
Aircraft
called "myAircraft"Aircraft
Waypoint
using GeoSPARQLWaypoint
Waypoint
, and it's distance to the "myAircraft" Aircraft
Waypoint
的 label ,它与“myAircraft” Aircraft
的距离This query works without any problem.这个查询没有任何问题。
Now I am adding a custom vocabulary using Jena FunctionFactory
.现在我正在使用 Jena
FunctionFactory
添加自定义词汇表。 In my case I want to retrieve in real time the visibility of the meteo in meters at the position of the waypoint (to take an example).在我的情况下,我想在航路点的 position 处以米为单位实时检索气象的能见度(举个例子)。 In order to do that, I created a custom vocabulary with one
visibility
word.为了做到这一点,我创建了一个包含一个
visibility
单词的自定义词汇表。 It has only one argument which is the Label
of the Waypoint
in my case.它只有一个参数,在我的例子中是
Waypoint
的Label
。
I then changed my query as following:然后我将查询更改如下:
SELECT ?label ?distance ?visibility
WHERE {
?wpt rdf:type inav:Waypoint .
?wpt inav:Label ?label .
?ac rdf:type inav:Aircraft .
?ac inav:Label "myAircraft" .
?wpt inav:hasExactGeometry ?geom .
?geom inav:asWKT ?wkt .
?ac inav:hasExactGeometry ?geom2 .
?geom2 inav:asWKT ?wkt2 .
BIND (geof:distance(?wkt, ?wkt2, <http://www.opengis.net/def/uom/OGC/1.0/nauticalMile>) as ?distance)
BIND (my:visibility(?wpt) as ?visibility)
}
ORDER BY ASC(?distance )
LIMIT 1
It also works without any problem, but I remarked in my Debugger that the Java visibility
function is called for every Waypoint
in the Ontology, not only the closest one.它也可以毫无问题地工作,但我在我的调试器中指出,Java
visibility
function 会为本体中的每个Waypoint
调用,而不仅仅是最近的一个。 If I have a lot of waypoints, I will have to call my Java function for Waypoint
, when ideally I would like to do that for only one of them, the closest one.如果我有很多航点,我将不得不为航点调用我的 Java
Waypoint
,理想情况下我只想为其中一个,最接近的一个。
Is there a way to do that to speed-up this query?有没有办法加速这个查询? (the idea is that in real-life I would call a meteo service for my Waypoint, but I do not want to do that for every
Waypoint
, but only the one I found in my query). (想法是,在现实生活中,我会为我的 Waypoint 调用一个气象服务,但我不想为每个
Waypoint
都这样做,而只是我在查询中找到的那个)。
Per the very informative answer of UninformedUser:根据 UninformedUser 的非常翔实的回答:
SELECT ?label ?distance ?visibility
{
{SELECT ?label ?distance
WHERE {
?wpt rdf:type inav:Waypoint .
?wpt inav:Label ?label .
?ac rdf:type inav:Aircraft .
?ac inav:Label "myAircraft" .
?wpt inav:hasExactGeometry ?geom .
?geom inav:asWKT ?wkt .
?ac inav:hasExactGeometry ?geom2 .
?geom2 inav:asWKT ?wkt2 .
BIND (geof:distance(?wkt, ?wkt2, <http://www.opengis.net/def/uom/OGC/1.0/nauticalMile>) as ?distance)
} ORDER BY ASC(?distance ) LIMIT 1
} BIND (my:visibility(?wpt) as ?visibility)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.