Search in sources :

Example 21 with QueryExecution

use of org.apache.jena.query.QueryExecution in project opentheso by miledrousset.

the class AlignmentQuery method queryGemet.

/**
 * Cette fonction permet de récupérer les alignements présents sur Gemet
 * pour un concept passé en paramètre
 *
 * @param idC
 * @param idTheso
 * @param lexicalValue
 * @param lang
 * @return
 */
private ArrayList<NodeAlignment> queryGemet(String idC, String idTheso, String lexicalValue, String lang) {
    listeAlign = new ArrayList<>();
    if (lexicalValue.contains(" ")) {
        lexicalValue = lexicalValue.substring(0, lexicalValue.indexOf(" "));
    }
    String sparqlQueryString1 = "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> " + "SELECT * WHERE {" + "       ?uri skos:prefLabel ?pl ." + "       FILTER(regex(?pl,\"" + lexicalValue + "*\"))" + "       FILTER ( (lang(?pl)=\"" + lang + "\") )" + "   }";
    /*
        
        PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

                SELECT * WHERE {
                 ?uri skos:prefLabel ?pl .
                      FILTER(regex(?pl,"Enseignement"))
                      FILTER ( (lang(?pl)="fr") )

                  }
        */
    // System.out.println(sparqlQueryString1);
    /*String endpointURL = "http://cr.eionet.europa.eu/sparql";
         SPARQLRepository crEndpoint = new SPARQLRepository(endpointURL);
         RepositoryConnection conn = null;
         try {
         crEndpoint.initialize();
         conn = crEndpoint.getConnection();
         TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQueryString1);
         TupleQueryResult bindings = q.evaluate();
         while (bindings.hasNext()) {
         BindingSet b = bindings.next();
         NodeAlignment na = new NodeAlignment();
         na.setInternal_id_concept(idC);
         na.setInternal_id_thesaurus(idTheso);
         na.setConcept_target(b.getBinding("pl").getValue().stringValue());
         na.setDef_target(b.getBinding("def").getValue().stringValue());
         na.setThesaurus_target("Gemet");
         na.setUri_target(b.getBinding("uri").getValue().stringValue());
         listeAlign.add(na);
         }
         } catch (Exception e) {
         e.printStackTrace();
         } finally {
         try {
         conn.close();
         } catch (RepositoryException e) {
         e.printStackTrace();
         }
         }*/
    Query query = QueryFactory.create(sparqlQueryString1);
    QueryExecution qexec = QueryExecutionFactory.sparqlService("http://cr.eionet.europa.eu/sparql", query);
    ResultSet results = qexec.execSelect();
    while (results.hasNext()) {
        QuerySolution qs = results.next();
        NodeAlignment na = new NodeAlignment();
        na.setInternal_id_concept(idC);
        na.setInternal_id_thesaurus(idTheso);
        na.setConcept_target(qs.get("pl").toString());
        na.setDef_target(qs.get("def").toString());
        na.setThesaurus_target("Gemet");
        na.setUri_target(qs.get("uri").toString());
        listeAlign.add(na);
    }
    qexec.close();
    return listeAlign;
}
Also used : NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) Query(org.apache.jena.query.Query) QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Aggregations

QueryExecution (org.apache.jena.query.QueryExecution)21 ResultSet (org.apache.jena.query.ResultSet)18 Query (org.apache.jena.query.Query)13 QuerySolution (org.apache.jena.query.QuerySolution)12 Test (org.junit.Test)7 Model (org.apache.jena.rdf.model.Model)5 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)4 Node (org.apache.jena.graph.Node)4 Dataset (org.apache.jena.query.Dataset)4 Resource (org.apache.jena.rdf.model.Resource)4 AbstractRegexpBasedTest (org.apache.jena.arq.AbstractRegexpBasedTest)3 MockSecurityEvaluator (org.apache.jena.permissions.MockSecurityEvaluator)3 SecurityEvaluator (org.apache.jena.permissions.SecurityEvaluator)3 SecuredModel (org.apache.jena.permissions.model.SecuredModel)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 Triple (org.apache.jena.graph.Triple)2 Literal (org.apache.jena.rdf.model.Literal)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1