4

您可以在Linked MDB SPARQL Explorer中运行以下查询。(最后一个变量)的值?imdbID包含来自三个可能域(freebase.com、rottentomatoes.com 或 imdb.com)之一的 IRI。我想知道如何应用filter只保留来自 imdb.com 域的行。

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX movie: <http://data.linkedmdb.org/resource/movie/>

SELECT ?title ?date ?director ?imdbID 
WHERE {
 ?film foaf:page ?imdbID.  
 ?film dc:title ?title.
 ?film dc:date ?date .
 ?film movie:director ?directorURI.
 ?directorURI rdfs:label ?director .
}
4

1 回答 1

4

不知道为什么@JoshuaTaylor 没有将其发布为答案,但将@JoshuaTaylor 的过滤器添加到您的查询中是您所要求的:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX movie: <http://data.linkedmdb.org/resource/movie/>

SELECT ?title ?date ?director ?imdbID 
WHERE {
 ?film foaf:page ?imdbID.  
 ?film dc:title ?title.
 ?film dc:date ?date .
 ?film movie:director ?directorURI.
 ?directorURI rdfs:label ?director .
 FILTER(regex(str(?imdbID), "www.imdb.com" ) )
}

返回:

<?xml version="1.0"?>
<sparql
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:xs="http://www.w3.org/2001/XMLSchema#"
    xmlns="http://www.w3.org/2005/sparql-results#" >
  <head>
    <variable name="title"/>
    <variable name="date"/>
    <variable name="director"/>
    <variable name="imdbID"/>
  </head>
  <results>
    <result>
      <binding name="title">
        <literal>Buffy the Vampire Slayer</literal>
      </binding>
      <binding name="date">
        <literal>1992-07-31</literal>
      </binding>
      <binding name="director">
        <literal>Fran Rubel Kuzui (Director)</literal>
      </binding>
      <binding name="imdbID">
        <uri>http://www.imdb.com/title/tt0103893</uri>
      </binding>
    </result>
    <result>
      <binding name="title">
        <literal>Batman</literal>
      </binding>
      <binding name="date">
        <literal>1989-06-23</literal>
      </binding>
      <binding name="director">
        <literal>Tim Burton (Director)</literal>
      </binding>
      <binding name="imdbID">
        <uri>http://www.imdb.com/title/tt0096895</uri>
      </binding>
    </result>
    <result>
      <binding name="title">
        <literal>Batman</literal>
      </binding>
      <binding name="date">
        <literal>1966-07-30</literal>
      </binding>
      <binding name="director">
        <literal>Leslie H. Martinson (Director)</literal>
      </binding>
      <binding name="imdbID">
        <uri>http://www.imdb.com/title/tt0060153</uri>
      </binding>
    </result>
    <result>
      <binding name="title">
        <literal>Batman &amp; Robin</literal>
      </binding>
      <binding name="date">
        <literal>1997-06-20</literal>
      </binding>
      <binding name="director">
        <literal>Joel Schumacher (Director)</literal>
      </binding>
      <binding name="imdbID">
        <uri>http://www.imdb.com/title/tt0118688</uri>
      </binding>
    </result>
    <result>
      <binding name="title">
        <literal>Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb</literal>
      </binding>

如果你想让它不区分大小写,你可以i像这样使用标志:

FILTER(regex(str(?imdbID), "www.IMDB.com", "i" )

如果您想查看有关过滤器的更多信息,请查看3.1 限制字符串的值

于 2014-07-04T19:37:45.270 回答