Semantic Web


Mise en oeuvre (2)

Code source:

import org.apache.jena.rdf.model.*;
import org.apache.jena.util.*;
import org.apache.jena.query.*;
import java.io.*;

public class Skills {
  public static void main(String[] args) {
    // 1 //
    Model model = ModelFactory.createDefaultModel();
    model.read( "skills.ttl" );
    // 2 //
    String str = "prefix : <http://skills/> \n"+
      "select ?n where { ?x :skills :"+args[0]+" . ?x :name ?n . }\n";
    Query query = QueryFactory.create( str );
    // 3 //
    QueryExecution result = QueryExecutionFactory.create(query,model);
    ResultSet iterator = result.execSelect();
    while (iterator.hasNext()) {
      QuerySolution solution = iterator.nextSolution();
      System.out.println( solution.get("?n") );
    }
  }
}

3 - 8