1
votes

I want to extract graphs for 5 individuals who are Film(or movies) from DBPedia.

My query is:

ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
"construct{?s ?p ?o}"+ "where{?s a http://dbpedia.org/ontology/Film ."+ "?s ?p ?o"} OFFSET 0 LIMIT 5" );

I get the following result:

1- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Film .

2- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2002/07/owl#Thing .

3- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.wikidata.org/entity/Q386724 .

4- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Wikidata:Q11424 .

5- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Work .

Problem: The same film is returned 5 times as all the class: Film, Thing, Q386724,WIKIdata:Q11424, and Work are equivalent class (or Subclass relation exist).

My question:

I want to return once the triple

 <http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham>    
 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
 <http://dbpedia.org/ontology/Film> .

and filter out the other 4 triples.

How do it please?

Thank you in advance

2
You asked for ?s ?p ?o, so you'll get among the results other classes of which ?s is a member, regardless if they are equivalent or not.Ivo Velitchkov
Thank you. But How i can i return back only the triple of ?s related to Film class?bib

2 Answers

1
votes

I think you want this query

construct {?s a <http://dbpedia.org/ontology/Film> .}
where { ?s a <http://dbpedia.org/ontology/Film>. }
limit 5
5
votes

I think the following should work for you:

CONSTRUCT {?s ?p ?o}
WHERE {
  {  SELECT DISTINCT ?s
     WHERE {
        ?s a <http://dbpedia.org/ontology/Film> .
     } LIMIT 5
  }
  ?s ?p ?o .
}