sparql获取非特定前缀的所有主题

时间:2016-05-13 10:03:18

标签: sparql

我有一个包含许多前缀的资源的数据集。我想找到不是来自两个特定前缀的所有资源。

我执行了这个查询:

select *
where
{

 ?s ?p ?o .
  bind (strafter(str(?s), "#") as ?prefix)
  filter (?prefix != "http://www.first.com/to#")
  filter (?prefix != "http://www.second.com/rs#")
}
limit 10

那是行不通的,因为

strafter(str("http://www.first.com/to#test")给了我test而非http://www.first.com/to#

有人知道如何获得前缀吗?

1 个答案:

答案 0 :(得分:1)

select * where { ?s ?p ?o . BIND(STRBEFORE(str(?s), "#") as ?prefix) FILTER (?prefix != "http://www.first.com/to") FILTER (?prefix != "http://www.first.com/rs") } 应该有效。即:

STRSTARTS

或者您可以使用select * where { ?s ?p ?o . FILTER (!(STRSTARTS(str(?s), "http://www.first.com/to#"))) FILTER (!(STRSTARTS(str(?s), "http://www.first.com/rs#"))) }

regex
也可以使用

select * where { ?s ?p ?o . FILTER (!(regex(str(?s), "http://www.first.com/to|http://http://www.first.com/rs[#/]"))) }

{{1}}

...这将允许URI以斜杠或哈希结束,如果这是一个问题。