简体   繁体   中英

How to get gross from Dbpedia with SPARQL

I tried to get the gross from dbpedia with sparql query but I couldn't. My code is

library(SPARQL)
endpoint <- 'http://live.dbpedia.org/sparql'
options <- NULL
prefix <- c("db","http://dbpedia.org/resource/")

sparql_prefix <- "PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
"

q <- paste(sparql_prefix,
           'SELECT ?actor ?movie  ?gross
           WHERE {
           ?m dc:subject <http://dbpedia.org/resource/Category:American_films> .
           ?m rdfs:label ?movie .
           FILTER(LANG(?movie) = "en")

           ?m dbo:gross ?a .
           ?a rdfs:label ?gross .
            FILTER(DATATYPE(?gross) = xsd:double)

           ?m dbp:starring ?a .
           ?a rdfs:label ?actor .
           FILTER(LANG(?actor) = "en")

           }')

results <- SPARQL(endpoint,q,ns=prefix,extra=options)$results

but returned a blank data.frame

Do you have any idea how to get the gross ??

  1. The value of dbo:gross is not a node, it doesn't make sense to use rdfs:label on it. Instead, it's directly a value.
  2. The type of dbo:gross is not xsd:double , it's usually <http://dbpedia.org/datatype/usDollar> , but some movies use another currency.

So, the fixed query could look something like:

SELECT ?actor ?movie  ?gross 
WHERE {
  ?m dc:subject <http://dbpedia.org/resource/Category:American_films> .
  ?m rdfs:label ?movie .
  FILTER(LANG(?movie) = "en")

  ?m dbo:gross ?gross .

  ?m dbp:starring ?a .
  ?a rdfs:label ?actor .
  FILTER(LANG(?actor) = "en")
}

Keep in mind that this query will only list movies that have both a dbo:gross and at least one dbp:starring . If that's not what you want, consider using OPTIONAL .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM