3

我是语义 Web 编程的新手,我正在尝试使用 SPARQL 查询做一些事情,但我不完全确定是否可行。但是,我想在尝试另一种方法之前先问问大师。

我有一个 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

对比

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

我对想法完全开放!谢谢!

4

2 回答 2

4

您可以为此使用 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:))
于 2013-05-11T06:30:51.623 回答
1

sparql 1.1 中有一个 substr(...) 函数,但它需要一个索引作为第二个运算符,所以我想在你的情况下它不是那么有用。 http://www.w3.org/TR/sparql11-query/#func-substr

我建议改用替换功能 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_", ""))

}

让知道这是否有效;-)

于 2013-05-11T04:30:47.803 回答