2013-05-11 46 views
3

我是新來的語義網絡編程,我試圖做一些SPARQL查詢,我不完全確定是可能的。然而,我想在嘗試另一種方法之前,我會問問大師。如何將SPARQL查詢結果的URI分成多個部分?

我有一個SPARQL查詢返回一個URI資源作爲列之一。下面的例子:

http://purl.uniprot.org/uniprot/Q9UKM9 

我想採取URL(Q9UKM9)的最後部分,並把它變成一個變量正則表達式命令用來發現相同的蛋白質(由數字,我確定提取)在另一個資源中。

我不能只是做像直查詢:

?random_resource_one X:propertyOne ?what_I_am_interested_in . 
?random_resource_two Y:hasURI ?what_I_am_interested_in . 

,因爲資源的URI不同:

http://purl.uniprot.org/interpro/IPR000504 

VS

http://purl.org/obo/owl/InterPro#InterPro_IPR000504 

我對完全開放想法!謝謝!

回答

1

在sparql 1.1中有一個substr(...)函數,但它需要一個索引作爲第二個操作符,所以我想它在你的情況下並沒有那麼有用。 http://www.w3.org/TR/sparql11-query/#func-substr

我建議,而不是使用的東西,如替換功能 http://www.w3.org/TR/sparql11-query/#func-replace

: 代替( 「http://xxpurl.uniprot.org/interpro/IPR000504」, 「http://xxpurl.uniprot.org/interpro/」, 「」) 爲了獲得唯一的ID,然後對其進行測試的東西或多或少像這樣(只給你一個想法):

SELECT DISTINCT * 
WHERE { 

    ?uri_1 a ?type_1 . 
    ?uri_2 a ?type_2 . 

    FILTER (replace(str(?uri_1),"http://xxpurl.uniprot.org/interpro/", "") = replace(str(?uri_2),"http://xxpurl.org/obo/owl/InterPro#InterPro_", "")) 

} 

我們知道,如果作品;-)

3

您可以使用SPARQL的STRAFTER功能如下:

STRAFTER("http:xx//purl.uniprot.org/uniprot/Q9UKM9", "http:xx//purl.uniprot.org/uniprot/") 

將返回 「Q9UKM9」。

作爲進一步提示,您可以重用名稱空間前綴作爲簡寫。因此,假設您在查詢中有這樣的:

PREFIX uniprot: <http:xx//purl.uniprot.org/uniprot/> 

,你可以這樣做:

STRAFTER("http:xx//purl.uniprot.org/uniprot/Q9UKM9", str(uniprot:)) 
相關問題