2013-06-20 29 views
0
http://www.example.com/teach.rdfs/John http://www.example.com/teach.rdfs#position "Full Professor"   

http://www.example.com/teach.rdfs/John http://www.example.com/teach.rdfs#course"Math" 

http://www.example.com/teach.rdfs/John http://www.example.com/teach.rdfs#student"Undergraduate" 

http://www.example.com/teach.rdfs/Arthur http://www.example.com/teach.rdfs#position "Assistant Professor" 

http://www.example.com/teach.rdfs/Arthur http://www.example.com/teach.rdfs#course"Web Engineering" 

http://www.example.com/teach.rdfs/Arthur http://www.example.com/teach.rdfs#student"Graduate" 

提取從一個RDF三元謂語比較對象(名稱),如果這些是三元和我想找到助理教授誰教研究生如何使用SPARQL

Lecturer  Position 

Arthur   Assistant Professor 

它是如何可能使用SPARQL提取上述日期

回答

4

您的數據不在我所知道的任何合法的RDF序列化中,但它很容易進入N3序列化。在同一文檔中將http://.../teach.rdfs#http://.../teach.rdfs/用作前綴是相當罕見的。看到一個或另一個是很常見的,但不是兩者都有。這不是非法的,所以我們可以使用它。在N3格式,這裏就是你的數據文件,data.n3

@prefix teach1: <http://www.example.com/teach.rdfs/> . 
@prefix teach2: <http://www.example.com/teach.rdfs#> . 

teach1:John teach2:position "Full Professor" . 
teach1:John teach2:course "Math" . 
teach1:John teach2:student "Undergraduate" . 
teach1:Arthur teach2:position "Assistant Professor" . 
teach1:Arthur teach2:course "Web Engineering" . 
teach1:Arthur teach2:student "Graduate" . 

查詢是非常簡單了。這是因爲,作爲一個文件名爲query.sparql

PREFIX teach1: <http://www.example.com/teach.rdfs/> 
PREFIX teach2: <http://www.example.com/teach.rdfs#> 

SELECT ?lecturer ?position WHERE { 
    VALUES ?position { "Assistant Professor" } 
    ?lecturer teach2:position ?position ; 
      teach2:student "Graduate" . 
} 

這是一個有點不尋常關於這個查詢的唯一的事情就是使用VALUES ?position { "Assistant Professor" }。我使用VALUES表單的原因是,您希望的結果包括輸出中的"Assistant Professor"。如果我們排除VALUES ...部分,我們可以重寫的圖案

?lecturer teach2:position "Assistant Professor" ; 
      teach2:student "Graduate" . 

,並從中找到相同?lecturer S,但沒有必然"Assistant Professor"變量。通過數據和查詢,我們可以使用Jena的ARQ命令行工具對數據運行查詢:

$ arq --query query.sparql --data data.n3 
----------------------------------------- 
| lecturer  | position    | 
========================================= 
| teach1:Arthur | "Assistant Professor" | 
-----------------------------------------