login about faq

I search by keywords in the field title and I get "The group does not contain triple pattern with '$film_title' object before bif:contains() predicate". Only the search by keywords in the film abstract works. What am I doing wrong?

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>

PREFIX ont: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?film_title ?film_abstract ?cinematography ?gross ?editing ?narrator
WHERE {
    ?film_title rdf:type <http://dbpedia.org/ontology/Film> .
    ?film_title rdfs:comment ?film_abstract .
    OPTIONAL {?film_title ont:cinematography ?cinematography .}
    OPTIONAL {?film_title ont:gross ?gross .}
    OPTIONAL {?film_title ont:editing ?editing .}
    OPTIONAL {?film_title ont:narrator ?narrator .}
    OPTIONAL {?film_title ont:editing ?editing .}
    FILTER(bif:contains(?film_abstract, "war")) .
    FILTER(bif:contains(?film_title, "war"))
}

asked Feb 12 at 14:38

paulrusu's gravatar image

paulrusu
212


You use ?film_title in the subject position, so it's a URI or a blank node.

The error message says triple pattern with '$film_title' object indicating it is expecting it in the object position of a triple pattern.

  1. Change ?film_title to ?file in the pattern (more meaningful name).
  2. Add?film foaf:name ?film_title to get the literal string name.

Also:

FILTER regex(str(?film_title), "war")

keeps the query within SPARQL 1.0 or

FILTER contains(?film_title, "war")

in SPARQL 1.1 which is a bit cleaner.

Overall:

WHERE {
    ?film rdf:type <http://dbpedia.org/ontology/Film> .
    ?film foaf:name ?film_title .
    FILTER contains(?film_title, "war")
}

Or if you really want to test the URI of the resource ?file:

    FILTER contains(str(?film), "war")

answered Feb 12 at 16:23

AndyS's gravatar image

AndyS
5.3k27

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×593
×120

Asked: Feb 12 at 14:38

Seen: 382 times

Last updated: Feb 12 at 16:23