我在Jena中使用以下sparql Query来打印一些信息:
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 Column中附加数据类型。我需要像
这样的输出--------------------------------------------------------------
| Place | Temperature | Date |
==============================================================
| :Delhi | 16 | 2014-10-02T03:20:10 |
我如何在查询中指定此内容?
答案 0 :(得分: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