org.apache.jena.query.DatasetFactory Java Examples
The following examples show how to use
org.apache.jena.query.DatasetFactory.
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: SparqlJenaEngineTest.java From zeppelin with Apache License 2.0 | 7 votes |
@BeforeClass public static void setUp() { port = Fuseki.choosePort(); Model model = ModelFactory.createDefaultModel(); model.read(DATA_FILE); Dataset ds = DatasetFactory.create(model); server = FusekiServer .create() .port(port) .add(DATASET, ds) .build(); DataAccessPointRegistry registry = server.getDataAccessPointRegistry(); assertTrue(registry.isRegistered(DATASET)); assertEquals(1, registry.size()); server.start(); }
Example #2
Source File: RdfStreamReaderDatasetTest.java From RDFUnit with Apache License 2.0 | 6 votes |
@Before public void setUp() { Model defaultModel = ModelFactory.createDefaultModel(); defaultModel.add( ResourceFactory.createResource("http://rdfunit.aksw.org"), OWL.sameAs, ResourceFactory.createResource("http://dbpedia.org/resource/Cool") ); Model namedModel = ModelFactory.createDefaultModel(); namedModel.add( ResourceFactory.createResource("http://rdfunit.aksw.org"), OWL.sameAs, ResourceFactory.createResource("http://dbpedia.org/resource/Super") ); dataset = DatasetFactory.create(defaultModel); dataset.addNamedModel("http://rdfunit.aksw.org", namedModel); }
Example #3
Source File: QueryExceptionHTTPMapper.java From Processor with Apache License 2.0 | 6 votes |
@Override public Response toResponse(QueryExceptionHTTP ex) { if (ex.getResponseCode() > 0) return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.fromStatusCode(ex.getResponseCode()), ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")). getModel())). status(ex.getResponseCode()). build(); else return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")). getModel())). status(Response.Status.INTERNAL_SERVER_ERROR). build(); }
Example #4
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 #5
Source File: PredicateMappingsDataSet.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public PredicateMappingsDataSet(int numberOfHashFunctions, int numberOfColorFunctions) { this.numberOfColorFunctions = numberOfColorFunctions; this.numberOfHashFunctions = numberOfHashFunctions; Model defModel = ModelFactory.createDefaultModel(); dataset = DatasetFactory.create(defModel); dataset.getDefaultModel() .getGraph() .add(new Triple(NodeFactory.createURI(Constants.ibmns + Constants.NUM_COL_FUNCTION), NodeFactory.createURI(Constants.ibmns + Constants.VALUE_PREDICATE), intToNode(numberOfColorFunctions))); dataset.getDefaultModel() .getGraph() .add(new Triple(NodeFactory.createURI(Constants.ibmns + Constants.NUM_HASH_FUNCTION), NodeFactory.createURI(Constants.ibmns + Constants.VALUE_PREDICATE), intToNode(numberOfHashFunctions))); }
Example #6
Source File: ExRIOT_3.java From xcurator with Apache License 2.0 | 6 votes |
public static void main(String...argv) { Dataset ds = null ; // Read a TriG file into quad storage in-memory. ds = RDFDataMgr.loadDataset("data.trig") ; // read some (more) data into a dataset graph. RDFDataMgr.read(ds, "data2.trig") ; // Create a dataset, Dataset ds2 = DatasetFactory.createTxnMem() ; // read in data, indicating the syntax in case the remote end does not // correctly provide the HTTP content type. RDFDataMgr.read(ds2, "http://host/data2.unknown", TRIG) ; }
Example #7
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 #8
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 #9
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 #10
Source File: UpdateExecuteOperations.java From xcurator with Apache License 2.0 | 5 votes |
public static void main(String []args) { // Create an empty DatasetGraph (has an empty default graph and no named graphs) Dataset dataset = DatasetFactory.createTxnMem() ; ex1(dataset) ; ex2(dataset) ; ex3(dataset) ; }
Example #11
Source File: RdfReader.java From RDFUnit with Apache License 2.0 | 5 votes |
default Dataset readDataset() throws RdfReaderException { try { Dataset dataset = DatasetFactory.create(); readDataset(dataset); return dataset; } catch (Exception e) { throw new RdfReaderException(e); } }
Example #12
Source File: RdfDocumentGraphConsumerTest.java From baleen with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException { JCasTestGraphUtil.populateJcas(jCas); port = getPort(); ds = DatasetFactory.createTxnMem(); server = FusekiServer.make(port, "/ds", ds.asDatasetGraph()).start(); }
Example #13
Source File: RdfEntityGraphConsumerTest.java From baleen with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException { JCasTestGraphUtil.populateJcas(jCas); ds = DatasetFactory.createTxnMem(); server = FusekiServer.create().add("/ds", ds).build(); server.start(); }
Example #14
Source File: DatatypeFormatExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(DatatypeFormatException ex) { return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.BAD_REQUEST, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")). getModel())). status(Response.Status.BAD_REQUEST). build(); }
Example #15
Source File: HttpExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(HttpException ex) { return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")). getModel())). status(Response.Status.INTERNAL_SERVER_ERROR). build(); }
Example #16
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 #17
Source File: RiotExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(RiotException ex) { return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.BAD_REQUEST, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")). getModel())). status(Response.Status.BAD_REQUEST). build(); }
Example #18
Source File: QueryParseExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(QueryParseException ex) { return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")). getModel())). status(Response.Status.INTERNAL_SERVER_ERROR). build(); }
Example #19
Source File: NotFoundExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(NotFoundException ex) { return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.NOT_FOUND, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#NotFound")). getModel())). status(Response.Status.NOT_FOUND). build(); }
Example #20
Source File: ConfigurationExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(ConfigurationException ex) { return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")). getModel())). status(Response.Status.INTERNAL_SERVER_ERROR). build(); }
Example #21
Source File: ParameterExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(ParameterException ex) { return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.BAD_REQUEST, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")). getModel())). status(Response.Status.BAD_REQUEST). build(); }
Example #22
Source File: ModelExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(ModelException ex) { Resource exception = toResource(ex, Response.Status.BAD_REQUEST, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")); ex.getModel().add(exception.getModel()); return getResponseBuilder(DatasetFactory.create(ex.getModel())).status(Response.Status.BAD_REQUEST).build(); }
Example #23
Source File: ClientExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(ClientException ex) { Resource exRes = toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")); if (ex.getClientResponse().getLocation() != null) exRes.addLiteral(HTTP.absoluteURI, ex.getClientResponse().getLocation()); return getResponseBuilder(DatasetFactory.create(exRes.getModel())). status(Response.Status.INTERNAL_SERVER_ERROR). build(); }
Example #24
Source File: OntologyExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(OntologyException ex) { return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")). getModel())). status(Response.Status.INTERNAL_SERVER_ERROR). build(); }
Example #25
Source File: Item.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response post(Dataset dataset) { if (log.isDebugEnabled()) log.debug("POST GRAPH {} to GraphStore {}", getURI()); Dataset newDataset = DatasetFactory.create(); newDataset.addNamedModel(getURI().toString(), dataset.getDefaultModel()); // put request entity graph into a named graph return super.post(newDataset); }
Example #26
Source File: ConstraintViolationExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(ConstraintViolationException ex) { Resource exception = toResource(ex, Response.Status.BAD_REQUEST, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")); ex.getModel().add(exception.getModel()); SPINConstraints.addConstraintViolationsRDF(ex.getConstraintViolations(), ex.getModel(), true); ResIterator it = ex.getModel().listSubjectsWithProperty(RDF.type, SPIN.ConstraintViolation); try { while (it.hasNext()) { Resource violation = it.next(); // connect Response to ConstraintViolations ex.getModel().add(exception, ResourceFactory.createProperty("http://www.w3.org/ns/prov#wasDerivedFrom"), violation); } } finally { it.close(); } return getResponseBuilder(DatasetFactory.create(ex.getModel())). status(Response.Status.BAD_REQUEST). build(); }
Example #27
Source File: SPARQLExtCli.java From sparql-generate with Apache License 2.0 | 5 votes |
private static Dataset getDataset(File dir, FileConfigurations request) { try { return request.loadDataset(dir); } catch (Exception ex) { LOG.warn("Error while loading the dataset, no dataset will be used."); return DatasetFactory.create(); } }
Example #28
Source File: ContextUtils.java From sparql-generate with Apache License 2.0 | 5 votes |
private Builder() { this.context = new Context(ARQ.getContext()); this.commons = new Commons(); // update functionregistry FunctionRegistry registry = (FunctionRegistry) context.get(ARQConstants.registryFunctions); SPARQLExtFunctionRegistry newRegistry = new SPARQLExtFunctionRegistry(registry, context); context.set(ARQConstants.registryFunctions, newRegistry); // update iteratorregistry IteratorFunctionRegistry iteratorRegistry = (IteratorFunctionRegistry) context .get(SPARQLExt.REGISTRY_ITERATORS); IteratorFunctionRegistry newIteratorRegistry = new IteratorFunctionRegistry(iteratorRegistry, context); context.set(SPARQLExt.REGISTRY_ITERATORS, newIteratorRegistry); // default streammanager context.set(SysRIOT.sysStreamManager, SPARQLExtStreamManager.makeStreamManager()); // set variable parts context.set(DATASET, DatasetFactory.create()); // default prefix manager context.set(PREFIX_MANAGER, PrefixMapping.Standard); // default number of results and blank nodes context.set(SIZE, 0); // context.set(LIST_NODES, new HashMap<>()); context.set(COMMONS, commons); }
Example #29
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 #30
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); }