Query a linked movie database (LMDB) using SPARQL

Given this RDF graph:

:Matrix [rdfs:label] :The Matrix . :Matrix [movie:id] :23 . :Matrix [movie:actor] :Keanu Reaves . :Matrix [movie:actor] :Laurence Fishburne . :Die Hard 3 [rdfs:label] :Die Hard 3 . :Die Hard 3 [movie:id] :42 . :Die Hard 3 [movie:actor] :Bruce Willis . :Die Hard 3 [movie:actor] :Samuel L. Jackson . 

and a query like this:

 SELECT ?id ?name ?actor WHERE { ?instance movie:id ?id . ?instance rdfs:label ?name . ?instance movie:actor ?actor . } 

I would expect a result like:

 id | name | actor 23 | The Matrix | Laurence Fishburne 23 | The Matrix | Keanu Reaves 42 | Die Hard 3 | Bruce Willis 42 | Die Hard 3 | Samuel L. Jackson 

but instead I get:

 id | name | actor 23 | The Matrix | Laurence Fishburne 42 | Die Hard 3 | Bruce Willis 

What is the reason for this?

By the way, when I use this query:

 SELECT * WHERE { ?instance movie:id ?id . ?instance rdfs:label "The Matrix" . ?instance movie:actor ?actor . } 

Result (as expected):

 id | name | actor 23 | The Matrix | Laurence Fishburne 23 | The Matrix | Keanu Reaves 
+3
source share
1 answer

Using Jena ARQ, I was able to use the following query to get the data that you think is interested in the Linked Base DataBase SPARQL endpoint:

 PREFIX dcterms: <http://purl.org/dc/terms/> PREFIX movie: <http://data.linkedmdb.org/resource/movie/> SELECT ?id ?filmTitle ?actorName WHERE { VALUES ?filmTitle { "The Matrix" } SERVICE <http://data.linkedmdb.org/sparql> { ?film a movie:film ; movie:filmid ?id ; dcterms:title ?filmTitle ; movie:actor [ a movie:actor ; movie:actor_name ?actorName ]. } } 

data.n3 is an empty file, since arq requires the --data argument, even if the SERVICE keyword means that we are requesting remote data.

 $ arq --query query.sparql --data data.n3 ----------------------------------------------------------------------------------------- | id | filmTitle | actorName | ========================================================================================= | "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Keanu Reeves" | | "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Laurence Fishburne" | | "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Hugo Weaving" | | "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Joe Pantoliano" | | "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Gloria Foster" | | "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Carrie-Anne Moss" | ----------------------------------------------------------------------------------------- 

Removing the line VALUES ?filmTitle ... expands the search to all the films and their actors, of course.

The properties used in your request are different from the real properties used in LMDB, which makes it difficult to understand what different options might be. It could be rdfs:label instead of dcterms:title , or lines with or without language tags, etc.

+3
source

Source: https://habr.com/ru/post/1200183/


All Articles