How could I store multiple ontologies in TDB

人走茶凉 提交于 2019-12-02 01:29:47

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

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();
    }
  }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!