use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestAssembler method model_6.
@Test
public void model_6() {
Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
Resource xNamed = assem.getResource("http://example/test#graphNamed");
Store store = create(assem);
// Named graph: Check they are connected to the same place in the store
Model model2 = (Model) Assembler.general.open(xNamed);
Model model3 = (Model) Assembler.general.open(xNamed);
Resource s = model2.createResource();
Property p = model2.createProperty("http://example/p");
// Check two models connected to the same graph
Literal o2 = model2.createLiteral("xyz");
model2.add(s, p, o2);
assertTrue(model3.contains(s, p, o2));
}
use of org.apache.jena.rdf.model.Property 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.Property in project jena by apache.
the class AbstractWholeFileTripleInputFormatTests method generateTuples.
@Override
protected final void generateTuples(OutputStream output, int num) throws IOException {
Model m = ModelFactory.createDefaultModel();
Resource currSubj = m.createResource("http://example.org/subjects/0");
Property predicate = m.createProperty("http://example.org/predicate");
for (int i = 0; i < num; i++) {
if (i % 10 == 0) {
currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
}
m.add(currSubj, predicate, m.createTypedLiteral(i));
}
this.writeTuples(m, output);
output.close();
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class AbstractCompressedWholeFileTripleInputFormatTests method generateTuples.
@Override
protected final void generateTuples(OutputStream output, int num) throws IOException {
Model m = ModelFactory.createDefaultModel();
Resource currSubj = m.createResource("http://example.org/subjects/0");
Property predicate = m.createProperty("http://example.org/predicate");
for (int i = 0; i < num; i++) {
if (i % 10 == 0) {
currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
}
m.add(currSubj, predicate, m.createTypedLiteral(i));
}
this.writeTuples(m, output);
output.close();
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class AbstractWholeFileTripleInputFormatTests method generateMixedTuples.
@Override
protected final void generateMixedTuples(OutputStream output, int num) throws IOException {
// Write good data
Model m = ModelFactory.createDefaultModel();
Resource currSubj = m.createResource("http://example.org/subjects/0");
Property predicate = m.createProperty("http://example.org/predicate");
for (int i = 0; i < num / 2; i++) {
if (i % 10 == 0) {
currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
}
m.add(currSubj, predicate, m.createTypedLiteral(i));
}
this.writeTuples(m, output);
// Write junk data
byte[] junk = "junk data\n".getBytes(utf8);
for (int i = 0; i < num / 2; i++) {
output.write(junk);
}
output.flush();
output.close();
}
Aggregations