Skip to content

Commit

Permalink
Fix Shared class expression causes extra triples in output #1109
Browse files Browse the repository at this point in the history
Defer check was on objects but not on lists, causing triple duplication.
  • Loading branch information
ignazio1977 committed Jan 14, 2024
1 parent 8dda5c8 commit d63b26b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDocumentFormat;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
import org.semanticweb.owlapi.model.OWLOntology;

class BlankNodeIdsAndAnnotationsRoundTripTestCase extends TestBase {
Expand Down Expand Up @@ -69,6 +70,16 @@ protected OWLOntology blankNodeIdsAndAnnotationsRoundTripTestCase(OWLOntology on
return ont1;
}

protected OWLOntology anonClassAndAnnotationsRoundTripTestCase(OWLOntology ont1) {
Set<OWLAnnotation> anns =
set(df.getOWLAnnotation(df.getRDFSComment(), df.getOWLLiteral("comment")));
OWLClassExpression restrict = df.getOWLObjectSomeValuesFrom(R, B);
OWLObjectIntersectionOf intersect = df.getOWLObjectIntersectionOf(C, restrict);
ont1.getOWLOntologyManager().addAxiom(ont1, df.getOWLEquivalentClassesAxiom(A, intersect));
ont1.getOWLOntologyManager().addAxiom(ont1, df.getOWLSubClassOfAxiom(A, restrict, anns));
return ont1;
}

@Override
public boolean equal(OWLOntology ont1, OWLOntology ont2) {
// Axioms without annotations are lost if identical axioms with
Expand All @@ -94,6 +105,12 @@ void testFormat(OWLDocumentFormat format) {
roundTripOntology(blankNodeIdsAndAnnotationsRoundTripTestCase(createAnon()), format);
}

@ParameterizedTest
@MethodSource("formats")
void testFormat1(OWLDocumentFormat format) {
roundTripOntology(anonClassAndAnnotationsRoundTripTestCase(createAnon()), format);
}

@Test
void roundTripRDFXMLAndFunctionalShouldBeSame() {
OWLOntology o = blankNodeIdsAndAnnotationsRoundTripTestCase(createAnon());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.semanticweb.owlapi.vocab.OWLRDFVocabulary.RDF_DESCRIPTION;
import static org.semanticweb.owlapi.vocab.OWLRDFVocabulary.RDF_TYPE;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -246,7 +247,16 @@ protected void render(RDFResource node, boolean root) {

protected void renderList(RDFNode n) {
if (n.isAnonymous()) {
render((RDFResourceBlankNode) n, false);
if (n.idRequired()) {
if (!pending.contains(n)) {
defer(n);
}
writer.writeStartElement(RDF_DESCRIPTION.getIRI());
writer.writeNodeIDAttribute((RDFResourceBlankNode) n);
writer.writeEndElement();
} else {
render((RDFResourceBlankNode) n, false);
}
} else {
if (n.isLiteral()) {
write((RDFLiteral) n);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private void write(RDFResource node) {
writeSpace();
pushTab();
for (Iterator<RDFNode> it = list.iterator(); it.hasNext();) {
write(verifyNotNull(it.next()));
renderObject(verifyNotNull(it.next()));
if (it.hasNext()) {
writeNewLine();
}
Expand Down

0 comments on commit d63b26b

Please sign in to comment.