我是语义web编程的新手,我正在尝试用SPARQL查询做一些事情,我不完全确定是否可能。然而,我想在尝试另一种方法之前,我应该问一下大师。
我有一个SPARQL查询,它返回一个URI资源作为其中一列。在下面的例子:
http://purl.uniprot.org/uniprot/Q9UKM9
我想采取该URL (Q9UKM9
)的最后一部分,并将其放入一个变量中,在regex命令中使用,以在另一个资源中找到相同的蛋白质(由我提取的数字识别)。
我不能直接做这样的查询:
?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
和
http://purl.org/obo/owl/InterPro#InterPro_IPR000504
我是完全开放的想法!谢谢!
您可以使用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:))
在sparql 1.1中有一个substr(…)函数,但它需要一个索引作为第二个操作符,所以我想它在您的情况下不是很有用。http://www.w3.org/TR/sparql11-query/func-substr
我建议使用replace函数http://www.w3.org/TR/sparql11-query/func-replace
像这样: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_", ""))
}
让我们知道这是否有效;-)