Search in sources :

Example 76 with ResultSet

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;
}
Also used : BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable)

Example 77 with ResultSet

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 78 with ResultSet

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

Example 79 with ResultSet

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

ResultSet (org.apache.jena.query.ResultSet)79 Test (org.junit.Test)43 BuilderResultSet (org.apache.jena.sparql.sse.builders.BuilderResultSet)33 BaseTest (org.apache.jena.atlas.junit.BaseTest)27 QueryExecution (org.apache.jena.query.QueryExecution)18 QuerySolution (org.apache.jena.query.QuerySolution)15 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Query (org.apache.jena.query.Query)11 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)8 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)8 ArrayList (java.util.ArrayList)7 Node (org.apache.jena.graph.Node)7 Model (org.apache.jena.rdf.model.Model)6 ConfigTest (org.apache.jena.tdb.ConfigTest)6 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 Var (org.apache.jena.sparql.core.Var)5 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4