use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestResultSet method make2Rewindable.
private ResultSetRewindable make2Rewindable(String var, Node val) {
ResultSet rs = make2(var, val);
ResultSetRewindable rsw = ResultSetFactory.makeRewindable(rs);
return rsw;
}
use of org.apache.jena.query.ResultSet in project jena by apache.
the class TestResultSetFormat1 method resultset_04.
@Test
public void resultset_04() {
ResultSet rs = make($rs);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ResultSetFormatter.outputAsTSV(out, rs);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ResultSet rs2 = ResultSetFactory.fromTSV(in);
areIsomorphic(rs, rs2);
}
use of org.apache.jena.query.ResultSet in project opentheso by miledrousset.
the class AlignmentQuery method queryAgrovoc.
/**
* Cette fonction permet de récupérer les alignements présents sur Agrovoc
* pour un concept passé en paramètre
*
* @param idC
* @param idTheso
* @param lexicalValue
* @param lang
* @return
*/
private ArrayList<NodeAlignment> queryAgrovoc(String idC, String idTheso, String lexicalValue, String lang, String source) {
listeAlign = new ArrayList<>();
lexicalValue = String.valueOf(lexicalValue.charAt(0)).toUpperCase() + lexicalValue.substring(1);
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 + "\") )" + " OPTIONAL { " + " ?uri skos:scopeNote ?def ." + " FILTER ( (lang(?def)=\"" + lang + "\") )" + " }" + " }";
// System.out.println(sparqlQueryString1);
Query query = QueryFactory.create(sparqlQueryString1);
QueryExecution qexec = QueryExecutionFactory.sparqlService("URL A DEFINIR", 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(source);
na.setUri_target(qs.get("uri").toString());
listeAlign.add(na);
}
qexec.close();
return listeAlign;
}
use of org.apache.jena.query.ResultSet 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