2015-02-24 192 views
0

我使用以下SPARQL查詢在耶拿打印一些信息:獲得打印日期時間

String qr = "PREFIX : <http://www.example.com/tempsensor#>\n" + 
       "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n"+ 
       "SELECT \n"+ 
       "?Place ?Temperature ?Date \n"+ 
       "WHERE\n"+ 
       "{ ?ind :locatedIn ?Place .\n " + 
        "?ind :measures ?Temperature .\n " + 
        "?ind :onDate ?Date .\n " + 
       "FILTER(regex(str(?Place),'Delhi', 'i'))\n"+ 
       "FILTER (datatype(?Date) = xsd:dateTime)\n"+ 
       "}"; 

輸出是:

-------------------------------------------------------------- 
| Place | Temperature | Date        | 
============================================================== 
| :Delhi | 16   | "2014-10-02T03:20:10"^^xsd:dateTime | 

不過,我不希望數據類型附加在Date列中。我需要輸出像

-------------------------------------------------------------- 
| Place | Temperature | Date        | 
============================================================== 
| :Delhi | 16   | 2014-10-02T03:20:10     | 

如何推薦我在查詢中指定此?

+0

[SPARQL查詢?我怎麼會只有一個文字或字符串作爲結果]的可能重複(HTTP ://stackoverflow.com/questions/15724868/sparql-query-how-i-get-only-a-literal-or-string-as-result) – 2015-02-24 11:54:37

回答

1

您可以使用項目表情只得到文字的字符串形式:

String qr = "PREFIX : <http://www.example.com/tempsensor#>\n" + 
      "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n"+ 
      "SELECT \n"+ 
      "?Place ?Temperature (STR(?Date) AS ?StrDate) \n"+ 
      "WHERE\n"+ 
      "{ ?ind :locatedIn ?Place .\n " + 
      " ?ind :measures ?Temperature .\n " + 
      " ?ind :onDate ?Date .\n " + 
      " FILTER(regex(str(?Place),'Delhi', 'i'))\n"+ 
      " FILTER (datatype(?Date) = xsd:dateTime)\n"+ 
      "}"; 

這裏我們使用內置STR()功能的?Date值轉換爲只是它的字符串形式沒有數據類型。

SPARQL定義了廣泛的內置功能,這是非常值得你的時間讀了 - http://www.w3.org/TR/sparql11-query/#expressions