我试图使用owlapi将我的本体保存为NTriples格式。当我试图保存我的本体时会出现这个错误:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:373)
at java.base/java.util.ArrayList.get(ArrayList.java:426)
at java.base/java.util.Collections$UnmodifiableList.get(Collections.java:1321)
at java.base/java.util.Collections$UnmodifiableList.get(Collections.java:1321)
at org.semanticweb.owlapi.rdf.model.AbstractTranslator.lambda$visit$3(AbstractTranslator.java:710)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.semanticweb.owlapi.rdf.model.AbstractTranslator.visit(AbstractTranslator.java:709)
at org.semanticweb.owlapi.model.OWLSameIndividualAxiom.accept(OWLSameIndividualAxiom.java:51)
at org.semanticweb.owlapi.rdf.model.AbstractTranslator.translate(AbstractTranslator.java:288)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1624)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
at org.semanticweb.owlapi.rdf.RDFRendererBase.createGraph(RDFRendererBase.java:484)
at org.semanticweb.owlapi.rdf.RDFRendererBase.createGraph(RDFRendererBase.java:471)
at org.semanticweb.owlapi.rdf.RDFRendererBase.lambda$renderEntities$5(RDFRendererBase.java:294)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
at java.base/java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:1002)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
at org.semanticweb.owlapi.rdf.RDFRendererBase.renderEntities(RDFRendererBase.java:295)
at org.semanticweb.owlapi.rdf.RDFRendererBase.renderInOntologySignatureEntities(RDFRendererBase.java:280)
at org.semanticweb.owlapi.rdf.RDFRendererBase.renderOntologyComponents(RDFRendererBase.java:263)
at org.semanticweb.owlapi.rdf.RDFRendererBase.render(RDFRendererBase.java:258)
at org.semanticweb.owlapi.rio.RioStorer.storeOntology(RioStorer.java:230)
at org.semanticweb.owlapi.util.AbstractOWLStorer.store(AbstractOWLStorer.java:85)
at org.semanticweb.owlapi.util.AbstractOWLStorer.storeOntology(AbstractOWLStorer.java:72)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:1324)
at preprocess.PositiveInference.inferringSemanticsofEquality(PositiveInference.java:117)
at preprocess.PositiveInference.inferencing(PositiveInference.java:85)
at preprocess.PositiveInference.main(PositiveInference.java:65)
错误引用的代码是:
NTriplesDocumentFormat nTriplesFormat = new NTriplesDocumentFormat();
try {
ontologyManager.saveOntology(ontologyInferred, nTriplesFormat, IRI.create(file.toURI()));
} catch (OWLOntologyStorageException e) {
e.printStackTrace();
}
本体论:
SameIndividual(<http://www.example.com/individual/eq#PB> )
SameIndividual(<http://www.example.com/individual/eq#transY> )
SameIndividual(<http://www.example.com/individual/eq#symX> )
SameIndividual(<http://www.example.com/individual/eq#OC> )
SameIndividual(<http://www.example.com/individual/eq#transZ> )
SameIndividual(<http://www.example.com/individual/eq#SAA> )
SameIndividual(<http://www.example.com/individual/eq#transX> )
SameIndividual(<http://www.example.com/individual/eq#OAC> )
SameIndividual(<http://www.example.com/individual/eq#refO> )
SameIndividual(<http://www.example.com/individual/eq#refS> )
SameIndividual(<http://www.example.com/individual/eq#SA> )
SameIndividual(<http://www.example.com/individual/eq#PAB> )
SameIndividual(<http://www.example.com/individual/eq#transX> <http://www.example.com/individual/eq#transY> <http://www.example.com/individual/eq#transZ> )
SameIndividual(<http://www.example.com/individual/eq#symY> )
基于OWL2RL/RDF规则eq-ref-推理的反射sameAs公理结果
如果:T(?s,?p,?o(则:T((?s(owl:sameAs,?s(
SameIndividual(http://www.example.com/individual/eq#PB(
推理代码:
result.add(dataFactory.getOWLSameIndividualAxiom(individual, individual));
我可以将我的本体保存为OWLXMLFormat,但由于我正在构建一个需要三重形式的数据集。有什么解决方案可以将其保存为任何三重形式吗?
其他格式已尝试并出错:
NTriplesDocumentFormat nTriplesFormat = new NTriplesDocumentFormat();
N3DocumentFormat n3Format = new N3DocumentFormat();
TrigDocumentFormat trigFormat = new TrigDocumentFormat();
TurtleDocumentFormat turtleFormat = new TurtleDocumentFormat();
RioTurtleDocumentFormat rioFormat = new RioTurtleDocumentFormat();
编辑:
完整的推断代码:
public class InferredSameIndividualAxiomGenerator extends InferredIndividualAxiomGenerator<OWLSameIndividualAxiom>{
@Override
protected void addAxioms(OWLNamedIndividual entity, OWLReasoner reasoner, OWLDataFactory dataFactory, Set<OWLSameIndividualAxiom> result) {
Set<OWLNamedIndividual> sameIndividuals = asUnorderedSet(reasoner.getSameIndividuals(entity).entities());
sameIndividuals.add(entity);
result.add(dataFactory.getOWLSameIndividualAxiom(entity, entity));
if (sameIndividuals.size() > 1)
result.add(dataFactory.getOWLSameIndividualAxiom(sameIndividuals));
}
@Override
public String getLabel() {
return "Same Individuals T(?x, owl:sameAs, ?y)";
}
}
作为一种解决方法,可以使用ONT-API
由于ONTAPI是一个以RDF为中心的OWLAPI实现,因此任何RDF序列化都不会有问题(默认情况下,OWLAPI格式会被Jena替代(
但是,公理SameIndividual(x, x)
仍然是非法的,创建这样的构造需要切换到RDFneneneba API。
示例:
OWLOntologyManager m = OntManagers.createManager();
OWLOntology ont = m.createOntology();
String i = "http://i";
OntModel g = ((Ontology) ont).asGraphModel();
g.createIndividual(i).addSameIndividual(g.createIndividual(i));
ont.saveOntology(new NTriplesDocumentFormat(), System.out);
输出:
<http://i> <http://www.w3.org/2002/07/owl#sameAs> <http://i> .
<http://i> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
_:B0ee0d3dfX2D1fe4X2D4489X2D9fc3X2De18bae6cfab4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Ontology> .
异常是一个错误(请按照注释中的建议报告(,但请注意,这些不是合法的OWL公理。语法和语义规范显示sameA至少需要两个参数。
(考虑到公理应该允许定义同义词个体;一个论点只提供了没有新信息(
如果公理是由推断的公理生成器生成的,那么看起来该代码也有一个错误。