我正在尝试将一些人添加到我现有的本体(OntModel)中,目的是为 DatatypeProperty 添加值/文字,并在运行时从 datatypeproperty 的范围内知道特定的数据类型。我的 OntModel 由 TDBStore 支持,链接到数据集(因此对 OntModel 的任何更改都会反映回我的 TDBStore/数据集)。根据以下代码添加个人:
Individual ind =oc.createIndividual(namespace+nameOfIndividual); // oc is OntClass object
Literal l = ontModel.createTypedLiteral("1230",dp.getRange().getURI()); //dp is a DatatypeProperty object
ind.addLiteral(dp,l);
当代码执行时,会添加文字并进行 sparql 查询:
"SELECT * WHERE { ?s :ABCConstant ?o }"; //:ABCConstant is the datatypeProperty for which the literal is added by the above code.
给我以下结果:
------------------------------------------------------------------------------------------------------------------------------------------------
| s | o |
================================================================================================================================================
| <http://www.semanticweb.org/ontologies/2012/10/Ontology.owl#individual1ABCDConstant> | "10000.0"^^<http://www.w3.org/2001/XMLSchema#int> |
| <http://www.semanticweb.org/ontologies/2012/10/Ontology.owl#individual2ABCDConstant> | 1230 |
------------------------------------------------------------------------------------------------------------------------------------------------
但是当我尝试在第二次运行中使用相同的查询(这次没有创建任何个人)时,当程序尝试显示/访问结果时,我得到以下异常:
Exception in thread "main" com.hp.hpl.jena.tdb.base.file.FileException: ObjectFileStorage.read[nodes](181624)[filesize=248062][file.size()=248062]: Impossibly large object : 1634628966 bytes > filesize-(loc+SizeOfInt)=66434
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.triple(TupleLib.java:126)
at com.hp.hpl.jena.tdb.lib.TupleLib.triple(TupleLib.java:114)
at com.hp.hpl.jena.tdb.lib.TupleLib.access$000(TupleLib.java:45)
at com.hp.hpl.jena.tdb.lib.TupleLib$3.convert(TupleLib.java:76)
at com.hp.hpl.jena.tdb.lib.TupleLib$3.convert(TupleLib.java:72)
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$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.util.iterator.WrappedIterator.next(WrappedIterator.java:94)
at com.hp.hpl.jena.util.iterator.FilterIterator.hasNext(FilterIterator.java:55)
at com.hp.hpl.jena.graph.compose.CompositionBase$2.hasNext(CompositionBase.java:94)
at com.hp.hpl.jena.util.iterator.NiceIterator$1.hasNext(NiceIterator.java:103)
at com.hp.hpl.jena.util.iterator.WrappedIterator.hasNext(WrappedIterator.java:90)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIterTriplePattern$TripleMapper.hasNextBinding(QueryIterTriplePattern.java:151)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java:81)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIterBlockTriples.hasNextBinding(QueryIterBlockTriples.java:64)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.ResultSetStream.hasNext(ResultSetStream.java:75)
at com.hp.hpl.jena.sparql.resultset.ResultSetMem.<init>(ResultSetMem.java:97)
at com.hp.hpl.jena.query.ResultSetFactory.makeRewindable(ResultSetFactory.java:420)
at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:149)
at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:132)
at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:120)
at com.hp.hpl.jena.sparql.resultset.TextOutput.format(TextOutput.java:67)
at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:122)
at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:74)
at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:65)
at senseXploreApi.SparqlQuery.sparqlQuery(SparqlQuery.java:82)
at senseXploreApi.TryMain.main(TryMain.java:39)
注意:查看添加的个人的其他查询执行正常。但是像“SELECT * WHERE { ?s ?o 1230}”这样的查询会导致同样的错误。
也像这样查询:“SELECT * WHERE { ?s ?o 10000.0}”或“SELECT * WHERE { ?s ?o 10000}”不会给出任何错误,但不会返回任何结果。
文字 10000 是使用以下语句添加的:
ind.addLiteral(opp,new Integer(10000));
请帮我!!我在哪里错了.. 用于创建个人的程序是错误的吗?如果是!那么在运行时添加具有特定数据类型的文字还有其他可能的方法吗?