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;
}
Aggregations