use of org.apache.jena.rdf.model.Model in project jena by apache.
the class TestAssembler method model_2.
@Test
public void model_2() {
Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
Resource x = assem.getResource("http://example/test#graphNamed");
// Model for default graph
Model model = (Model) Assembler.general.open(x);
assertNotNull(model);
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class TestConnection method connection_1.
@Test
public void connection_1() {
SDBConnection conn1 = SDBFactory.createConnection(conn);
Store store1 = StoreFactory.create(storeDesc, conn1);
// Reset
store1.getTableFormatter().format();
SDBConnection conn2 = SDBFactory.createConnection(conn);
Store store2 = StoreFactory.create(storeDesc, conn2);
Model model1 = SDBFactory.connectDefaultModel(store1);
Model model2 = SDBFactory.connectDefaultModel(store2);
Resource s = model1.createResource();
Property p = model1.createProperty("http://example/p");
// These are autocommit so two stores should be OK (but not a good design paradigm)
model1.add(s, p, "model1");
model2.add(s, p, "model2");
assertEquals(2, model1.size());
assertEquals(2, model2.size());
assertTrue(model1.isIsomorphicWith(model2));
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class TestAssembler method model_5.
@Test
public void model_5() {
Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
Resource xDft = assem.getResource("http://example/test#graphDft");
Store store = create(assem);
// Default graph: Check they are connected to the same place in the store
Model model2 = (Model) Assembler.general.open(xDft);
Model model3 = (Model) Assembler.general.open(xDft);
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.Model in project jena by apache.
the class TestAssembler method model_4.
@Test
public void model_4() {
Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
Resource xDft = assem.getResource("http://example/test#graphDft");
Resource xNamed = assem.getResource("http://example/test#graphNamed");
Store store = create(assem);
Model model1 = (Model) Assembler.general.open(xDft);
Model model2 = (Model) Assembler.general.open(xNamed);
// Check they are not connected to the same place in the store
Resource s = model1.createResource();
Property p = model1.createProperty("http://example/p");
Literal o = model1.createLiteral("foo");
model1.add(s, p, o);
assertTrue(model1.contains(s, p, o));
assertTrue(model1.size() == 1);
assertTrue(model2.size() == 0);
assertFalse(model1.isIsomorphicWith(model2));
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class ExJsonLD method doSimpleStuff.
/**
* Simple stuff.
*
* output using defaults,
* in "expanded"", compacted" or "flattened" format
* (framed is more difficult, not handled here)
*/
void doSimpleStuff() {
Model m = aSimpleModel();
// to get a default output: just do like for any other lang
System.out.println("--- DEFAULT ---");
m.write(System.out, "JSON-LD");
// same thing, using the more modern RDFDataMgr, and specifying the RDFFormat
System.out.println("\n--- DEFAULT ---");
RDFDataMgr.write(System.out, m, RDFFormat.JSONLD);
// output can be pretty (with line breaks), or not
System.out.println("\n--- DEFAULT, PRETTY (same as above, BTW) ---");
RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_PRETTY);
System.out.println("\n--- DEFAULT, FLAT ---");
RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_FLAT);
// all these default outputs use the JsonLD "Compact" format
// (note the "@context" node in the output)
// if prefixes are defined in the model,
// they are used in computing the @context,
// and corresponding values are displayed as prefix:localname
// (note something nice wrt prefixes in jsonld: look in the output at the value of "seeAlso")
m.setNsPrefix("ex", "http://www.ex.com/");
m.setNsPrefix("sh", "http://schema.org/");
System.out.println("\n--- DEFAULT, model including prefix mappings ---");
RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_PRETTY);
// Besides "Compact", JSON-LD defines the following kinds of outputs: expanded, flattened, and framed
// For each of them, there is a dedicated RDFFormat -- actually, 2 of them (one pretty, one flat)
// As previously seen, RDFFormat.JSONLD is just an alias of RDFFormat.JSONLD_COMPACT_PRETYY
// Let's try the other ones:
// Expand is the fastest one
// no @context in it
System.out.println("\n--- EXPAND ---");
RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_EXPAND_PRETTY);
// flatten has an @context node
System.out.println("\n--- FLATTEN ---");
RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_FLATTEN_PRETTY);
// framed requires some more parameters to run, we'll get back to it later
}
Aggregations