LinkedMDB SPARQL Query

安稳与你 提交于 2019-11-30 06:02:38

问题


I'm a bit confused here. I have the following SPARQL query that works brilliantly against the LinkedMDB explorer.

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

 SELECT ?label?resource WHERE {
    ?resource mdb:id ?uri .
    ?resource dc:title ?label . 
    FILTER regex(?label,'^Batman')
}

This one filters out all the Batman movies like this (I've filtered out all the results and is only showing five here):

-----------------------------------------------|
| Label                           | Resource   |
|----------------------------------------------|
| Batman                          | db:film/2  |
| Batman                          | db:film/3  |
| Batman & Robin                  | db:film/4  |
| Batman: Mask of the Phantasm    | db:film/737|
| Batman: Mystery of the Batwoman | db:film/974|
-----------------------------------------------|

But, here comes the question. If I write "Forrest Gump" instead of "Batman", the query can't find any result.

However, if I change the last line to

    ?resource dc:title "Forrest Gump". 

it finds the movie in the LinkedMDB database, so I know its hiding there somewhere. But it's not returned when I use the FILTER regex solution.

I've noticed that if I only search without filter and just print all the movies in the database, it looks like LinkedMDB have some sort of LIMIT on 2557 so that the webpage won't crash. And it looks like the FILTER only filters those 2557 movies. Is there a way to retrieve more movies?


回答1:


SPARQL 1.1 introduces more string functions, such as contains, strstarts, and strends which are much more specialized and could be much faster than using a full blown regular expression. However, it doesn't look like the LinkedMDB explorer supports SPARQL 1.1 yet, so those aren't useful here.

If you know the exact name of the movie, it will be much more efficient to simply ask for it instead of using regular expressions. E.g.,

SELECT ?resource WHERE {
    ?resource movie:filmid ?uri .
    ?resource dc:title "Forrest Gump" .
}

SPARQL Results

returns the film db:film/38179.



来源:https://stackoverflow.com/questions/18783869/linkedmdb-sparql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!