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