问题
I am working on a project which need to save multiple ontologies in one TDB. I tried to do it in my own way, but it didn't work. Help me please..If you know how to use TDB , could you post the code applied to my code?
String directory = "./111";
Dataset dataset = TDBFactory.createDataset(directory);
Model tdb = dataset.getNamedModel("test1");
String source = "file:///e:/Course.rdf";
System.out.println(tdb.toString());
tdb.commit();
tdb.close();
String source2 = "file:///e:/lyx/resouces/Course1.rdf";
Model tdb2 = dataset.getNamedModel("test2");//see error1 information
FileManager.get().readModel( tdb2, source2);
System.out.println(tdb2.toString());//see error2 information
tdb2.commit();
tdb2.close();
dataset.close();
But I got a error: Error1 imformation:
ERROR [main] (ObjectFileStorage.java:345) - ObjectFileStorage.read[nodes](25148)[filesize=30366][file.size()=30366]: Impossibly large object : 879060026 bytes > filesize-(loc+SizeOfInt)=5214
Error2 imformation:
Exception in thread "main" com.hp.hpl.jena.tdb.base.file.FileException: ObjectFileStorage.read[nodes](30397)[filesize=33022][file.size()=33022]: Impossibly large object : 1711276032 bytes > filesize-(loc+SizeOfInt)=2621
at com.hp.hpl.jena.tdb.base.objectfile.ObjectFileStorage.read(ObjectFileStorage.java:346)
at com.hp.hpl.jena.tdb.lib.NodeLib.fetchDecode(NodeLib.java:78)
at com.hp.hpl.jena.tdb.nodetable.NodeTableNative.readNodeFromTable(NodeTableNative.java:178)
at com.hp.hpl.jena.tdb.nodetable.NodeTableNative._retrieveNodeByNodeId(NodeTableNative.java:103)
at com.hp.hpl.jena.tdb.nodetable.NodeTableNative.getNodeForNodeId(NodeTableNative.java:74)
at com.hp.hpl.jena.tdb.nodetable.NodeTableCache._retrieveNodeByNodeId(NodeTableCache.java:103)
at com.hp.hpl.jena.tdb.nodetable.NodeTableCache.getNodeForNodeId(NodeTableCache.java:74)
at com.hp.hpl.jena.tdb.nodetable.NodeTableWrapper.getNodeForNodeId(NodeTableWrapper.java:55)
at com.hp.hpl.jena.tdb.nodetable.NodeTableInline.getNodeForNodeId(NodeTableInline.java:67)
at com.hp.hpl.jena.tdb.lib.TupleLib.quad(TupleLib.java:161)
at com.hp.hpl.jena.tdb.lib.TupleLib.quad(TupleLib.java:153)
at com.hp.hpl.jena.tdb.lib.TupleLib.access$100(TupleLib.java:45)
at com.hp.hpl.jena.tdb.lib.TupleLib$4.convert(TupleLib.java:87)
at com.hp.hpl.jena.tdb.lib.TupleLib$4.convert(TupleLib.java:83)
at org.apache.jena.atlas.iterator.Iter$4.next(Iter.java:317)
at org.apache.jena.atlas.iterator.Iter$4.next(Iter.java:317)
at org.apache.jena.atlas.iterator.Iter.next(Iter.java:915)
at com.hp.hpl.jena.util.iterator.WrappedIterator.next(WrappedIterator.java:94)
at com.hp.hpl.jena.graph.impl.GraphBase.toString(GraphBase.java:422)
at com.hp.hpl.jena.graph.impl.GraphBase.toString(GraphBase.java:391)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.toString(ModelCom.java:1498)
at CreateTDB.main(CreateTDB.java:60)
回答1:
Which version of Jena?
Try putting the transaction on the dataset.
dataset.begin(ReadWrite.WRITE) ;
see http://jena.apache.org/documentation/tdb/tdb_transactions.html
回答2:
These helper functions work for me:
/**
* get a model for the given directory
*
* @param directory
* @return
*/
public Model getModel(String directory) {
// Make a TDB-backed dataset
dataset = TDBFactory.createDataset(directory);
// open write transaction
// see http://jena.apache.org/documentation/tdb/tdb_transactions.html
dataset.begin(ReadWrite.WRITE);
Model model = dataset.getDefaultModel();
return model;
}
/**
* save the given model
* @param model
*/
public void saveModel(Model model) {
if (model != null && dataset != null) {
model.commit();
model.close();
dataset.close();
}
}
来源:https://stackoverflow.com/questions/21115009/how-could-i-store-multiple-ontologies-in-tdb