Search in sources :

Example 76 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class QueryTest method runTestAsk.

void runTestAsk(Query query, QueryExecution qe) throws Exception {
    boolean result = qe.execAsk();
    if (results != null) {
        if (results.isBoolean()) {
            boolean b = results.getBooleanResult();
            assertEquals("ASK test results do not match", b, result);
        } else {
            Model resultsAsModel = results.getModel();
            StmtIterator sIter = results.getModel().listStatements(null, RDF.type, ResultSetGraphVocab.ResultSet);
            if (!sIter.hasNext())
                throw new QueryTestException("Can't find the ASK result");
            Statement s = sIter.nextStatement();
            if (sIter.hasNext())
                throw new QueryTestException("Too many result sets in ASK result");
            Resource r = s.getSubject();
            Property p = resultsAsModel.createProperty(ResultSetGraphVocab.getURI() + "boolean");
            boolean x = r.getRequiredProperty(p).getBoolean();
            if (x != result)
                assertEquals("ASK test results do not match", x, result);
        }
    }
    return;
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 77 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestItem method _getName.

private String _getName() {
    Statement s = testResource.getProperty(TestManifest.name);
    String ln = s.getSubject().getLocalName();
    if (s == null)
        return ln + " <<unset>>";
    return "(" + ln + ") " + s.getString();
}
Also used : Statement(org.apache.jena.rdf.model.Statement)

Example 78 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestItem method _getNamedGraphsURIs.

/**
     * Get the named graphs : maybe unknown if part for the query (FROM NAMED)
     * 
     * @return List
     */
private List<String> _getNamedGraphsURIs() {
    if (!_getAction().isAnon())
        // Action is a URI - data had better be in the query itself.
        return null;
    List<String> l = new ArrayList<>();
    ClosableIterator<Statement> cIter = _getAction().listProperties(VocabTestQuery.graphData);
    for (; cIter.hasNext(); ) {
        Statement obj = cIter.next();
        String df = obj.getResource().getURI();
        l.add(df);
    }
    cIter.close();
    return l;
}
Also used : Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList)

Example 79 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestItem method _getDefaultGraphURIs.

// ----------------------------------------------------
// ---- Query specific properties
/**
     * Get the data file (default graph): maybe unknown if part for the query
     * (FROM)
     * 
     * @return List
     */
private List<String> _getDefaultGraphURIs() {
    if (!_getAction().isAnon())
        // Action is a URI - data had better be in the query itself.
        return null;
    List<String> l = new ArrayList<>();
    ClosableIterator<Statement> cIter = _getAction().listProperties(VocabTestQuery.data);
    for (; cIter.hasNext(); ) {
        Statement stmt = cIter.next();
        String df = stmt.getResource().getURI();
        l.add(df);
    }
    cIter.close();
    return l;
}
Also used : Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList)

Example 80 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class UpdateTest method getDataset.

static Dataset getDataset(Resource r) {
    //DataSource ds = DatasetFactory.create() ;
    DatasetGraph dsg = DatasetGraphFactory.create();
    // Growing. dataset.
    Dataset ds = DatasetFactory.wrap(dsg);
    List<String> dftData = getAll(r, TestManifestUpdate_11.data);
    for (String x : dftData) FileManager.get().readModel(ds.getDefaultModel(), x);
    ClosableIterator<Statement> cIter = r.listProperties(TestManifestUpdate_11.graphData);
    for (; cIter.hasNext(); ) {
        // An graphData entry can be a URI or a [ ut ... ; rdfs:label "foo" ] ;
        Statement stmt = cIter.next();
        Resource gn = stmt.getResource();
        if (gn.isAnon()) {
            if (!gn.hasProperty(TestManifestUpdate_11.graph))
                System.err.println("No data for graphData");
            String fn = gn.getProperty(TestManifestUpdate_11.graph).getResource().getURI();
            String name = gn.getProperty(RDFS.label).getString();
            Model m = FileManager.get().loadModel(fn);
            ds.addNamedModel(name, m);
        } else {
            String x = gn.getURI();
            Model m = FileManager.get().loadModel(x);
            ds.addNamedModel(x, m);
        }
    }
    cIter.close();
    return ds;
}
Also used : Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) Model(org.apache.jena.rdf.model.Model) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)141 Model (org.apache.jena.rdf.model.Model)56 Resource (org.apache.jena.rdf.model.Resource)46 StmtIterator (org.apache.jena.rdf.model.StmtIterator)46 Test (org.junit.Test)39 RDFNode (org.apache.jena.rdf.model.RDFNode)29 Dataset (org.apache.jena.query.Dataset)28 ArrayList (java.util.ArrayList)25 Property (org.apache.jena.rdf.model.Property)18 ReifiedStatement (org.apache.jena.rdf.model.ReifiedStatement)17 Triple (org.apache.jena.graph.Triple)16 WonMessageValidator (won.protocol.validation.WonMessageValidator)14 TextIndexException (org.apache.jena.query.text.TextIndexException)12 Ignore (org.junit.Ignore)10 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)8 Iterator (java.util.Iterator)7 SecuredReifiedStatement (org.apache.jena.permissions.model.SecuredReifiedStatement)7 SecuredStatement (org.apache.jena.permissions.model.SecuredStatement)7 Literal (org.apache.jena.rdf.model.Literal)7 SecuredPrefixMappingTest (org.apache.jena.permissions.graph.SecuredPrefixMappingTest)6