2015-10-29 50 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的運行時類路徑中,然後重新啓動。