4

我想获得所有标题中没有“指环王”字符串的电影。我在Linked Movie Database SPARQL 端点尝试了这个,但它不起作用。怎么了?

PREFIX m: <http://data.linkedmdb.org/resource/movie/>
SELECT DISTINCT *  WHERE {
   ?film dc:title ?titulo_pelicula.
   FILTER NOT EXISTS { 
      FILTER (regex(?titulo_pelicula, "The Lord of the Rings","i")) . 
   }
}
4

1 回答 1

8

首先,您应该澄清“不起作用”的含义。起初,我假设您的意思是它不会返回任何结果,但是当我在端点运行它时,我意识到您实际上收到了一条关于问题所在的相当清晰的错误消息:

Parse error: 
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX oddlinker: <http://data.linkedmdb.org/resource/oddlinker/>
PREFIX map: <file:/C:/d2r-server-0.4/mapping.n3#>
PREFIX db: <http://data.linkedmdb.org/resource/>
PREFIX dbpedia: <http://dbpedia.org/property/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
PREFIX m: <http://data.linkedmdb.org/resource/movie/>
SELECT DISTINCT *  WHERE {
   ?film dc:title ?titulo_pelicula.
   FILTER NOT EXISTS { 
      FILTER (regex(?titulo_pelicula, "The Lord of the Rings","i")) . 
   }
}

Lexical error at line 16, column 14.  Encountered: " " (32), after : "NOT"

当您到达NOT. 端点基于RDF 的原始 SPARQL 查询语言,而不是SPARQL 1.1 查询语言。原始 SPARQL 没有NOT EXISTS.

不过,这很容易解决。首先,认识到filter接受一个表达式并只保留表达式计算结果为真的那些结果。当正则表达式与标题匹配时,过滤器表达式regex(?titulo_pelicula, "The Lord of the Rings","i")返回 true,并且您正在寻找它返回 false 的情况,因此您只需使用!. (!运算符与 XPath 函数相同。映射在 SPARQL 推荐的11.3 运算符映射not部分中定义。)您需要这样的查询:

PREFIX m: <http://data.linkedmdb.org/resource/movie/>
SELECT DISTINCT *  WHERE {
   ?film dc:title ?titulo_pelicula.
   FILTER (!regex(?titulo_pelicula, "The Lord of the Rings","i")) . 
}

SPARQL 结果

于 2013-10-07T13:57:44.423 回答