如何将本体模型写入/读取到tdb?

时间:2018-05-27 05:15:09

标签: rdf jena owl

我是Apache Jena的新手。我想写/读本体模型到tdb,所以写了一小段代码来测试它:

private static void basicOntology() {
    OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    m.setNsPrefix("graph", NS);
    OntClass thingClass = m.createClass(NS + "THING");
    thingClass.addComment("a", "b");
    OntClass klass = m.createClass(NS + "POI");
    klass.addSuperClass(thingClass);
    Dataset dataset = TDBFactory.createDataset("/tmp/someThings");
    dataset.begin(ReadWrite.WRITE);
    dataset.addNamedModel("ontology", m);
    dataset.commit();
}

但它给了我这个异常堆栈:

Exception in thread "main" java.lang.NullPointerException
at org.apache.jena.tdb.store.DatasetPrefixesTDB.readPrefix(DatasetPrefixesTDB.java:86)
at org.apache.jena.sparql.graph.GraphPrefixesProjection.get(GraphPrefixesProjection.java:101)
at org.apache.jena.sparql.graph.GraphPrefixesProjection.set(GraphPrefixesProjection.java:79)
at org.apache.jena.shared.impl.PrefixMappingImpl.setNsPrefix(PrefixMappingImpl.java:75)
at org.apache.jena.shared.impl.PrefixMappingImpl.setNsPrefixes(PrefixMappingImpl.java:163)
at org.apache.jena.shared.impl.PrefixMappingImpl.setNsPrefixes(PrefixMappingImpl.java:130)
at org.apache.jena.graph.GraphUtil.addInto(GraphUtil.java:137)
at org.apache.jena.sparql.core.DatasetGraphTriplesQuads.addGraph(DatasetGraphTriplesQuads.java:80)
at org.apache.jena.sparql.core.DatasetGraphWrapper.addGraph(DatasetGraphWrapper.java:94)
at org.apache.jena.sparql.core.DatasetImpl.addNamedModel(DatasetImpl.java:158)
at com.sankuai.ai.kg.jena.Main.basicOntology(Main.java:31)
at com.sankuai.ai.kg.jena.Main.main(Main.java:19)

0 个答案:

没有答案