Skip to content

Commit

Permalink
Fix Annotations on DifferentIndividualsAxioms lost #816
Browse files Browse the repository at this point in the history
Errors and missing rendering/parsing for annotations on three-argument
different/same individuals. Missng roundtrip tests.
  • Loading branch information
ignazio1977 committed May 20, 2022
1 parent 5c031b5 commit a7e81ef
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 107 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import static org.semanticweb.owlapi.api.test.TestEntities.P;
import static org.semanticweb.owlapi.api.test.TestEntities.Q;
import static org.semanticweb.owlapi.api.test.TestEntities.R;
import static org.semanticweb.owlapi.api.test.TestEntities.i;
import static org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.AsymmetricObjectProperty;
import static org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.ClassAssertion;
import static org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.DataPropertyAssertion;
import static org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.DataPropertyDomain;
import static org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.DataPropertyRange;
import static org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.DifferentIndividuals;
import static org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.DisjointClasses;
import static org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.DisjointDataProperties;
import static org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.DisjointObjectProperties;
Expand Down Expand Up @@ -91,6 +93,8 @@ public static List<Function<List<OWLAnnotation>, OWLAxiom>> getData() {
a -> ObjectPropertyDomain(P, A, a), a -> ObjectPropertyRange(P, A, a), a -> ReflexiveObjectProperty(P, a),
a -> df.getOWLSubClassOfAxiom(A, B, a), a -> SubDataPropertyOf(DP, DQ, a),
a -> SubObjectPropertyOf(P, Q, a), a -> SymmetricObjectProperty(P, a), a -> TransitiveObjectProperty(P, a),
a -> SubPropertyChainOf(Arrays.asList(P, Q), R, a));
a -> SubPropertyChainOf(Arrays.asList(P, Q), R, a), a -> DifferentIndividuals(Arrays.asList(i, I, J), a),
a -> DifferentIndividuals(Arrays.asList(I, J), a), a -> DifferentIndividuals(Arrays.asList(i, I, J), a),
a -> DifferentIndividuals(Arrays.asList(I, J), a));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,6 @@ private void initialiseIndividualFrameSections() {
initialiseSection(new AnnAxiom<>(this::parseFact, FACTS, (s, o, anns) -> o.getAnnotatedAxiom(anns)), individualFrames);
initialiseSection(new AnnAxiom<OWLIndividual, OWLIndividual>(x -> parseIndividual(), SAME_AS, (s, o, anns) -> df.getOWLSameIndividualAxiom(s, o, anns)), individualFrames);
initialiseSection(new AnnAxiom<OWLIndividual, OWLIndividual>(x -> parseIndividual(), DIFFERENT_FROM, (s, o, anns) -> df.getOWLDifferentIndividualsAxiom(s, o, anns)), individualFrames);
// Extensions
initialiseSection(new AnnAxiom<OWLIndividual, Set<OWLIndividual>>(x -> parseIndividualList(), DIFFERENT_INDIVIDUALS, (s, o, anns) -> create(df, s, o, anns)), individualFrames);
//@formatter:on
}

Expand Down Expand Up @@ -1762,9 +1760,9 @@ private Set<OntologyAxiomPair> parseSameIndividual() {
if (!SAME_INDIVIDUAL.matches(section)) {
throw new ExceptionBuilder().withKeyword(SAME_INDIVIDUAL).build();
}
Set<OWLIndividual> individuals = parseIndividualList();
Set<OWLOntology> ontologies = getOntologies();
Set<OWLAnnotation> annotations = parseAnnotations();
Set<OWLIndividual> individuals = parseIndividualList();
Set<OntologyAxiomPair> pairs = new HashSet<>();
for (OWLOntology ont : ontologies) {
pairs.add(new OntologyAxiomPair(ont, df.getOWLSameIndividualAxiom(individuals, annotations)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import static org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax.REFLEXIVE;
import static org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax.RULE;
import static org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax.SAME_AS;
import static org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax.SAME_INDIVIDUAL;
import static org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax.SUBCLASS_OF;
import static org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax.SUB_PROPERTY_CHAIN;
import static org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax.SUB_PROPERTY_OF;
Expand Down Expand Up @@ -294,12 +295,25 @@ public void writeOntology() throws OWLOntologyStorageException {
.forEach(ax -> writeMoreThanTwo(ax, ax.getOperandsAsList(), EQUIVALENT_PROPERTIES));
// Nary different individuals
o.axioms(AxiomType.DIFFERENT_INDIVIDUALS).sorted(ooc)
.forEach(ax -> writeMoreThanTwo(ax, ax.getOperandsAsList(), DIFFERENT_INDIVIDUALS));
.forEach(ax -> writeMoreThanTwo(ax, ax.getOperandsAsList(), DIFFERENT_INDIVIDUALS, true));
// Nary same individuals
o.axioms(AxiomType.SAME_INDIVIDUAL).sorted(ooc)
.forEach(ax -> writeMoreThanTwo(ax, ax.getOperandsAsList(), SAME_INDIVIDUAL, true));
o.axioms(AxiomType.SWRL_RULE).sorted(ooc)
.forEach(rule -> writeSection(RULE, Collections.singleton(rule).iterator(), ", ", false));
flush();
}

protected <T> void writeMoreThanTwo(OWLAxiom ax, List<T> individuals, ManchesterOWLSyntax section,
boolean writeTwoIfAnnotated) {
if (individuals.size() > 2
|| writeTwoIfAnnotated && individuals.size() == 2 && !ax.annotationsAsList().isEmpty()) {
SectionMap<Object, OWLAxiom> map = new SectionMap<>();
map.put(individuals, ax);
writeSection(section, map, ",", false);
}
}

protected <T> void writeMoreThanTwo(OWLAxiom ax, List<T> individuals, ManchesterOWLSyntax section) {
if (individuals.size() > 2) {
SectionMap<Object, OWLAxiom> map = new SectionMap<>();
Expand Down Expand Up @@ -764,8 +778,10 @@ public Collection<OWLAxiom> write(OWLIndividual individual) {
if (!isFiltered(AxiomType.SAME_INDIVIDUAL)) {
Collection<OWLIndividual> inds = sortedCollection();
filtersort(o.sameIndividualAxioms(individual)).forEach(ax -> {
add(inds, ax.individuals());
axioms.add(ax);
if (ax.getOperandsAsList().size() == 2 && ax.annotationsAsList().isEmpty()) {
add(inds, ax.individuals());
axioms.add(ax);
}
});
inds.remove(individual);
writeSection(SAME_AS, inds.iterator(), ",", true);
Expand All @@ -774,7 +790,7 @@ public Collection<OWLAxiom> write(OWLIndividual individual) {
Collection<OWLIndividual> inds = sortedCollection();
Collection<OWLDifferentIndividualsAxiom> nary = sortedCollection();
filtersort(o.differentIndividualAxioms(individual)).forEach(ax -> {
if (ax.getOperandsAsList().size() == 2) {
if (ax.getOperandsAsList().size() == 2 && ax.annotationsAsList().isEmpty()) {
add(inds, ax.individuals());
axioms.add(ax);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ public void visit(OWLHasKeyAxiom axiom) {

@Override
public void visit(OWLSameIndividualAxiom axiom) {
addPairwise(axiom, axiom.individuals(), OWL_SAME_AS.getIRI());
axiom.splitToAnnotatedPairs().forEach(a -> addSingleTripleAxiom(a, a.getOperandsAsList().get(0),
OWL_SAME_AS.getIRI(), a.getOperandsAsList().get(1)));
processIfAnonymous(axiom.individuals(), axiom);
}

Expand All @@ -671,6 +672,7 @@ public void visit(OWLDifferentIndividualsAxiom axiom) {
translateAnonymousNode(axiom);
addTriple(axiom, RDF_TYPE.getIRI(), OWL_ALL_DIFFERENT.getIRI());
addListTriples(axiom, OWL_DISTINCT_MEMBERS.getIRI(), axiom.individuals());
translateAnnotations(axiom);
processIfAnonymous(axiom.individuals(), axiom);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,8 @@ protected boolean canHandleAllDifferent(IRI s) {
protected boolean handleAllDifferentTriple(IRI s, IRI p, IRI o) {
IRI listNode = object(s, OWL_MEMBERS, OWL_DISTINCT_MEMBERS);
if (listNode != null) {
List<OWLAnnotation> annotations = pendingAnns(s);
pendingAnnotations.addAll(annotations);
add(df.getOWLDifferentIndividualsAxiom(individuals(listNode), pendingAnns()));
return tripleIndex.consumeTriple(s, p, o);
}
Expand Down

0 comments on commit a7e81ef

Please sign in to comment.