Reputation: 19
I tried to save my ontology as NTriples format using owlapi. This error appear when I try to save my ontology:
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)
And the code that referenced in error is:
NTriplesDocumentFormat nTriplesFormat = new NTriplesDocumentFormat();
try {
ontologyManager.saveOntology(ontologyInferred, nTriplesFormat, IRI.create(file.toURI()));
} catch (OWLOntologyStorageException e) {
e.printStackTrace();
}
The ontology:
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> )
The reflexsive sameAs axiom result of inferrencing based on OWL 2 RL/RDF rules eq-ref
If: T(?s, ?p, ?o) then: T(?s, owl:sameAs, ?s)
SameIndividual(http://www.example.com/individual/eq#PB )
The inferencing code:
result.add(dataFactory.getOWLSameIndividualAxiom(individual, individual));
I can save my ontology as OWLXMLFormat, but since I am building a dataset that need in triple form. Is there any solution to save it in any triple form?
Other Format already tried and error:
NTriplesDocumentFormat nTriplesFormat = new NTriplesDocumentFormat();
N3DocumentFormat n3Format = new N3DocumentFormat();
TrigDocumentFormat trigFormat = new TrigDocumentFormat();
TurtleDocumentFormat turtleFormat = new TurtleDocumentFormat();
RioTurtleDocumentFormat rioFormat = new RioTurtleDocumentFormat();
Edit:
The full inferrence code:
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)";
}
}
Upvotes: 0
Views: 246
Reputation: 835
As a workaround ONT-API could be used.
Since ONTAPI is a RDF-centric OWLAPI implementation, there must be no problem with any RDF-serialization (by default there is a substitution of OWLAPI formats with Jena alternatives).
But, axiom SameIndividual(x, x)
is still illegal, and to create such construction need to switch to RDF API.
Example:
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);
Output:
<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> .
Upvotes: 0
Reputation: 10684
The exception is a bug (please report it, as recommended in the comment), however note that those are not legal OWL axioms. The syntax and semantic specification shows sameAs as requiring two arguments at least.
(Consider that the axiom is supposed to allow definition of synonym individuals; one argument only offers no new information)
If the axioms are generated by an inferred axiom generator, looks like that code has a bug as well.
Upvotes: 0