我正在开发一个需要在一个TDB中保存多个本体的项目。我试图以自己的方式做到这一点,但它没有用。请帮帮我..如果你知道如何使用TDB,你可以发布应用于我的代码的代码吗?
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();
但是我收到了一个错误: Error1信息:
ERROR [main] (ObjectFileStorage.java:345) - ObjectFileStorage.read[nodes](25148)[filesize=30366][file.size()=30366]: Impossibly large object : 879060026 bytes > filesize-(loc+SizeOfInt)=5214
错误2信息:
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)
答案 0 :(得分:1)
耶拿的哪个版本?
尝试将事务放在数据集上。
dataset.begin(ReadWrite.WRITE) ;
见 http://jena.apache.org/documentation/tdb/tdb_transactions.html
答案 1 :(得分:1)
这些助手功能对我有用:
/**
* 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();
}
}