gpt4 book ai didi

java - 打印日期时间而不在​​ Sparql 输出中指定数据类型

转载 作者:行者123 更新时间:2023-12-01 11:52:32 24 4
gpt4 key购买 nike

我正在耶拿使用以下 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 |

但是,我不希望在日期列中附加数据类型。我需要像这样的输出

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

我应该如何在查询中指定它?

最佳答案

您可以使用项目表达式来获取文字的字符串形式:

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

关于java - 打印日期时间而不在​​ Sparql 输出中指定数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28689016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com