title: Querying DBpedia with SPARQL and Jena
body: <p>I cannot understand how can I query DBpedia using Jena. In the tutorials like <a href="http://www.ibm.com/developerworks/xml/library/j-sparql/#side2" rel="nofollow noreferrer">here</a>(Listing 4) model is initialized as follows:</p>
  
  <pre class="lang-java prettyprint-override"><code>// Open the bloggers RDF graph from the filesystem
  InputStream in = new FileInputStream(new File("bloggers.rdf"));
  
  // Create an empty in-memory model and populate it from the graph
  Model model = ModelFactory.createMemModelMaker().createModel();
  model.read(in,null); // null base URI, since model URIs are absolute
  in.close();
  </code></pre>
  
  <p>Let's say I want to write a query that will list churches in Paris. In SPARQL it will look like (taken from <a href="http://lists.w3.org/Archives/Public/public-lod/2009Oct/0040.html" rel="nofollow noreferrer">this mailing list message</a>):</p>
  
  <pre><code>PREFIX p: &lt;http://dbpedia.org/property/&gt;
  PREFIX dbpedia: &lt;http://dbpedia.org/resource/&gt;
  PREFIX category: &lt;http://dbpedia.org/resource/Category:&gt;
  PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
  PREFIX skos: &lt;http://www.w3.org/2004/02/skos/core#&gt;
  PREFIX geo: &lt;http://www.georss.org/georss/&gt;
  
  SELECT DISTINCT ?m ?n ?p ?d
  WHERE {
   ?m rdfs:label ?n.
   ?m skos:subject ?c.
   ?c skos:broader category:Churches_in_Paris.
   ?m p:abstract ?d.
   ?m geo:point ?p
   FILTER ( lang(?n) = "fr" )
   FILTER ( lang(?d) = "fr" )
   }
  </code></pre>
  
  <p>How will this query look in Java?  Particularly, I'm interested in how the model object is initialized.</p>