org.apache.jena.sparql.sse.SSE Java Examples
The following examples show how to use
org.apache.jena.sparql.sse.SSE.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdateProgrammatic.java From xcurator with Apache License 2.0 | 6 votes |
public static void main(String []args) { Dataset dataset = DatasetFactory.createTxnMem() ; UpdateRequest request = UpdateFactory.create() ; request.add(new UpdateDrop(Target.ALL)) ; request.add(new UpdateCreate("http://example/g2")) ; request.add(new UpdateLoad("file:etc/update-data.ttl", "http://example/g2")) ; UpdateAction.execute(request, dataset) ; System.out.println("# Debug format"); SSE.write(dataset) ; System.out.println(); System.out.println("# N-Quads: S P O G") ; RDFDataMgr.write(System.out, dataset, Lang.NQUADS) ; }
Example #2
Source File: UpdateExecuteOperations.java From xcurator with Apache License 2.0 | 6 votes |
public static void ex3(Dataset dataset) { // Build up the request then execute it. // This is the preferred way for complex sequences of operations. UpdateRequest request = UpdateFactory.create() ; request.add("DROP ALL") .add("CREATE GRAPH <http://example/g2>") ; // Different style. // Equivalent to request.add("...") UpdateFactory.parse(request, "LOAD <file:etc/update-data.ttl> INTO GRAPH <http://example/g2>") ; // And perform the operations. UpdateAction.execute(request, dataset) ; System.out.println("# Debug format"); SSE.write(dataset) ; System.out.println(); System.out.println("# N-Quads: S P O G") ; RDFDataMgr.write(System.out, dataset, Lang.NQUADS) ; }
Example #3
Source File: AbstractTestDeltaConnection.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void change_1() { String NAME = "change_1s"; DeltaClient dClient = createRegister(NAME); try(DeltaConnection dConn = dClient.get(NAME)) { Version verLocal0 = dConn.getLocalVersion(); Version verRemotel0 = dConn.getRemoteVersionLatest(); DatasetGraph dsg = dConn.getDatasetGraph(); Txn.executeWrite(dsg, ()->{ dsg.add(SSE.parseQuad("(:gx :sx :px :ox)")); }); Version verLocal1 = dConn.getLocalVersion(); Version verRemotel1 = dConn.getRemoteVersionLatest(); assertEquals(verLocal1, dConn.getLocalVersion()); assertEquals(verRemotel1, dConn.getRemoteVersionLatest()); assertFalse(dConn.getDatasetGraph().isEmpty()); if ( dConn.getStorage() != null ) assertFalse(dConn.getStorage().isEmpty()); } }
Example #4
Source File: AbstractTestDeltaConnection.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void change_2() { String NAME = "change_2"; DeltaClient dClient = createRegister(NAME); try(DeltaConnection dConn = dClient.get(NAME)) { Id dsRef = dConn.getDataSourceId(); Version version = dConn.getRemoteVersionLatest(); DatasetGraph dsg = dConn.getDatasetGraph(); Txn.executeWrite(dsg, ()->{ Quad q = SSE.parseQuad("(_ :s1 :p1 :o1)"); dsg.add(q); }); // Rebuild directly. DatasetGraph dsg2 = DatasetGraphFactory.createTxnMem(); Version ver = dConn.getRemoteVersionLatest(); RDFPatch patch1 = dConn.getLink().fetch(dsRef, ver) ; RDFPatchOps.applyChange(dsg2, patch1); Set<Quad> set1 = Txn.calculateRead(dsg, ()->Iter.toSet(dsg.find())); Set<Quad> set2 = Txn.calculateRead(dsg2, ()->Iter.toSet(dsg2.find())); assertEquals(set1, set2); } }
Example #5
Source File: UpdateReadFromFile.java From xcurator with Apache License 2.0 | 6 votes |
public static void main(String []args) { // Create an empty GraphStore (has an empty default graph and no named graphs) Dataset dataset = DatasetFactory.createTxnMem() ; // ---- Read and update script in one step. UpdateAction.readExecute("update.ru", dataset) ; // ---- Reset. UpdateAction.parseExecute("DROP ALL", dataset) ; // ---- Read the update script, then execute, in separate two steps UpdateRequest request = UpdateFactory.read("update.ru") ; UpdateAction.execute(request, dataset) ; // Write in debug format. System.out.println("# Debug format"); SSE.write(dataset) ; System.out.println(); System.out.println("# N-Quads: S P O G") ; RDFDataMgr.write(System.out, dataset, Lang.NQUADS) ; }
Example #6
Source File: CustomAggregate.java From xcurator with Apache License 2.0 | 6 votes |
public static void main(String[] args) { // Example aggregate that counts literals. // Returns unbound for no rows. String aggUri = "http://example/countLiterals" ; /* Registration */ AggregateRegistry.register(aggUri, myAccumulatorFactory, NodeConst.nodeMinusOne); // Some data. Graph g = SSE.parseGraph("(graph (:s :p :o) (:s :p 1))") ; String qs = "SELECT (<http://example/countLiterals>(?o) AS ?x) {?s ?p ?o}" ; // Execution as normal. Query q = QueryFactory.create(qs) ; try ( QueryExecution qexec = QueryExecutionFactory.create(q, ModelFactory.createModelForGraph(g)) ) { ResultSet rs = qexec.execSelect() ; ResultSetFormatter.out(rs); } }
Example #7
Source File: AbstractTestDeltaClient.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void update_3() { // Create on the Delta link then setup DeltaClient DeltaLink dLink = getLink(); String DS_NAME = "12345"; Id dsRef = dLink.newDataSource(DS_NAME, "http://example/datasource_update_3"); DeltaClient dClient = createDeltaClient(); dClient.register(dsRef, LocalStorageType.MEM, SyncPolicy.NONE); DeltaConnection dConn = dClient.get(DS_NAME); Quad quad = SSE.parseQuad("(_ :s :p :o)"); DatasetGraph dsg = dConn.getDatasetGraph(); long x0 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) ); assertEquals(0, x0); dsg.begin(ReadWrite.WRITE); dsg.add(quad); dsg.abort(); long x1 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) ); assertEquals(0, x1); }
Example #8
Source File: TestRDFChangesCancel.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void changeSuppressEmptyCommit_4() { Quad q = SSE.parseQuad("(_ :s :p 'object')"); Triple t = SSE.parseTriple("(:t :p 'object')"); Txn.executeRead(dsg, ()->{}); testCounters(counter.summary(), 0, 0); Txn.executeWrite(dsg, ()->{dsg.add(q);}); testCounters(counter.summary(), 1, 0); Txn.executeWrite(dsg, ()->{dsg.getDefaultGraph().add(t);}); testCounters(counter.summary(), 2, 0); Txn.executeWrite(dsg, ()->{dsg.getDefaultGraph().getPrefixMapping().setNsPrefix("", "http://example/");}); testCounters(counter.summary(), 2, 1); Txn.executeWrite(dsg, ()->{}); testCounters(counter.summary(), 2, 1); }
Example #9
Source File: TestZone.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void zone_03() { assertTrue(zone.localConnections().isEmpty()); DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem(); String NAME = "ABC"; Id dsRef = registerExternal(NAME, dsgBase); assertFalse(zone.localConnections().isEmpty()); Quad quad = SSE.parseQuad("(_ :s :p :o)"); try(DeltaConnection dConn = deltaClient.get(dsRef)) { DatasetGraph dsg = dConn.getDatasetGraph(); Txn.executeWrite(dsg, ()->dsg.add(quad)); } // read log. PatchLogInfo info = deltaLink.getPatchLogInfo(dsRef); assertEquals(Version.create(1), info.getMaxVersion()); }
Example #10
Source File: ExRIOT_out3.java From xcurator with Apache License 2.0 | 5 votes |
@Override public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) { // Writers are discouraged : just hope the charset is UTF-8. IndentedWriter x = RiotLib.create(out) ; SSE.write(x, graph) ; }
Example #11
Source File: ExQuadFilter.java From xcurator with Apache License 2.0 | 5 votes |
/** Example setup - in-memory dataset with two graphs, one triple in each */ private static Dataset setup() { Dataset ds = TDBFactory.createDataset() ; DatasetGraph dsg = ds.asDatasetGraph() ; Quad q1 = SSE.parseQuad("(<http://example/g1> <http://example/s> <http://example/p> <http://example/o1>)") ; Quad q2 = SSE.parseQuad("(<http://example/g2> <http://example/s> <http://example/p> <http://example/o2>)") ; dsg.add(q1) ; dsg.add(q2) ; return ds ; }
Example #12
Source File: AbstractTestDeltaClient.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void update_2() { // Create on the Delta link then setup DeltaClient DeltaLink dLink = getLink(); String DS_NAME = "1234"; Id dsRef = dLink.newDataSource(DS_NAME, "http://example/datasource_update_2"); DeltaClient dClient = createDeltaClient(); dClient.register(dsRef, LocalStorageType.MEM, SyncPolicy.NONE); DeltaConnection dConn = dClient.get(DS_NAME); assertNotNull(dConn); assertEquals(Version.INIT, dConn.getLocalVersion()); assertEquals(Version.INIT, dConn.getRemoteVersionLatest()); Quad quad = SSE.parseQuad("(_ :s :p :o)"); DatasetGraph dsg = dConn.getDatasetGraph(); long x0 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) ); assertEquals(0, x0); Txn.executeWrite(dsg, ()->dsg.add(quad)); long x1 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) ); assertEquals(1, x1); long x2 = Iter.count(dConn.getStorage().find()); assertEquals(1, x1); }
Example #13
Source File: AbstractTestDeltaClient.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void update_1() { // Create on the Delta link then setup DeltaClient DeltaLink dLink = getLink(); String DS_NAME = "123"; Id dsRef = dLink.newDataSource(DS_NAME, "http://example/datasource_update_1"); DeltaClient dClient = createDeltaClient(); dClient.register(dsRef, LocalStorageType.MEM, SyncPolicy.NONE); DeltaConnection dConn = dClient.get(DS_NAME); assertNotNull(dConn); assertEquals(Version.INIT, dConn.getLocalVersion()); assertEquals(Version.INIT, dConn.getRemoteVersionLatest()); Quad quad = SSE.parseQuad("(_ :s :p :o)"); DatasetGraph dsg = dConn.getDatasetGraph(); long x0 = Iter.count(dsg.find()); assertEquals(0, x0); Txn.executeWrite(dsg, ()->dsg.add(quad)); long x1 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find())); assertEquals(1, x1); DatasetGraph dsgx = dConn.getStorage(); long x2 = Txn.calculateRead(dsgx, ()->Iter.count(dsgx.find())); assertEquals(1, x1); }
Example #14
Source File: DeltaTestLib.java From rdf-delta with Apache License 2.0 | 4 votes |
static Quad freshQuad() { return SSE.parseQuad("(_ :s :p '"+DateTimeUtils.nowAsXSDDateTimeString()+"'^^xsd:dateTimeStamp)"); }
Example #15
Source File: TestPatchFuseki.java From rdf-delta with Apache License 2.0 | 4 votes |
private static Node node(String string) { return SSE.parseNode(string); }
Example #16
Source File: TestManagedDatasetBuilder2.java From rdf-delta with Apache License 2.0 | 4 votes |
@Test public void buildManaged_persistentZone() { // Restart. Location loc = Location.create(ZONE_DIR); Zone zone = Zone.connect(loc); Quad q1 = SSE.parseQuad("(:g :s :p 1)"); Quad q2 = SSE.parseQuad("(:g :s :p 2)"); { DatasetGraph dsg = ManagedDatasetBuilder.create() .deltaLink(deltaLink) .logName("ABD") .zone(zone) .syncPolicy(SyncPolicy.TXN_RW) .storageType(LocalStorageType.TDB2) .build(); DeltaConnection conn = (DeltaConnection)(dsg.getContext().get(symDeltaConnection)); Txn.executeWrite(dsg, ()->dsg.add(q1)); Txn.executeRead( conn.getDatasetGraph(), ()->assertTrue(conn.getDatasetGraph().contains(q1)) ); } // Same zone Zone.clearZoneCache(); zone = Zone.connect(loc); // Storage should be recovered from the on-disk state. { DatasetGraph dsg1 = ManagedDatasetBuilder.create() .deltaLink(deltaLink) .logName("ABD") .zone(zone) .syncPolicy(SyncPolicy.TXN_RW) //.storageType(LocalStorageType.TDB2) // Storage required. Should detect [FIXME] .build(); DatasetGraph dsg2 = ManagedDatasetBuilder.create() .deltaLink(deltaLink) .logName("ABD") .zone(zone) .syncPolicy(SyncPolicy.TXN_RW) //.storageType(LocalStorageType.TDB) // Wrong storage - does not matter; dsg1 setup choice applies .build(); DeltaConnection conn1 = (DeltaConnection)(dsg1.getContext().get(symDeltaConnection)); DeltaConnection conn2 = (DeltaConnection)(dsg2.getContext().get(symDeltaConnection)); Txn.executeRead(conn1.getDatasetGraph(), ()->assertTrue(conn1.getDatasetGraph().contains(q1)) ); Txn.executeWrite(conn2.getDatasetGraph(), ()->conn2.getDatasetGraph().add(q2)); Txn.executeRead(conn1.getDatasetGraph(), ()->assertTrue(conn1.getDatasetGraph().contains(q2)) ); } }
Example #17
Source File: ExRIOT_5.java From xcurator with Apache License 2.0 | 4 votes |
@Override public void read(InputStream in, String baseURI, ContentType ct, StreamRDF output, Context context) { Item item = SSE.parse(in) ; read(item, baseURI, ct, output, context) ; }
Example #18
Source File: ExRIOT_5.java From xcurator with Apache License 2.0 | 4 votes |
@Override public void read(Reader in, String baseURI, ContentType ct, StreamRDF output, Context context) { Item item = SSE.parse(in) ; read(item, baseURI, ct, output, context) ; }
Example #19
Source File: ExRIOT_out3.java From xcurator with Apache License 2.0 | 4 votes |
@Override public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) { SSE.write(out, graph) ; }
Example #20
Source File: AbstractTestDeltaConnection.java From rdf-delta with Apache License 2.0 | 4 votes |
@Test public void change_empty_commit_1() { Quad q = SSE.parseQuad("(:g :s :p :o)") ; String NAME = "change_empty_commit_1"; DeltaClient dClient = createRegister(NAME); try(DeltaConnection dConn = dClient.get(NAME)) { Id patchId0 = dConn.getRemoteIdLatest(); assertNull(patchId0); Version ver0 = dConn.getRemoteVersionLatest(); // The "no empty commits" dsg DatasetGraph dsg = dConn.getDatasetGraphNoEmpty(); Txn.executeWrite(dsg, ()->{}); Id patchId1 = dConn.getLatestPatchId(); Version ver1 = dConn.getRemoteVersionLatest(); // No change at start of log. assertEquals(patchId0, patchId1); assertEquals(ver0, ver1); Txn.executeWrite(dsg, ()->dsg.add(q)); Id patchId2 = dConn.getLatestPatchId(); Version ver2 = dConn.getRemoteVersionLatest(); assertNotEquals(patchId0, patchId2); assertNotEquals(ver0, ver2); DatasetGraph dsgx = dConn.getDatasetGraph(); Txn.executeWrite(dsgx, ()->{}); Id patchId3 = dConn.getLatestPatchId(); Version ver3 = dConn.getRemoteVersionLatest(); assertNotEquals(patchId2, patchId3); assertNotEquals(ver2, ver3); // No change mid log. Txn.executeWrite(dsg, ()->Iter.count(dsg.find())); Id patchId4 = dConn.getLatestPatchId(); Version ver4 = dConn.getRemoteVersionLatest(); assertEquals(patchId3, patchId4); assertEquals(ver3, ver4); } }
Example #21
Source File: TestManagedDatasetBuilder.java From rdf-delta with Apache License 2.0 | 4 votes |
@Test public void buildManaged_3_differentZones() { // Different zones, same local server. Zone zone1 = Zone.connect(Location.mem()); Zone zone2 = Zone.connect(Location.mem()); DatasetGraph dsg1 = ManagedDatasetBuilder.create() .deltaLink(deltaLink) .logName("BCD") .zone(zone1) .syncPolicy(SyncPolicy.TXN_RW) .storageType(LocalStorageType.MEM) .build(); // Different zones. DeltaLink deltaLink2 = DeltaLinkLocal.connect(localServer); DatasetGraph dsg2 = ManagedDatasetBuilder.create() .deltaLink(deltaLink2) .logName("BCD") .zone(zone2) .syncPolicy(SyncPolicy.TXN_RW) .storageType(LocalStorageType.MEM) .build(); Quad q1 = SSE.parseQuad("(:g :s :p 1)"); Quad q2 = SSE.parseQuad("(:g :s :p 2)"); Txn.executeWrite(dsg1, ()->dsg1.add(q1)); Txn.executeRead(dsg2, ()->assertTrue(dsg2.contains(q1))); DeltaConnection conn1 = (DeltaConnection)(dsg1.getContext().get(symDeltaConnection)); DeltaConnection conn2 = (DeltaConnection)(dsg2.getContext().get(symDeltaConnection)); assertNotSame(conn1.getStorage(), conn2.getStorage()); try ( DeltaConnection c = conn1 ) { DatasetGraph dsg = c.getDatasetGraph(); Txn.executeRead( c.getDatasetGraph(), ()->assertTrue(dsg2.contains(q1)) ); Txn.executeWrite( c.getDatasetGraph(), ()->c.getDatasetGraph().add(q2) ); } try ( DeltaConnection c = conn2 ) { Txn.executeRead(c.getDatasetGraph(), ()->assertTrue(dsg2.contains(q2))); } }
Example #22
Source File: TestManagedDatasetBuilder.java From rdf-delta with Apache License 2.0 | 4 votes |
@Test public void buildManaged_2_sameZone() { Zone zone = Zone.connect(Location.mem()); DatasetGraph dsg1 = ManagedDatasetBuilder.create() .deltaLink(deltaLink) .logName("ABC") .zone(zone) .syncPolicy(SyncPolicy.TXN_RW) .storageType(LocalStorageType.MEM) .build(); // Rebuild from with same zone. Should get the same underlying storage database. // i.e. same Zone item. DeltaLink deltaLink2 = DeltaLinkLocal.connect(localServer); DatasetGraph dsg2 = ManagedDatasetBuilder.create() .deltaLink(deltaLink2) .logName("ABC") .zone(zone) .syncPolicy(SyncPolicy.TXN_RW) .storageType(LocalStorageType.MEM) .build(); assertNotSame(dsg1, dsg2); DeltaConnection conn1 = (DeltaConnection)(dsg1.getContext().get(symDeltaConnection)); DeltaConnection conn2 = (DeltaConnection)(dsg2.getContext().get(symDeltaConnection)); // Same zone, same underlying storage client-side assertSame(conn1.getStorage(), conn2.getStorage()); Quad q1 = SSE.parseQuad("(:g :s :p 1)"); Quad q2 = SSE.parseQuad("(:g :s :p 2)"); Txn.executeWrite(dsg1, ()->dsg1.add(q1)); Txn.executeRead(dsg2, ()->assertTrue(dsg2.contains(q1))); try ( DeltaConnection c = conn1 ) { DatasetGraph dsg = c.getDatasetGraph(); Txn.executeRead( c.getDatasetGraph(), ()->assertTrue(c.getDatasetGraph().contains(q1)) ); Txn.executeWrite( c.getDatasetGraph(), ()->c.getDatasetGraph().add(q2) ); } try ( DeltaConnection c = conn2 ) { Txn.executeRead(c.getDatasetGraph(), ()->assertTrue(c.getDatasetGraph().contains(q2))); } }
Example #23
Source File: TestRestart.java From rdf-delta with Apache License 2.0 | votes |
private static Quad quad() { return SSE.parseQuad("(_ :s :p "+(counter++)+")"); }