的問題
對於它的價值,它看起來並不像耶拿是這樣做的,而是(假設DBpedia資源的存在意味着您正在查詢DBpedia)DBpedia的端點。鑑於這種簡單的數據:
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ma: <http://www.w3.org/ns/ma-ont#> .
<http://dbpedia.org/resource/Japantown,_San_Francisco> rdfs:label "Japantown, San Francisco"@en .
與此查詢:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ma: <http://www.w3.org/ns/ma-ont#>
CONSTRUCT { ?subject ma:title ?label }
WHERE {
?subject rdfs:label ?label
}
耶拿的ARQ似乎保持在兩個RDF/XML和龜前綴:
$ arq --data data.n3 --query construct.sparql --results RDF/XML
<rdf:RDF
xmlns:ma="http://www.w3.org/ns/ma-ont#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<rdf:Description rdf:about="http://dbpedia.org/resource/Japantown,_San_Francisco">
<ma:title xml:lang="en">Japantown, San Francisco</ma:title>
</rdf:Description>
</rdf:RDF>
$ arq --data data.n3 --query construct.sparql
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ma: <http://www.w3.org/ns/ma-ont#> .
<http://dbpedia.org/resource/Japantown,_San_Francisco>
ma:title "Japantown, San Francisco"@en .
然而,運行一個非常類似的查詢(注意將保持我們的結果很小的VALUES)運行在DBpedia public SPARQL endpoint上,得到您提到的自動生成的名稱空間前綴。
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ma: <http://www.w3.org/ns/ma-ont#>
CONSTRUCT { ?subject ma:title ?label }
WHERE {
VALUES ?subject { <http://dbpedia.org/resource/Japantown,_San_Francisco> }
?subject rdfs:label ?label
}
SPARQL Results
@prefix ns0: <http://www.w3.org/ns/ma-ont#> .
<http://dbpedia.org/resource/Japantown,_San_Francisco> ns0:title "Japantown, San Francisco"@en .
注意,這些結果是相同RDF圖;前綴只是一個方便的方法,使一些輸出更具可讀性。任何RDF處理工具都會看到它們完全相同。 Jena沒有做錯任何事情(事實上,Jena的好處在於它保留了前綴),但是在DBpedia上運行的Virtuoso實例也不是。
保留前綴
雖然前綴隻影響人可讀性圖的系列化,圖的序列化的易讀性也很重要。即使DBpedia已經離開並在您之下進行了更改,仍然有一些方法可以保留前綴。
使用聯合查詢(SERVICE)
在命令行上使用ARQ(如上所示)與現有的數據局部地保持在理想的前綴中構造的模型。我們可以編寫一個類似的查詢,實際上可以遠程查詢DBpedia,但由於ARQ的工作是實際構建圖形,因此前綴會以您期望的方式結束。例如:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ma: <http://www.w3.org/ns/ma-ont#>
CONSTRUCT { ?subject ma:title ?label }
WHERE {
VALUES ?subject { <http://dbpedia.org/resource/Japantown,_San_Francisco> }
SERVICE <http://dbpedia.org/sparql> {
?subject rdfs:label ?label
}
}
ARQ仍然需要--data
的說法,所以我創建了一個空文件,empty-data.n3
。這裏我們需要的數據實際上來自DBpedia。
$ arq --data empty-data.n3 --query construct-remote.sparql
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ma: <http://www.w3.org/ns/ma-ont#> .
<http://dbpedia.org/resource/Japantown,_San_Francisco>
ma:title "Japantown, San Francisco"@en .
更改在耶拿模型(PrefixMapping)
由於耶拿型號前綴是PrefixMapping,可以改變所使用的前綴。以下是運行遠程查詢(不使用聯合查詢)並在之後更新前綴的Java代碼。
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.vocabulary.RDFS;
public class RemoteQueryPrefixChange {
final static String MA_NS = "http://www.w3.org/ns/ma-ont#";
final static String queryString = "" +
"PREFIX rdfs: <"+RDFS.getURI()+">\n" +
"PREFIX ma: <"+MA_NS+">\n" +
"\n" +
"CONSTRUCT { ?subject ma:title ?label }\n" +
"WHERE {\n" +
" VALUES ?subject { <http://dbpedia.org/resource/Japantown,_San_Francisco> }\n" +
" ?subject rdfs:label ?label\n" +
"}\n" +
"";
final static String DBPEDIA_SERVICE = "http://dbpedia.org/sparql";
public static void main(String[] args) {
Model results = QueryExecutionFactory.sparqlService(DBPEDIA_SERVICE, queryString).execConstruct();
System.out.println("== Original Prefixes ==");
results.write(System.out, "TTL");
System.out.println("== Updated Prefixes ==");
results.removeNsPrefix(results.getNsURIPrefix(MA_NS));
results.setNsPrefix("ma", MA_NS);
results.write(System.out, "TTL");
}
}
的輸出(請注意在更新序列模型的原始序列化ns2
和ma
):
== Original Prefixes ==
@prefix ns2: <http://www.w3.org/ns/ma-ont#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://dbpedia.org/resource/Japantown,_San_Francisco>
ns2:title "Japantown, San Francisco"@en .
== Updated Prefixes ==
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ma: <http://www.w3.org/ns/ma-ont#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://dbpedia.org/resource/Japantown,_San_Francisco>
ma:title "Japantown, San Francisco"@en .
我有點驚訝,如果這是在圖什麼將會發生,這Jena給你回來了,但是,只要'ns2'前綴用於'http:// www.w3.org/ns/ma-ont#',它不會改變結果圖的_meaning_,因爲URI是一樣的。 –