Java Code Examples for org.apache.jena.query.DatasetFactory#wrap()
The following examples show how to use
org.apache.jena.query.DatasetFactory#wrap() .
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: DeltaEx01_DatasetWithPatchLog.java From rdf-delta with Apache License 2.0 | 6 votes |
public static void main(String ...args) { // -- Base dataset DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem(); // -- Destination for changes. // Text form of output. OutputStream out = System.out; // Create an RDFChanges that writes to "out". RDFChanges changeLog = RDFPatchOps.textWriter(out); // Combined datasetgraph and changes. DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog); // Wrap in the Dataset API Dataset ds = DatasetFactory.wrap(dsg); // -------- // Do something. Read in data.ttl inside a transaction. // (data.ttl is in src/main/resources/) Txn.executeWrite(ds, ()->RDFDataMgr.read(dsg, "data.ttl") ); }
Example 2
Source File: DatasetDeclarationPlan.java From sparql-generate with Apache License 2.0 | 6 votes |
protected final Context prepareDataset(Binding binding, Context context) { if (fromClauses == null || fromClauses.isEmpty()) { return context; } final DatasetGraph dsg = DatasetGraphFactory.createGeneral(); fromClauses.forEach((fromClause) -> { if (fromClause.getGenerate() == null) { if (!fromClause.isNamed()) { addDefaultGraph(binding, context, dsg, fromClause.getName()); } else { addNamedGraph(binding, context, dsg, fromClause.getName()); } } else { SPARQLExtQuery generate = fromClause.getGenerate(); if (!fromClause.isNamed()) { addDefaultGraph(binding, context, dsg, generate); } else { addNamedGraph(binding, context, dsg, generate, fromClause.getName()); } } }); Dataset newDataset = DatasetFactory.wrap(dsg); return ContextUtils.fork(context).setDataset(newDataset).fork(); }
Example 3
Source File: ExecuteSPARQLStar.java From RDFstarTools with Apache License 2.0 | 5 votes |
@Override public Dataset createDataset() { final DatasetGraph dsg = DatasetGraphFactory.createTxnMem(); final DatasetGraph dsgWrapped = new DatasetGraphWrapperStar(dsg); final Dataset ds = DatasetFactory.wrap(dsgWrapped); addGraphs(ds); dataset = ds; return dataset; }
Example 4
Source File: DeltaEx02_DatasetCollectPatch.java From rdf-delta with Apache License 2.0 | 5 votes |
public static void main(String ...args) { // -- Base dataset DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem(); // -- Destination for changes. // Text form of output. OutputStream out = System.out; // Create an RDFChanges that writes to "out". RDFChanges changeLog = RDFPatchOps.textWriter(out); // ---- Collect up changes. //RDFPatchOps.collect(); RDFChangesCollector rcc = new RDFChangesCollector(); DatasetGraph dsg = RDFPatchOps.changes(dsgBase, rcc); Dataset ds = DatasetFactory.wrap(dsg); Txn.executeWrite(ds, ()->RDFDataMgr.read(dsg, "data.ttl") ); // Again - different bnodes. // Note all changes are recorded - even if they have no effect // (e.g the prefix, the triple "ex:s ex:p ex:o"). Txn.executeWrite(ds, ()->RDFDataMgr.read(dsg, "data.ttl") ); // Collected (in-memory) patch. RDFPatch patch = rcc.getRDFPatch(); // Write it. patch.apply(changeLog); }
Example 5
Source File: DeltaConnection.java From rdf-delta with Apache License 2.0 | 5 votes |
private DeltaConnection(DataState dataState, DatasetGraph basedsg, DeltaLink link, SyncPolicy syncTxnBegin) { Objects.requireNonNull(dataState, "DataState"); Objects.requireNonNull(link, "DeltaLink"); //Objects.requireNonNull(basedsg, "base DatasetGraph"); if ( basedsg instanceof DatasetGraphChanges ) FmtLog.warn(this.getClass(), "[%s] DatasetGraphChanges passed into %s", dataState.getDataSourceId() ,Lib.className(this)); this.state = dataState; this.base = basedsg; this.datasourceId = dataState.getDataSourceId(); this.datasourceName = dataState.getDatasourceName(); this.dLink = link; this.valid = true; this.syncPolicy = syncTxnBegin; if ( basedsg == null ) { this.target = null; this.managed = null; this.managedDataset = null; this.managedNoEmpty = null; this.managedNoEmptyDataset = null; return; } // Where to put incoming changes. this.target = new RDFChangesApply(basedsg); // Note: future possibility of having RDFChangesEvents // RDFChanges t = new RDFChangesApply(basedsg); // //t = new RDFChangesEvents(t, n->{System.out.println("**** Event: "+n); return null;}); // this.target = t; // Where to send outgoing changes. RDFChanges monitor = new RDFChangesDS(); this.managed = new DatasetGraphChanges(basedsg, monitor, null, syncer(syncTxnBegin)); this.managedDataset = DatasetFactory.wrap(managed); // ---- RDFChanges monitor1 = new RDFChangesSuppressEmpty(monitor); this.managedNoEmpty = new DatasetGraphChanges(basedsg, monitor1, null, syncer(syncTxnBegin)); this.managedNoEmptyDataset = DatasetFactory.wrap(managedNoEmpty); }
Example 6
Source File: AssemblerFileLog.java From rdf-delta with Apache License 2.0 | 4 votes |
@Override public Object open(Assembler a, Resource root, Mode mode) { if ( !exactlyOneProperty(root, VocabPatch.pDataset) ) throw new AssemblerException(root, "No dataset to be logged"); if ( !root.hasProperty(VocabPatch.pLogFile) ) throw new AssemblerException(root, "No log file"); Resource dataset = GraphUtils.getResourceValue(root, VocabPatch.pDataset); List<String> destLogs = GraphUtils.multiValueAsString(root, VocabPatch.pLogFile); String logPolicy = GraphUtils.getStringValue(root, VocabPatch.pLogPolicy); FilePolicy policy = logPolicy == null ? FilePolicy.FIXED : FilePolicy.policy(logPolicy); DatasetGraph dsgBase;; try { Dataset dsBase = (Dataset)a.open(dataset); dsgBase = dsBase.asDatasetGraph(); } catch (Exception ex) { FmtLog.error(this.getClass(), "Failed to build the dataset to adding change logging to: %s",dataset); throw ex; } RDFChanges changes = null; // It would be better if each file had a policy. // patch:logFile [ patch:filename ; patch:policy ]; // patch:logFile ("FILE" "FIXED"); for ( String x : destLogs ) { FmtLog.info(LOG, "Log file: '%s'", x); if ( x.startsWith("file:") ) x = IRILib.IRIToFilename(x); ManagedOutput output = OutputMgr.create(x, policy); // -------------- String ext = FileUtils.getFilenameExt(x); // if ( ext.equals("gz") ) { // String fn2 = x.substring(0, ".gz".length()); // ext = FileUtils.getFilenameExt(fn2); // } // OutputStream out = IO.openOutputFile(x); boolean binaryPatches = ext.equalsIgnoreCase(RDFPatchConst.EXT_B); RDFChanges sc = binaryPatches ? null //RDFPatchOps.binaryWriter(out); //: RDFPatchOps.textWriter(out); : new RDFChangesManagedOutput(output); if ( sc == null ) throw new AssemblerException(root, "Failed to build the output destination: "+x); changes = RDFChangesN.multi(changes, sc); } DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changes); Dataset ds = DatasetFactory.wrap(dsg); return ds; }
Example 7
Source File: TestDatasetGraphWithAbort.java From rdf-delta with Apache License 2.0 | 4 votes |
protected Dataset create() { DatasetGraph dsg1 = DatasetGraphFactory.create() ; DatasetGraphBuffering dsg = new DatasetGraphBuffering(dsg1) ; return DatasetFactory.wrap(dsg) ; }
Example 8
Source File: DeltaAssembler.java From rdf-delta with Apache License 2.0 | 4 votes |
@Override public Dataset open(Assembler a, Resource root, Mode mode) { // delta:changes ; list or multiple properties. List<String> deltaServers = getAsMultiStringValue(root, pDeltaChanges); if ( deltaServers.isEmpty() ) throw new AssemblerException(root, "No destination for changes given"); FmtLog.info(Delta.DELTA_CLIENT, "Delta Patch Log Servers: "+deltaServers) ; // Name of the patch log. // delta:patchlog if ( ! exactlyOneProperty(root, pDeltaPatchLog) ) throw new AssemblerException(root, "No patch log name") ; String dsName = getAsStringValue(root, pDeltaPatchLog); // delta:storage // delta:dataset, which is implicitly delta:storage "external". // Checking stage. boolean hasExternalDataset = root.hasProperty(pDataset); DatasetGraph externalDataset = null; if ( hasExternalDataset ) { Resource datasetR = GraphUtils.getResourceValue(root, pDataset) ; Dataset ds = (Dataset)a.open(datasetR) ; externalDataset = ds.asDatasetGraph(); } if ( ! root.hasProperty(pDeltaStorage) && ! hasExternalDataset ) throw new AssemblerException(root, "Must have storage type (delta:storage) or an external dataset description (delat:dataset)"); String storageTypeStr = getAsStringValue(root, pDeltaStorage); LocalStorageType storage = LocalStorageType.fromString(storageTypeStr); if ( storage == null ) { if ( hasExternalDataset ) storage = LocalStorageType.EXTERNAL; else throw new AssemblerException(root, "Unrecognized storage type '"+storageTypeStr+"'"); } else { if ( hasExternalDataset && ( storage != LocalStorageType.EXTERNAL ) ) throw new AssemblerException(root, "Storage type must be 'external' or absent when using delta:dataset"); } // delta:zone. // The zone is ephemeral if the storage is ephemeral. Location zoneLocation; if ( storage.isEphemeral() ) zoneLocation = Location.mem(); else { if ( !exactlyOneProperty(root, pDeltaZone) ) throw new AssemblerException(root, "No location for state manangement (zone)"); String zoneLocationStr = getAsStringValue(root, pDeltaZone); zoneLocation = Location.create(zoneLocationStr); } // Build. DatasetGraph dsg = (externalDataset == null) ? LibBuildDC.setupDataset(dsName, zoneLocation, storage, deltaServers) : LibBuildDC.setupDataset(dsName, zoneLocation, externalDataset, deltaServers); Dataset dataset = DatasetFactory.wrap(dsg); // Poll for changes as well. Not implemented (yet). // if ( root.hasProperty(pPollForChanges) ) { // if ( ! exactlyOneProperty(root, pPollForChanges) ) // throw new AssemblerException(root, "Multiple places to poll for chnages") ; // String source = getStringValue(root, pPollForChanges) ; // forkUpdateFetcher(source, dsgSub) ; // } return dataset; }