本文整理汇总了Java中org.apache.jena.query.DatasetFactory.createMem方法的典型用法代码示例。如果您正苦于以下问题:Java DatasetFactory.createMem方法的具体用法?Java DatasetFactory.createMem怎么用?Java DatasetFactory.createMem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.query.DatasetFactory
的用法示例。
在下文中一共展示了DatasetFactory.createMem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkModel
import org.apache.jena.query.DatasetFactory; //导入方法依赖的package包/类
private void checkModel(Model model, URI uri, boolean useCompression) {
String fileName = FileBasedSink.generateFileName(uri.toString(), useCompression);
File file = new File(tempDirectory.getAbsolutePath() + File.separator + fileName);
if (model.size() == 0) {
Assert.assertFalse("found a file " + file.getAbsolutePath() + " while the model of " + uri.toString()
+ " was empty (and shouldn't create a file).", file.exists());
return;
} else {
Assert.assertTrue("Couldn't find the file " + file.getAbsolutePath() + " for model " + uri.toString(),
file.exists());
}
Model readModel = null;
Dataset readData = DatasetFactory.createMem();
InputStream in = null;
try {
in = new FileInputStream(file);
if (useCompression) {
in = new GZIPInputStream(in);
}
RDFDataMgr.read(readData, in, Lang.NQ);
} catch (IOException e) {
e.printStackTrace();
Assert.fail("Couldn't read file for model " + uri.toString());
} finally {
IOUtils.closeQuietly(in);
}
readModel = readData.getNamedModel(uri.toString());
String errorMsg = "The read model of " + uri.toString() + ": " + readModel
+ " does not fit the expected model: " + model;
StmtIterator iterator = model.listStatements();
Statement s;
while (iterator.hasNext()) {
s = iterator.next();
Assert.assertTrue(errorMsg + " The read Model does not contain " + s, readModel.contains(s));
}
iterator = readModel.listStatements();
while (iterator.hasNext()) {
s = iterator.next();
Assert.assertTrue(errorMsg + " The read Model has the additional triple " + s, readModel.contains(s));
}
}
示例2: annotationDatasetFor
import org.apache.jena.query.DatasetFactory; //导入方法依赖的package包/类
public Dataset annotationDatasetFor(Child<?> workflowBean) {
Dataset dataset = DatasetFactory.createMem();
for (Annotation ann : scufl2Tools.annotationsFor(workflowBean)) {
WorkflowBundle bundle = ann.getParent();
URI annUri = uritools.uriForBean(ann);
String bodyUri = bundle.getGlobalBaseURI().resolve(ann.getBody())
.toASCIIString();
if (ann.getBody().isAbsolute()) {
logger.info("Skipping absolute annotation body URI: "
+ ann.getBody());
// TODO: Optional loading of external annotation bodies
continue;
}
String path = ann.getBody().getPath();
ResourceEntry resourceEntry = bundle.getResources()
.getResourceEntry(path);
if (resourceEntry == null) {
logger.warning("Can't find annotation body: " + path);
continue;
}
String contentType = resourceEntry.getMediaType();
Lang lang = RDFLanguages.contentTypeToLang(contentType);
if (lang == null) {
lang = RDFLanguages.filenameToLang(path);
}
if (lang == null) {
logger.warning("Can't find media type of annotation body: "
+ ann.getBody());
continue;
}
Model model = ModelFactory.createDefaultModel();
try (InputStream inStream = bundle.getResources()
.getResourceAsInputStream(path)) {
RDFDataMgr.read(model, inStream, bodyUri, lang);
} catch (IOException e) {
logger.warning("Can't read annotation body: " + path);
continue;
}
dataset.addNamedModel(annUri.toString(), model);
}
return dataset;
}
示例3: export
import org.apache.jena.query.DatasetFactory; //导入方法依赖的package包/类
@Override
public Optional<Dataset> export() throws DMPGraphException {
tx.ensureRunningTx();
try {
/*
* // all nodes would also return endnodes without further outgoing relations final Iterable<Node> recordNodes;
* GlobalGraphOperations globalGraphOperations = GlobalGraphOperations.at(database); recordNodes =
* globalGraphOperations.getAllNodes();
*/
final GlobalGraphOperations globalGraphOperations = GlobalGraphOperations.at(database);
// TODO: maybe slice this a bit, and deliver the whole graph in pieces
final Iterable<Relationship> relations = globalGraphOperations.getAllRelationships();
if (relations == null) {
tx.succeedTx();
return Optional.absent();
}
dataset = DatasetFactory.createMem();
for (final Relationship recordNode : relations) {
relationshipHandler.handleRelationship(recordNode);
}
// please also note that the Jena model implementation has its size limits (~1 mio statements (?) -> so one graph
// (of
// one data resource) need to keep this size in mind)
if (BaseRDFExporter.JENA_MODEL_WARNING_SIZE == successfullyProcessedStatements) {
GraphRDFExporter.LOG.warn("reached {} statements. This is approximately the jena model implementation size limit.",
BaseRDFExporter.JENA_MODEL_WARNING_SIZE);
}
tx.succeedTx();
} catch (final Exception e) {
final String mesage = "couldn't finish read RDF TX successfully";
tx.failTx();
GraphRDFExporter.LOG.error(mesage, e);
throw new DMPGraphException(mesage);
}
return Optional.fromNullable(dataset);
}