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 Jul 16, 2023
1 parent 10cf395 commit 0062ec4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDocumentFormat;
import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;

Expand Down Expand Up @@ -99,6 +100,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 @@ -124,6 +135,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 @@ -89,8 +89,8 @@ public RDFXMLRenderer(@Nonnull OWLOntology ontology, @Nonnull Writer w,
super(checkNotNull(ontology, "ontology cannot be null"),
checkNotNull(format, "format cannot be null"));
this.format = checkNotNull(format, "format cannot be null");
explicitXsdString = Boolean
.parseBoolean(format.getParameter("force xsd:string on literals", Boolean.FALSE).toString());
explicitXsdString = Boolean.parseBoolean(
format.getParameter("force xsd:string on literals", Boolean.FALSE).toString());
qnameManager = new RDFXMLNamespaceManager(ontology, format);
String defaultNamespace = qnameManager.getDefaultNamespace();
String base = base(defaultNamespace);
Expand Down Expand Up @@ -257,7 +257,16 @@ public void render(@Nonnull RDFResource node, boolean root) throws IOException {

protected void renderList(RDFNode n) throws IOException {
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(@Nonnull RDFResource node) throws IOException {
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 0062ec4

Please sign in to comment.