@prefix 在 sparql 中起什么作用?

问题描述 投票:0回答:3

我有一个问题: 在 sparql 中 @prefix 有什么作用:

@前缀:http://example.org/animals/

为什么要这样写?

sparql owl protege
3个回答
6
投票

Jeen Broekstra 的回答是正确的;

@prefix <...>
不是合法的 SPARQL 语法,只会为您产生语法错误。然而,RDF 的 Turtle 和 N3 序列化中也有类似的结构。在这些语法中,代码

@prefix animals: <http://example.org/animals/>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.

animals:Moose rdfs:subClasof animals:Animal

是具有单个三元组的图:

<http://example.org/animals/Moose> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://example.org/animals/Animal>

@prefix
行定义了前缀,可以更轻松地在图形序列化中引用 IRI。 SPARQL 也有前缀声明,但语法有点不同。在 SPARQL 查询中,行首没有
@
,行尾也没有
.
。因此,继续上面的示例,您可以使用以下查询来查询
animal:Animal
子类的所有内容:

prefix an: <http://example.org/animals/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?subclass where { 
  ?subclass rdfs:subClassOf an:Animal
}

请注意,在第一次序列化中,我们使用了

animals:
,但在 SPARQL 查询中,我们使用了具有相同前缀的
an:
。特定的前缀并不重要,只要它扩展为的实际 URI(部分)是相同的即可。严格来说,前缀是为了人类的方便;它们并不是绝对必要的。


4
投票

“@PREFIX”在 SPARQL 中不执行任何操作,除了可能生成语法错误之外。

然而,“PREFIX”(不带“@”)是用于声明命名空间前缀的 SPARQL 指令。它允许您在查询中写入

前缀名称,而不必在任何地方使用完整的 URI。因此,它是一种语法便利机制,可实现更短、更易于读取(和写入)的查询。


0
投票
The full list of built in prefixes is PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wds: <http://www.wikidata.org/entity/statement/> PREFIX wdv: <http://www.wikidata.org/value/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> PREFIX wikibase: <http://wikiba.se/ontology#> PREFIX p: <http://www.wikidata.org/prop/> PREFIX ps: <http://www.wikidata.org/prop/statement/> PREFIX pq: <http://www.wikidata.org/prop/qualifier/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX bd: <http://www.bigdata.com/rdf#> PREFIX wdref: <http://www.wikidata.org/reference/> PREFIX psv: <http://www.wikidata.org/prop/statement/value/> PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/> PREFIX pqv: <http://www.wikidata.org/prop/qualifier/value/> PREFIX pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/> PREFIX pr: <http://www.wikidata.org/prop/reference/> PREFIX prv: <http://www.wikidata.org/prop/reference/value/> PREFIX prn: <http://www.wikidata.org/prop/reference/value-normalized/> PREFIX wdno: <http://www.wikidata.org/prop/novalue/> PREFIX wdata: <http://www.wikidata.org/wiki/Special:EntityData/> PREFIX schema: <http://schema.org/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX prov: <http://www.w3.org/ns/prov#> PREFIX bds: <http://www.bigdata.com/rdf/search#> PREFIX gas: <http://www.bigdata.com/rdf/gas#> PREFIX hint: <http://www.bigdata.com/queryHints#>
    
© www.soinside.com 2019 - 2024. All rights reserved.