0

概述

我正在使用ARQ来查询本地RDF文件。该查询应用于5 个文件,它们是:

  • a_m.nt、description.nt、labels.nt、links.nt、literals.nt

信息被建模为一组三元组:

  • 宾语

算法

首先,我想从a_m.nt文件中选择特定主题。其次,我想从description.ntlabels.nt中选择所选主题的标签和描述。以另一种方式,搜索description.ntlabels.nt以查找与从a_m.nt中提取的主题具有相同主题的描述和标签。最后,我想从links.ntliterals.nt中提取其余属性。


询问

PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select ?x ?y ?p ?o
where { 
?topic rdf:type music. 
?topic rdf:description ?x.
?topic rdf:label ?y. 
?topic ?p ?o. 
}

命令行

sparql --data a_m.nt --data description.nt --data label.nt --data links.nt --data literals.nt --query query_sparql

问题

通过使用此查询,我首先选择一个具有该类型的主题,music然后选择它的描述、标签和其他属性。那是对的吗?

4

1 回答 1

2

在您当前的查询中,您似乎不需要 where 子句中的所有这些绑定,因为您无论如何都使用 last statement 检索所有内容?topic ?p ?o。您需要music正确命名变量并可能添加DISTINCT到 select 子句。所以也许像这样重写查询:

PREFIX : <http://example.org/>
select DISTINCT ?topic ?p ?o
where { 
  ?topic a :music. 
  ?topic ?p ?o. 
}

一个可能的结果可能是:

<foo> <type> <music>
<foo> <description> "this is foo"
<foo> <label> "foo"
<bar> <type> <music>
<bar> <label> "bar"

这与您的查询不同,更一般。你基本上得到了所有类型的东西music以及与之相关的所有属性和值。在您的查询中,您只会得到具有一些描述和标签(并且是 type music)的结果,以及与之关联的所有属性和值:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <http://example.org/>
select ?x ?y ?p ?o
where { 
  ?topic rdf:type :music. 
  ?topic rdf:description ?x.
  ?topic rdf:label ?y. 
  ?topic ?p ?o. 
}

将其视为具有?x ?y ?p ?o列标题的表格。一个可能的结果可能是:

"this is foo" "foo" <type> <music>
"this is foo" "foo" <description> "this is foo"
"this is foo" "foo" <label> "foo"

等等

您的查询将取决于您的数据的组织方式。我的问题是,是否有任何其他属性,description.nt并且labels.nt您想在结果中避免?如果是这样,那么您可能希望将该数据加载到命名图表中,并在查询中仅从该图表中提取描述和标签。任意示例:

SELECT ?a ?b
FROM <A>
FROM NAMED <B>
WHERE
{
  ?x a <foo> .
  GRAPH <B> { ?x ?a ?b }
}
于 2015-05-19T10:03:57.133 回答