use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class ExTDB6 method main.
public static void main(String[] args) throws Exception {
/// turn off the "No BGP optimizer warning"
TDB.setOptimizerWarningFlag(false);
final IRIFactory iriFactory = IRIFactory.semanticWebImplementation();
final String DATASET_DIR_NAME = "data0";
final Dataset data0 = TDBFactory.createDataset(DATASET_DIR_NAME);
// show the currently registered names
for (Iterator<String> it = data0.listNames(); it.hasNext(); ) {
out.println("NAME=" + it.next());
}
out.println("getting named model...");
/// this is the OWL portion
final Model model = data0.getNamedModel(MY_NS);
out.println("Model := " + model);
out.println("getting graph...");
/// this is the DATA in that MODEL
final Graph graph = model.getGraph();
out.println("Graph := " + graph);
if (graph.isEmpty()) {
final Resource product1 = model.createResource(iriFactory.construct(MY_NS + "product/1").toString());
final Property hasName = model.createProperty(MY_NS, "#hasName");
final Statement stmt = model.createStatement(product1, hasName, model.createLiteral("Beach Ball", "en"));
out.println("Statement = " + stmt);
model.add(stmt);
// just for fun
out.println("Triple := " + stmt.asTriple().toString());
} else {
out.println("Graph is not Empty; it has " + graph.size() + " Statements");
long t0, t1;
t0 = System.currentTimeMillis();
final Query q = QueryFactory.create("PREFIX exns: <" + MY_NS + "#>\n" + "PREFIX exprod: <" + MY_NS + "product/>\n" + " SELECT * " + // +" WHERE { exprod:1 exns:hasName ?name }"
" WHERE { ?res ?pred ?obj }");
out.println("Query := " + q);
t1 = System.currentTimeMillis();
out.println("QueryFactory.TIME=" + (t1 - t0));
t0 = System.currentTimeMillis();
final QueryExecution qExec = QueryExecutionFactory.create(q, model);
t1 = System.currentTimeMillis();
out.println("QueryExecutionFactory.TIME=" + (t1 - t0));
try {
t0 = System.currentTimeMillis();
ResultSet rs = qExec.execSelect();
t1 = System.currentTimeMillis();
out.println("executeSelect.TIME=" + (t1 - t0));
while (rs.hasNext()) {
QuerySolution sol = rs.next();
out.println("Solution := " + sol);
for (Iterator<String> names = sol.varNames(); names.hasNext(); ) {
final String name = names.next();
out.println("\t" + name + " := " + sol.get(name));
}
}
} finally {
qExec.close();
}
}
out.println("closing graph");
graph.close();
out.println("closing model");
model.close();
//out.println("closing DataSetGraph");
//dsg.close();
out.println("closing DataSet");
data0.close();
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestConcurrentAccess method mrswGraph1.
@Test
public void mrswGraph1() {
Model m = create().getDefaultModel();
Resource r = m.createResource("x");
ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
assertNotNull(iter1.next());
ExtendedIterator<Statement> iter2 = m.listStatements(r, null, (RDFNode) null);
assertNotNull(iter2.next());
for (; iter2.hasNext(); ) iter2.next();
assertNotNull(iter1.next());
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestConcurrentAccess method mrswGraph3.
@Test(expected = ConcurrentModificationException.class)
public void mrswGraph3() {
Model m = create().getDefaultModel();
Resource r = m.createResource("x");
ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
assertNotNull(iter1.next());
Triple t = SSE.parseTriple("(<y> <p> 99)");
m.getGraph().delete(t);
// Bad
iter1.hasNext();
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class StandardAnalyzerAssembler method toList.
private List<String> toList(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("stop word list not well formed");
}
RDFNode node = stmt.getObject();
if (!node.isLiteral()) {
throw new TextIndexException("stop word is not a literal : " + node);
}
result.add(((Literal) node).getLexicalForm());
stmt = current.getProperty(RDF.rest);
if (stmt == null) {
throw new TextIndexException("stop word list not terminated by rdf:nil");
}
node = stmt.getObject();
if (!node.isResource()) {
throw new TextIndexException("stop word list node is not a resource : " + node);
}
current = (Resource) node;
}
return result;
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestInMemDatasetAssembler method directDataLinkToQuads.
@Test
public void directDataLinkToQuads() throws IOException {
// first make a file of quads to load later
final Model model = createDefaultModel();
final Path quads = createTempFile("quadExample", ".nq");
final Resource quadsURI = model.createResource(quads.toFile().toURI().toString());
final Resource simpleExample = model.createResource("test:simpleExample");
simpleExample.addProperty(type, DatasetAssemblerVocab.tDatasetTxnMem);
simpleExample.addProperty(data, quadsURI);
final DatasetGraph dsg = createTxnMem().asDatasetGraph();
model.listStatements().mapWith(Statement::asTriple).mapWith(t -> new Quad(quadsURI.asNode(), t)).forEachRemaining(dsg::add);
try (OutputStream out = new FileOutputStream(quads.toFile())) {
write(out, dsg, NQUADS);
}
final Dataset dataset = assemble(simpleExample);
final Model assembledDefaultModel = dataset.getDefaultModel();
final Model assembledNamedModel = dataset.getNamedModel(quadsURI.getURI());
assertTrue(assembledDefaultModel.isEmpty());
assertTrue(assembledNamedModel.contains(assembledNamedModel.createStatement(simpleExample, data, quadsURI)));
}
Aggregations