Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

rdf - LinkedMDB SPARQL Query

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...