1

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. Jul 7, 2016 at 15:51
  • Thank you. But How i can i return back only the triple of ?s related to Film class?
    – bib
    Jul 7, 2016 at 16:05

2 Answers 2

5

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 .
}
0
1

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
  • Thank you. This query will return 5 differents Film. Which is very good but i need the other triplet of each individual, like name, duration etc.
    – bib
    Jul 7, 2016 at 16:16
  • @user2869180 with name Jul 7, 2016 at 17:18
  • @user2869180 with name, writer, producer Jul 7, 2016 at 17:20
  • 1
    @WilliamKinaan those are SELECT queries, not CONSTRUCT. You need a sub-SELECT in a CONSTRUCT query, see the answer of scotthenninger below Jul 8, 2016 at 2:45
  • While this query may or may not be what OP wants, note that for CONSTRUCT queries with sufficiently simply WHERE parts, you can just do CONSTRUCT WHERE. That is, this query is simply construct where { ?s a dbo:Film } limit 5 Jul 8, 2016 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.