Search in sources :

Example 26 with QuerySolution

use of org.apache.jena.query.QuerySolution in project autoindex by dice-group.

the class AutoIndexTest method testgetallclasses.

public void testgetallclasses() {
    seh.setLang("en");
    seh.setBaseUri(endpoint);
    ResultSet results = seh.getallclasses();
    assertNotNull(results);
    List<QuerySolution> asText = ResultSetFormatter.toList(results);
    Joiner listOfResults = Joiner.on("\n");
    System.out.println("Classes Results" + listOfResults.join(asText));
    System.out.println("Total Visible Results = " + asText.size());
    Assert.assertTrue(asText.size() > 1);
}
Also used : Joiner(org.apache.jena.ext.com.google.common.base.Joiner) QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet)

Example 27 with QuerySolution

use of org.apache.jena.query.QuerySolution in project jena by apache.

the class TestAPI method testInitialBindings3.

@Test
public void testInitialBindings3() {
    QuerySolutionMap init = new QuerySolutionMap();
    init.add("z", m.createLiteral("zzz"));
    String qs = "SELECT * {?s ?p 'x1'}";
    try (QueryExecution qExec = QueryExecution.model(m).query(qs).initialBinding(init).build()) {
        ResultSet rs = qExec.execSelect();
        QuerySolution qSoln = rs.nextSolution();
        assertTrue("Initial setting not set correctly now", qSoln.getLiteral("z").getLexicalForm().equals("zzz"));
    }
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution) QuerySolutionMap(org.apache.jena.query.QuerySolutionMap) Test(org.junit.Test)

Example 28 with QuerySolution

use of org.apache.jena.query.QuerySolution in project jena by apache.

the class TestSecurityFilterLocal method subjects.

private Set<Node> subjects(DatasetGraph dsg, String queryString, SecurityContext sCxt) {
    final DatasetGraph dsg1 = applyFilterDSG ? DataAccessCtl.filteredDataset(dsg, sCxt) : dsg;
    Dataset ds = DatasetFactory.wrap(dsg1);
    return Txn.calculateRead(ds, () -> {
        try (QueryExecution qExec = QueryExecutionFactory.create(queryString, ds)) {
            // }
            if (applyFilterTDB)
                sCxt.filterTDB(dsg1, qExec);
            List<QuerySolution> results = Iter.toList(qExec.execSelect());
            Stream<Node> stream = results.stream().map(qs -> qs.get("s")).filter(Objects::nonNull).map(RDFNode::asNode);
            return SetUtils.toSet(stream);
        }
    });
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Dataset(org.apache.jena.query.Dataset) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) QueryExecution(org.apache.jena.query.QueryExecution) RDFNode(org.apache.jena.rdf.model.RDFNode) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 29 with QuerySolution

use of org.apache.jena.query.QuerySolution in project jena by apache.

the class TestSecurityFilterLocal method graphs.

private Set<Node> graphs(DatasetGraph dsg, SecurityContext sCxt) {
    // Either applyFilterDSG or applyFilterTDB
    final DatasetGraph dsg1 = applyFilterDSG ? DataAccessCtl.filteredDataset(dsg, sCxt) : dsg;
    Dataset ds = DatasetFactory.wrap(dsg1);
    return Txn.calculateRead(ds, () -> {
        try (QueryExecution qExec = QueryExecutionFactory.create(queryGraphNames, ds)) {
            if (applyFilterTDB)
                sCxt.filterTDB(dsg1, qExec);
            List<QuerySolution> results = Iter.toList(qExec.execSelect());
            Stream<Node> stream = results.stream().map(qs -> qs.get("g")).filter(Objects::nonNull).map(RDFNode::asNode);
            return SetUtils.toSet(stream);
        }
    });
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Dataset(org.apache.jena.query.Dataset) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) QueryExecution(org.apache.jena.query.QueryExecution) RDFNode(org.apache.jena.rdf.model.RDFNode) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 30 with QuerySolution

use of org.apache.jena.query.QuerySolution in project jena by apache.

the class TestSecurityFilterLocal method subjects.

private Set<Node> subjects(DatasetGraph dsg, Function<DatasetGraph, Graph> graphChoice, String queryString, SecurityContext sCxt) {
    final DatasetGraph dsg1 = applyFilterDSG ? DataAccessCtl.filteredDataset(dsg, sCxt) : dsg;
    Graph graph = graphChoice.apply(dsg1);
    if (graph == null)
        // Can't see the graph.
        return Collections.emptySet();
    Model model = ModelFactory.createModelForGraph(graph);
    return Txn.calculateRead(testdsg, () -> {
        try (QueryExecution qExec = QueryExecutionFactory.create(queryString, model)) {
            if (applyFilterTDB)
                sCxt.filterTDB(dsg1, qExec);
            List<QuerySolution> results = Iter.toList(qExec.execSelect());
            Stream<Node> stream = results.stream().map(qs -> qs.get("s")).filter(Objects::nonNull).map(RDFNode::asNode);
            return SetUtils.toSet(stream);
        }
    });
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) QuerySolution(org.apache.jena.query.QuerySolution) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) QueryExecution(org.apache.jena.query.QueryExecution) RDFNode(org.apache.jena.rdf.model.RDFNode) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

QuerySolution (org.apache.jena.query.QuerySolution)129 ResultSet (org.apache.jena.query.ResultSet)106 QueryExecution (org.apache.jena.query.QueryExecution)99 Test (org.junit.Test)71 ArrayList (java.util.ArrayList)70 Query (org.apache.jena.query.Query)47 Dataset (org.apache.jena.query.Dataset)44 Resource (org.apache.jena.rdf.model.Resource)43 Literal (org.apache.jena.rdf.model.Literal)22 RDFNode (org.apache.jena.rdf.model.RDFNode)21 Model (org.apache.jena.rdf.model.Model)15 HashMap (java.util.HashMap)7 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)6 Extractor (infoeval.main.WikiData.Extractor)4 IOException (java.io.IOException)4 Node (org.apache.jena.graph.Node)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 Date (java.sql.Date)3 SimpleDateFormat (java.text.SimpleDateFormat)3 LinkedList (java.util.LinkedList)3