打印日期时间

问题描述:

我使用以下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

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

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