2015-10-29 46 views
1

我使用Sesame服务器来存储和查询三元组集合。在我的资源库中,我有三组代表由地球上经度和纬度定义的位置。SPARQL三角函数

例子:

PREFIX ont:<http://example.org/myontology.owl#> 

<http://foo.com/location-a> a ont:Location. 
<http://foo.com/location-a> ont:hasLatitude "25.91239"^^xsd:double. 
<http://foo.com/location-a> ont:hasLongitude "30.3911"^^xsd:double. 

<http://foo.com/location-b> a ont:Location. 
<http://foo.com/location-b> ont:hasLatitude "15.7778"^^xsd:double. 
<http://foo.com/location-b> ont:hasLongitude "13.6755"^^xsd:double. 

... 

我想编写一个查询,让我回所有被它限定的圆表面上的位置的中心点(Latidude_Center,Longitude_Center)和半径(公里或度)。

为了达到这个目的,我必须使用一些暗示三角函数的数学公式。据我所知SPARQL不支持三角函数。

是否有另一种创建此功能的方法?

回答

3

您可以自己添加自定义函数到Sesame的SPARQL引擎,programmaticaly。我前一段写了a tutorial如何做到这一点。它的要点是:

  1. 为您的函数创建一个类,实现接口org.openrdf.query.algebra.evaluation.function.Function

例如:

public class SinusFunction implements Function { 

    /** return the name of the function for use in SPARQL */ 
    public String getURI() { 
      return "http://example.org/function/sin"; 
    } 

    public Value evaluate(ValueFactory valueFactory, Value... args) 
     throws ValueExprEvaluationException 
    { 
      // TODO implement computing the function return value 
      // based on the input args 
    } 
} 
  • 产生对自定义功能(一个或多个)服务提供商接口(SPI)的注册表结构的广口瓶中。
  • 这涉及一个在你的JAR文件中的META-INF/services目录中称为org.openrdf.query.algebra.evaluation.function.Function文件。该文件的内容应该是每个函数实现的完全限定名称,每行一个。

    1. 将您的jar放在某处的Sesame Server的运行时类路径中,然后重新启动。