Search in sources :

Example 1 with Statement

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

the class ExModelSDB method main.

public static void main(String... argv) {
    Store store = StoreFactory.create("sdb.ttl");
    Model model = SDBFactory.connectDefaultModel(store);
    StmtIterator sIter = model.listStatements();
    for (; sIter.hasNext(); ) {
        Statement stmt = sIter.nextStatement();
        System.out.println(stmt);
    }
    sIter.close();
    store.close();
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Store(org.apache.jena.sdb.Store)

Example 2 with Statement

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

the class TextIndexLuceneAssembler method open.

/*
    <#index> a :TextIndexLucene ;
        #text:directory "mem" ;
        #text:directory "DIR" ;
        text:directory <file:DIR> ;
        text:entityMap <#endMap> ;
        .
    */
@SuppressWarnings("resource")
@Override
public TextIndex open(Assembler a, Resource root, Mode mode) {
    try {
        if (!GraphUtils.exactlyOneProperty(root, pDirectory))
            throw new TextIndexException("No 'text:directory' property on " + root);
        Directory directory;
        RDFNode n = root.getProperty(pDirectory).getObject();
        if (n.isLiteral()) {
            String literalValue = n.asLiteral().getLexicalForm();
            if (literalValue.equals("mem")) {
                directory = new RAMDirectory();
            } else {
                File dir = new File(literalValue);
                directory = FSDirectory.open(dir.toPath());
            }
        } else {
            Resource x = n.asResource();
            String path = IRILib.IRIToFilename(x.getURI());
            File dir = new File(path);
            directory = FSDirectory.open(dir.toPath());
        }
        Analyzer analyzer = null;
        Statement analyzerStatement = root.getProperty(pAnalyzer);
        if (null != analyzerStatement) {
            RDFNode aNode = analyzerStatement.getObject();
            if (!aNode.isResource()) {
                throw new TextIndexException("Text analyzer property is not a resource : " + aNode);
            }
            Resource analyzerResource = (Resource) aNode;
            analyzer = (Analyzer) a.open(analyzerResource);
        }
        Analyzer queryAnalyzer = null;
        Statement queryAnalyzerStatement = root.getProperty(pQueryAnalyzer);
        if (null != queryAnalyzerStatement) {
            RDFNode qaNode = queryAnalyzerStatement.getObject();
            if (!qaNode.isResource()) {
                throw new TextIndexException("Text query analyzer property is not a resource : " + qaNode);
            }
            Resource analyzerResource = (Resource) qaNode;
            queryAnalyzer = (Analyzer) a.open(analyzerResource);
        }
        String queryParser = null;
        Statement queryParserStatement = root.getProperty(pQueryParser);
        if (null != queryParserStatement) {
            RDFNode qpNode = queryParserStatement.getObject();
            if (!qpNode.isResource()) {
                throw new TextIndexException("Text query parser property is not a resource : " + qpNode);
            }
            Resource parserResource = (Resource) qpNode;
            queryParser = parserResource.getLocalName();
        }
        boolean isMultilingualSupport = false;
        Statement mlSupportStatement = root.getProperty(pMultilingualSupport);
        if (null != mlSupportStatement) {
            RDFNode mlsNode = mlSupportStatement.getObject();
            if (!mlsNode.isLiteral()) {
                throw new TextIndexException("text:multilingualSupport property must be a string : " + mlsNode);
            }
            isMultilingualSupport = mlsNode.asLiteral().getBoolean();
        }
        boolean storeValues = false;
        Statement storeValuesStatement = root.getProperty(pStoreValues);
        if (null != storeValuesStatement) {
            RDFNode svNode = storeValuesStatement.getObject();
            if (!svNode.isLiteral()) {
                throw new TextIndexException("text:storeValues property must be a string : " + svNode);
            }
            storeValues = svNode.asLiteral().getBoolean();
        }
        Resource r = GraphUtils.getResourceValue(root, pEntityMap);
        EntityDefinition docDef = (EntityDefinition) a.open(r);
        TextIndexConfig config = new TextIndexConfig(docDef);
        config.setAnalyzer(analyzer);
        config.setQueryAnalyzer(queryAnalyzer);
        config.setQueryParser(queryParser);
        config.setMultilingualSupport(isMultilingualSupport);
        config.setValueStored(storeValues);
        return TextDatasetFactory.createLuceneIndex(directory, config);
    } catch (IOException e) {
        IO.exception(e);
        return null;
    }
}
Also used : Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) IOException(java.io.IOException) Analyzer(org.apache.lucene.analysis.Analyzer) RAMDirectory(org.apache.lucene.store.RAMDirectory) File(java.io.File) RDFNode(org.apache.jena.rdf.model.RDFNode) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 3 with Statement

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

the class ConfigurableAnalyzerAssembler method toFilterList.

private List<String> toFilterList(Resource list) {
    List<String> result = new ArrayList<>();
    Resource current = list;
    while (current != null && !current.equals(RDF.nil)) {
        Statement stmt = current.getProperty(RDF.first);
        if (stmt == null) {
            throw new TextIndexException("filter list not well formed");
        }
        RDFNode node = stmt.getObject();
        if (!node.isResource()) {
            throw new TextIndexException("filter is not a resource : " + node);
        }
        result.add(node.asResource().getLocalName());
        stmt = current.getProperty(RDF.rest);
        if (stmt == null) {
            throw new TextIndexException("filter list not terminated by rdf:nil");
        }
        node = stmt.getObject();
        if (!node.isResource()) {
            throw new TextIndexException("filter list node is not a resource : " + node);
        }
        current = node.asResource();
    }
    return result;
}
Also used : TextIndexException(org.apache.jena.query.text.TextIndexException) Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 4 with Statement

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

the class T_TransSystem method describeWithAbort.

public static int describeWithAbort(String queryStr, DatasetGraph dsg, long abortTime) {
    int counter = 0;
    Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ);
    try (QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.wrap(dsg))) {
        qExec.setTimeout(abortTime);
        Model model = qExec.execDescribe();
        //ResultSet rs = qExec.execSelect() ;
        for (Iterator<Statement> stmIterator = model.listStatements(); stmIterator.hasNext(); ) {
            stmIterator.next();
            counter++;
        }
        return counter;
    }
}
Also used : Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model)

Example 5 with Statement

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

the class TestModelSetOperations method testUnion.

public void testUnion() {
    ModelHelper.modelAdd(model, "a P b; w R x");
    ModelHelper.modelAdd(model2, "w R x; y S z");
    final Model um = model.union(model2);
    Assert.assertFalse(model.containsAll(model2));
    Assert.assertFalse(model2.containsAll(model));
    Assert.assertTrue(um.containsAll(model));
    Assert.assertTrue(um.containsAll(model2));
    for (final StmtIterator it = um.listStatements(); it.hasNext(); ) {
        final Statement s = it.nextStatement();
        Assert.assertTrue(model.contains(s) || model2.contains(s));
    }
    for (final StmtIterator it = model.listStatements(); it.hasNext(); ) {
        Assert.assertTrue(um.contains(it.nextStatement()));
    }
    for (final StmtIterator it = model2.listStatements(); it.hasNext(); ) {
        Assert.assertTrue(um.contains(it.nextStatement()));
    }
    Assert.assertTrue(um.containsAll(model.listStatements()));
    Assert.assertTrue(um.containsAll(model2.listStatements()));
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)72 Model (org.apache.jena.rdf.model.Model)43 StmtIterator (org.apache.jena.rdf.model.StmtIterator)28 Test (org.junit.Test)25 Dataset (org.apache.jena.query.Dataset)24 Resource (org.apache.jena.rdf.model.Resource)19 WonMessageValidator (won.protocol.validation.WonMessageValidator)15 Property (org.apache.jena.rdf.model.Property)13 RDFNode (org.apache.jena.rdf.model.RDFNode)13 ArrayList (java.util.ArrayList)11 Ignore (org.junit.Ignore)11 Triple (org.apache.jena.graph.Triple)7 BaseTest (org.apache.jena.atlas.junit.BaseTest)6 Iterator (java.util.Iterator)4 RdfUtils (won.protocol.util.RdfUtils)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 OntModel (org.apache.jena.ontology.OntModel)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 GraphCollection (de.uni_koblenz.aggrimm.icp.crypto.sign.graph.GraphCollection)1