【问题标题】:how we can create a query based on SPARQL to see the value of some data type property?我们如何创建基于 SPARQL 的查询来查看某些数据类型属性的值?
【发布时间】:2010-10-20 02:12:09
【问题描述】:

我创建了这个查询:

PREFIX VB: <http://VBnet#>
SELECT  ?x ?y
WHERE 
{
  ?x VB:HasName ?y
}     

HasName 是一种数据类型属性。当我在 Protege 中运行此查询时,系统只显示没有任何数据类型属性值的主题。 mwans ?y 为空。另外,当我在耶拿系统中运行时,只显示:(字符串)

如何查看数据类型属性的值?y的值?

【问题讨论】:

  • 您能否编辑您的问题并显示您正在查询的数据(最好采用 Turtle/NTriples 格式),因为如果不查看数据就很难判断为什么您的查询不起作用。查询本身似乎是有效的,但您的数据可能存在一些问题

标签: sparql semantic-web jena ontology protege


【解决方案1】:

这取决于您的 RDF 文档中包含的数据。如果值是类型文字,那么您可以解析 SPARQL 结果集并询问绑定到 ?y 变量的值的数据类型。如果值以不符合 RDF 的方式呈现(例如 html),则数据类型可能不会出现。否则你会看到这样的:

<sparql xmlns="http://www.w3.org/2005/sparql-results#"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.w3.org/2001/sw/DataAccess/rf1/result2.xsd">
<head>
<variable name="y"/>
</head>
<results distinct="false" ordered="true">
 <result>
   <binding name="y"><literal xml:lang="en">John</literal></binding> //literals with language
 </result>
 <result>
   <binding name="y"><literal datatype="http://www.w3.org/2001/XMLSchema#integer">30</literal></binding> //typed literals
 </result>
...

要提取您需要查询 Jena API 的数据类型。

【讨论】:

    【解决方案2】:

    假设没有语言标签:

    SELECT  ?x ?y (DATATYPE(?y) AS ?dt)
    

    请注意,如果 ?y 是纯文字,则 DATATYPE 返回 xsd:string 但 ?y 没有 ^^ 数据类型(直到 RDF 1.1)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      相关资源
      最近更新 更多