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
213 views
in Technique[技术] by (71.8m points)

ontology - How to get the movies which are based on english novels using SPARQL in DBPEDIA

Using SPARQL, I am trying the get the list of all english novels and their properties.

I would also like to find if a movie was taken based on that novel and get the movie name and its director, If a movie relationship exists.

Code:

SELECT ?movie ?director ?book ?author ?publisher ?illustrator
WHERE {
?movie  dcterms:subject  <http://dbpedia.org/resource/Category:films> ;
        dbpedia-owl:basedOn     ?book .
?movie dbp:director ?director .

?book a dbpedia-owl:Book .
?book dbp:author ?author .
?book dbp:publisher ?publisher .
?book dbp:illustrator ?illustrator .

}
limit 200
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can get a lot of correct results, if you modify your query like this...

PREFIX     dcterms: <http://purl.org/dc/terms/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX         dbp: <http://dbpedia.org/property/>

SELECT ?book ?author ?movie ?director  ?publisher ?illustrator
WHERE {
?book a dbpedia-owl:Book .
  OPTIONAL {?book dbp:author ?author .}
  OPTIONAL {?book dbp:publisher ?publisher .}
  OPTIONAL {?book dbp:illustrator ?illustrator .}
  OPTIONAL {?book ^dbpedia-owl:basedOn ?movie . ?movie a dbpedia-owl:Film }
  OPTIONAL {?movie dbp:director ?director .}
}
LIMIT 200

...but keep in mind that there are many movies that are not classified as dbpedia-owl:Film. Then of course you make a union with a few other popular classifications but that would still not guarantee there there won't be a movie based on a book, which will not be omitted.

And by the way what do you call "English novels" -- those written originally in English or those by English authors?


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

...