假设模型包含三元组形式的数据。
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ns1: <http://example.org/vocab#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://example.org/library> a ns1:Library ;
ns1:contains <http://example.org/library/the-republic> .
<http://example.org/library/the-republic> a ns1:Book ;
ns1:contains <http://example.org/library/the-republic#introduction> ;
dc:creator "Plato" ;
dc:title "The Republic" .
<http://example.org/library/the-republic#introduction> a ns1:Chapter ;
dc:description "An introductory chapter on The Republic." ;
dc:title "The Introduction" .
所以我想从这个模型中创建一个新模型。
此类查询:
<http://example.org/library> ns1:contains ?data.
以上查询会给我
?data = <http://example.org/library/the-republic>
但我希望新模型中的每个三元组都是(来自)此结果URL的子项?data =&lt; http://example.org/library/the-republic&gt;包括此结果三元组也在模型
中<http://example.org/library> ns1:contains <http://example.org/library/the-republic> .
所以新模型将是:
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ns1: <http://example.org/vocab#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://example.org/library> ns1:contains <http://example.org/library/the-republic> .
<http://example.org/library/the-republic> a ns1:Book ;
ns1:contains <http://example.org/library/the-republic#introduction> ;
dc:creator "Plato" ;
dc:title "The Republic" .
<http://example.org/library/the-republic#introduction> a ns1:Chapter ;
dc:description "An introductory chapter on The Republic." ;
dc:title "The Introduction" .
为了增加更多的清晰度,我们再举一个例子 查询是:
<http://example.org/library/the-republic> dc:creator ?data.
这里的结果是?data =“Plato”。而“柏拉图”不是IRI或空白节点。
所以新模型将是:
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ns1: <http://example.org/vocab#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://example.org/library/the-republic> dc:creator "Plato" .
除了递归之外,有没有其他有效方法可以做到这一点? 我正在创建新模型以避免循环,因为数据不是非循环的。