Advertisement
Guest User

Untitled

a guest
Sep 10th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. import com.hp.hpl.jena.query.Query;
  2. import com.hp.hpl.jena.query.QueryExecution;
  3. import com.hp.hpl.jena.query.QueryExecutionFactory;
  4. import com.hp.hpl.jena.query.QueryFactory;
  5. import com.hp.hpl.jena.query.QuerySolution;
  6. import com.hp.hpl.jena.query.ResultSet;
  7. import com.hp.hpl.jena.rdf.model.Literal;
  8. import com.hp.hpl.jena.rdf.model.Model;
  9. import com.hp.hpl.jena.rdf.model.ModelFactory;
  10.  
  11.  
  12. public class java_test {
  13.  
  14.     public static void main(String[] args) {
  15.         // TODO Auto-generated method stub
  16.  
  17.    
  18.             Model model = ModelFactory.createDefaultModel();
  19.  
  20.             String sparqlQueryString = "PREFIX mdb: <http://data.linkedmdb.org/resource/movie/>"
  21.                     + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
  22.                     +
  23.  
  24.                     "select ?label "
  25.                     +
  26.  
  27.                     "where "
  28.                     +
  29.  
  30.                     "{ ?film     mdb:director_name ?dir ."+
  31.                     "?film rdfs:label ?label . }"
  32.                    
  33.                  
  34.  
  35.                     + "LIMIT 20";
  36.            
  37.            
  38.            
  39.            
  40.             Query query = QueryFactory.create(sparqlQueryString);
  41.  
  42.             QueryExecution qexec = QueryExecutionFactory.sparqlService("http://linkedmdb.org/sparql",query);
  43.            
  44.  
  45.             ResultSet results = qexec.execSelect();
  46.        
  47.  
  48.             while (results.hasNext()) {
  49.                 QuerySolution soln = results.nextSolution();
  50.                 Literal value = soln.getLiteral("label");
  51.                 System.out.println(value);
  52.                  System.out.println( soln.getResource("label").getURI());
  53.                
  54.  
  55.             }
  56.            
  57.            
  58.         }
  59.  
  60.        
  61.        
  62.        
  63.    
  64.    
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement