Search in sources :

Example 11 with QuerySolution

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

the class FusekiConfig method servicesAndDatasets.

private static List<DataAccessPoint> servicesAndDatasets(Model model) {
    // Old style configuration file : server to services.
    DatasetDescriptionRegistry dsDescMap = FusekiServer.registryForBuild();
    // ---- Services
    ResultSet rs = FusekiLib.query("SELECT * { ?s fu:services [ list:member ?service ] }", model);
    List<DataAccessPoint> accessPoints = new ArrayList<>();
    if (!rs.hasNext())
        // No "fu:services ( .... )" so try looking for services directly.
        // This means Fuseki2, service configuration files (no server section) work for --conf. 
        rs = FusekiLib.query("SELECT ?service { ?service a fu:Service }", model);
    for (; rs.hasNext(); ) {
        QuerySolution soln = rs.next();
        Resource svc = soln.getResource("service");
        DataAccessPoint acc = FusekiBuilder.buildDataAccessPoint(svc, dsDescMap);
        accessPoints.add(acc);
    }
    return accessPoints;
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet) ArrayList(java.util.ArrayList)

Example 12 with QuerySolution

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

the class FusekiConfig method readSystemDatabase.

// ---- System database
/** Read the system database */
public static List<DataAccessPoint> readSystemDatabase(Dataset ds) {
    DatasetDescriptionRegistry dsDescMap = FusekiServer.registryForBuild();
    String qs = StrUtils.strjoinNL(SystemState.PREFIXES, "SELECT * {", "  GRAPH ?g {", "     ?s fu:name ?name ;", "        fu:status ?status .", "  }", "}");
    List<DataAccessPoint> refs = new ArrayList<>();
    ds.begin(ReadWrite.WRITE);
    try {
        ResultSet rs = FusekiLib.query(qs, ds);
        for (; rs.hasNext(); ) {
            QuerySolution row = rs.next();
            Resource s = row.getResource("s");
            Resource g = row.getResource("g");
            Resource rStatus = row.getResource("status");
            //String name = row.getLiteral("name").getLexicalForm() ;
            DatasetStatus status = DatasetStatus.status(rStatus);
            Model m = ds.getNamedModel(g.getURI());
            // Rebase the resource of the service description to the containing graph.
            Resource svc = m.wrapAsResource(s.asNode());
            DataAccessPoint ref = FusekiBuilder.buildDataAccessPoint(svc, dsDescMap);
            refs.add(ref);
        }
        ds.commit();
        return refs;
    } finally {
        ds.end();
    }
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet)

Example 13 with QuerySolution

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

the class FusekiBuilder method addServiceEP.

private static void addServiceEP(DataService dataService, OperationName opName, Resource svc, Property property) {
    String p = "<" + property.getURI() + ">";
    ResultSet rs = query("SELECT * { ?svc " + p + " ?ep}", svc.getModel(), "svc", svc);
    for (; rs.hasNext(); ) {
        QuerySolution soln = rs.next();
        String epName = soln.getLiteral("ep").getLexicalForm();
        Endpoint operation = new Endpoint(opName, epName);
        addServiceEP(dataService, opName, epName);
    //log.info("  " + opName.name + " = " + dataAccessPoint.getName() + "/" + epName) ;
    }
}
Also used : Endpoint(org.apache.jena.fuseki.server.Endpoint) QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet)

Example 14 with QuerySolution

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

the class TextOutput method colWidths.

private int[] colWidths(ResultSetRewindable rs) {
    int numCols = rs.getResultVars().size();
    int numRows = 0;
    int[] colWidths = new int[numCols];
    // Widths at least that of the variable name.  Assumes we will print col headings.
    for (int i = 0; i < numCols; i++) colWidths[i] = (rs.getResultVars().get(i)).length();
    // Preparation pass : find the maximum width for each column
    for (; rs.hasNext(); ) {
        numRows++;
        QuerySolution rBind = rs.nextSolution();
        int col = -1;
        for (String s1 : rs.getResultVars()) {
            col++;
            String rVar = s1;
            String s = getVarValueAsString(rBind, rVar);
            if (colWidths[col] < s.length()) {
                colWidths[col] = s.length();
            }
        }
    }
    rs.reset();
    return colWidths;
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution)

Example 15 with QuerySolution

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

the class RDFOutput method asRDF.

public Resource asRDF(Model model, ResultSet resultSet, boolean includeRowIndex) {
    Resource results = model.createResource();
    // This always goes in.
    results.addProperty(RDF.type, ResultSetGraphVocab.ResultSet);
    for (String vName : resultSet.getResultVars()) results.addProperty(ResultSetGraphVocab.resultVariable, vName);
    int count = 0;
    for (; resultSet.hasNext(); ) {
        count++;
        QuerySolution rBind = resultSet.nextSolution();
        Resource thisSolution = model.createResource();
        if (includeTypeProperties)
            thisSolution.addProperty(RDF.type, ResultSetGraphVocab.ResultSolution);
        results.addProperty(ResultSetGraphVocab.solution, thisSolution);
        if (includeRowIndex) {
            // This can lead to equivalent result sets having different graphs
            // Best used if and only if query was completely sorted. 
            Literal x = model.createTypedLiteral(count + "", XSDDatatype.XSDinteger);
            thisSolution.addLiteral(ResultSetGraphVocab.index, x);
        }
        Iterator<String> iter = getAllVars() ? rBind.varNames() : resultSet.getResultVars().iterator();
        for (; iter.hasNext(); ) {
            Resource thisBinding = model.createResource();
            String rVar = iter.next();
            RDFNode n = rBind.get(rVar);
            if (n == null)
                continue;
            //                }
            if (includeTypeProperties)
                thisBinding.addProperty(RDF.type, ResultSetGraphVocab.ResultBinding);
            thisBinding.addProperty(ResultSetGraphVocab.variable, rVar);
            thisBinding.addProperty(ResultSetGraphVocab.value, n);
            thisSolution.addProperty(ResultSetGraphVocab.binding, thisBinding);
        }
    }
    results.addProperty(ResultSetGraphVocab.size, model.createTypedLiteral(count));
    addPrefixes(model);
    return results;
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Literal(org.apache.jena.rdf.model.Literal) Resource(org.apache.jena.rdf.model.Resource) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

QuerySolution (org.apache.jena.query.QuerySolution)23 ResultSet (org.apache.jena.query.ResultSet)11 RDFNode (org.apache.jena.rdf.model.RDFNode)9 QueryExecution (org.apache.jena.query.QueryExecution)8 ArrayList (java.util.ArrayList)5 Query (org.apache.jena.query.Query)5 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)5 Model (org.apache.jena.rdf.model.Model)5 Resource (org.apache.jena.rdf.model.Resource)5 Literal (org.apache.jena.rdf.model.Literal)4 Test (org.junit.Test)4 Extractor (infoeval.main.WikiData.Extractor)3 Date (java.sql.Date)3 AbstractRegexpBasedTest (org.apache.jena.arq.AbstractRegexpBasedTest)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 SimpleDateFormat (java.text.SimpleDateFormat)2 SqlTablesFiller (infoeval.main.WikiData.SqlTablesFiller)1 TableEntry (infoeval.main.mysql.TableEntry)1 HashMap (java.util.HashMap)1