简体   繁体   中英

Creating a named model in Jena

Given that this introduction states that using named models is better practice than using the default model, I'm trying to add a named model to a dataset:

Dataset dataset = TDBFactory.createDataset("MyDataset");
System.out.println(dataset.containsNamedModel("MyNewModel"));
Model MyNewModel = ModelFactory.createDefaultModel();
dataset.begin(ReadWrite.WRITE);
dataset.addNamedModel("MyNewModel", MyNewModel);
dataset.commit();
System.out.println(dataset.containsNamedModel("MyNewModel"));

but this returns

false
false

(so it's obviously not adding the model!). I had a look through the docs , and there is a createMethod(String name) method . I've tried using this, but because it's in an Interface, java complains when I try an instantiate ModelMaker ( Cannot instantiate the type ModelMaker ) - and the docs don't show which classes implement which interface.

This leads to a couple of questions:

  1. Is it actually best practice to use a named model in a dataset, rather than a default model?
  2. How do I call the createModel method? In the more verbose documentation it says that ModelFactory contains a method createFileModelMaker(String) - but the java docs don't mention this method, and trying to call it predictably leads to The method createFileModelMaker(String) is undefined for the type ModelFactory !

MyNewModel is empty so there is nothing to add. addNamedModel means copy in the contents of one graph into a named on in the dataset.

In TDB, a named graph is held as quads (graph, subject, predicate, object). There is no separate graph management. If there is no quad for the named graph, then it is not in the dataset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM