本文介绍了如何在TDB中存储多个本体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在一个项目中,该项目需要在一个TDB中保存多个本体.我试图用自己的方式做到这一点,但没有成功.请帮助我.如果您知道如何使用TDB,可以将应用到我的代码中的代码发布吗?
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();
但是我得到一个错误:错误1信息:
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信息:
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)
推荐答案
这些帮助函数对我有用:
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();
}
}
这篇关于如何在TDB中存储多个本体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!