Skip to content

Commit 2d427b6

Browse files
committed
ont-api: fix SWRLObjectPropertyAtom#getSimplified() (issue #17), add tests + minor changes in several places (comments, tests)
1 parent 3492b63 commit 2d427b6

9 files changed

+188
-265
lines changed

src/main/java/com/github/owlcs/ontapi/internal/objects/ONTSWRLAtomImpl.java

+1-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package com.github.owlcs.ontapi.internal.objects;
1616

17-
import com.github.owlcs.ontapi.DataFactory;
1817
import com.github.owlcs.ontapi.OntApiException;
1918
import com.github.owlcs.ontapi.internal.ModelObjectFactory;
2019
import com.github.owlcs.ontapi.internal.ONTObject;
@@ -681,20 +680,7 @@ public OntSWRL.Atom.WithObjectProperty asRDFNode() {
681680
@FactoryAccessor
682681
@Override
683682
public SWRLObjectPropertyAtom getSimplified() {
684-
OWLObjectPropertyExpression p = getPredicate();
685-
OWLObjectPropertyExpression ps = p.getSimplified();
686-
if (ps.equals(p)) {
687-
return eraseModel();
688-
}
689-
// p always equals ps (v5.1.11) - so the following code just in case:
690-
DataFactory df = getDataFactory();
691-
ps = eraseModel(ps);
692-
SWRLIArgument f = eraseModel(getFirstArgument());
693-
SWRLIArgument s = eraseModel(getSecondArgument());
694-
if (ps.isAnonymous()) {
695-
return df.getSWRLObjectPropertyAtom(ps.getInverseProperty(), s, f);
696-
}
697-
return df.getSWRLObjectPropertyAtom(ps, f, s);
683+
return eraseModel().getSimplified();
698684
}
699685

700686
@Override

src/main/java/com/github/owlcs/ontapi/owlapi/axioms/OWLInverseFunctionalObjectPropertyAxiomImpl.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of the ONT API.
33
* The contents of this file are subject to the LGPL License, Version 3.0.
4-
* Copyright (c) 2019, The University of Manchester, owl.cs group.
4+
* Copyright (c) 2020, The University of Manchester, owl.cs group.
55
*
66
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
77
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
@@ -13,8 +13,8 @@
1313
*/
1414
package com.github.owlcs.ontapi.owlapi.axioms;
1515

16-
import org.semanticweb.owlapi.model.*;
1716
import com.github.owlcs.ontapi.owlapi.objects.ce.OWLObjectMaxCardinalityImpl;
17+
import org.semanticweb.owlapi.model.*;
1818

1919
import javax.annotation.Nonnull;
2020
import java.util.Collection;
@@ -50,13 +50,12 @@ public OWLInverseFunctionalObjectPropertyAxiomImpl getAxiomWithoutAnnotations()
5050
@SuppressWarnings("unchecked")
5151
@Override
5252
public <T extends OWLAxiom> T getAnnotatedAxiom(@Nonnull Stream<OWLAnnotation> anns) {
53-
return (T) new OWLInverseFunctionalObjectPropertyAxiomImpl(getProperty(),
54-
mergeAnnotations(this, anns));
53+
return (T) new OWLInverseFunctionalObjectPropertyAxiomImpl(getProperty(), mergeAnnotations(this, anns));
5554
}
5655

5756
@Override
5857
public OWLSubClassOfAxiom asOWLSubClassOfAxiom() {
59-
return new OWLSubClassOfAxiomImpl(OWL_THING, new OWLObjectMaxCardinalityImpl(getProperty().getInverseProperty()
60-
.getSimplified(), 1, OWL_THING), NO_ANNOTATIONS);
58+
return new OWLSubClassOfAxiomImpl(OWL_THING,
59+
new OWLObjectMaxCardinalityImpl(getProperty().getInverseProperty(), 1, OWL_THING), NO_ANNOTATIONS);
6160
}
6261
}

src/main/java/com/github/owlcs/ontapi/owlapi/axioms/OWLInverseObjectPropertiesAxiomImpl.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of the ONT API.
33
* The contents of this file are subject to the LGPL License, Version 3.0.
4-
* Copyright (c) 2019, The University of Manchester, owl.cs group.
4+
* Copyright (c) 2020, The University of Manchester, owl.cs group.
55
*
66
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
77
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
@@ -81,11 +81,9 @@ public OWLObjectPropertyExpression getSecondProperty() {
8181

8282
@Override
8383
public Collection<OWLSubObjectPropertyOfAxiom> asSubObjectPropertyOfAxioms() {
84-
Set<OWLSubObjectPropertyOfAxiom> axs = new HashSet<>();
85-
axs.add(new OWLSubObjectPropertyOfAxiomImpl(first,
86-
second.getInverseProperty().getSimplified(), NO_ANNOTATIONS));
87-
axs.add(new OWLSubObjectPropertyOfAxiomImpl(second,
88-
first.getInverseProperty().getSimplified(), NO_ANNOTATIONS));
89-
return axs;
84+
Set<OWLSubObjectPropertyOfAxiom> res = new HashSet<>();
85+
res.add(new OWLSubObjectPropertyOfAxiomImpl(first, second.getInverseProperty(), NO_ANNOTATIONS));
86+
res.add(new OWLSubObjectPropertyOfAxiomImpl(second, first.getInverseProperty(), NO_ANNOTATIONS));
87+
return res;
9088
}
9189
}

src/main/java/com/github/owlcs/ontapi/owlapi/axioms/OWLObjectPropertyAssertionAxiomImpl.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of the ONT API.
33
* The contents of this file are subject to the LGPL License, Version 3.0.
4-
* Copyright (c) 2019, The University of Manchester, owl.cs group.
4+
* Copyright (c) 2020, The University of Manchester, owl.cs group.
55
*
66
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
77
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
@@ -13,9 +13,9 @@
1313
*/
1414
package com.github.owlcs.ontapi.owlapi.axioms;
1515

16-
import org.semanticweb.owlapi.model.*;
1716
import com.github.owlcs.ontapi.owlapi.objects.ce.OWLObjectHasValueImpl;
1817
import com.github.owlcs.ontapi.owlapi.objects.ce.OWLObjectOneOfImpl;
18+
import org.semanticweb.owlapi.model.*;
1919

2020
import javax.annotation.Nonnull;
2121
import java.util.Collection;
@@ -67,11 +67,10 @@ public <T extends OWLAxiom> T getAnnotatedAxiom(@Nonnull Stream<OWLAnnotation> a
6767
public OWLObjectPropertyAssertionAxiom getSimplified() {
6868
if (!getProperty().isAnonymous()) {
6969
return this;
70-
} else {
71-
OWLObjectInverseOf property = (OWLObjectInverseOf) getProperty();
72-
OWLObjectPropertyExpression invProp = property.getInverse();
73-
return new OWLObjectPropertyAssertionAxiomImpl(getObject(), invProp, getSubject(), NO_ANNOTATIONS);
7470
}
71+
// OWL2 does not allow assertion with anonymous property in model,
72+
// but OWLDataFactory allows such constructions
73+
return new OWLObjectPropertyAssertionAxiomImpl(getObject(), getProperty().getNamedProperty(), getSubject(), NO_ANNOTATIONS);
7574
}
7675

7776
@Override

src/main/java/com/github/owlcs/ontapi/owlapi/axioms/OWLSymmetricObjectPropertyAxiomImpl.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of the ONT API.
33
* The contents of this file are subject to the LGPL License, Version 3.0.
4-
* Copyright (c) 2019, The University of Manchester, owl.cs group.
4+
* Copyright (c) 2020, The University of Manchester, owl.cs group.
55
*
66
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
77
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
@@ -39,11 +39,11 @@ public OWLSymmetricObjectPropertyAxiomImpl(OWLObjectPropertyExpression property,
3939

4040
@Override
4141
public Set<OWLSubObjectPropertyOfAxiom> asSubPropertyAxioms() {
42-
Set<OWLSubObjectPropertyOfAxiom> result = new HashSet<>(2);
42+
Set<OWLSubObjectPropertyOfAxiom> res = new HashSet<>(2);
4343
OWLObjectPropertyExpression p = getProperty();
44-
result.add(new OWLSubObjectPropertyOfAxiomImpl(p, p.getInverseProperty().getSimplified(), NO_ANNOTATIONS));
45-
result.add(new OWLSubObjectPropertyOfAxiomImpl(p.getInverseProperty().getSimplified(), p, NO_ANNOTATIONS));
46-
return result;
44+
res.add(new OWLSubObjectPropertyOfAxiomImpl(p, p.getInverseProperty(), NO_ANNOTATIONS));
45+
res.add(new OWLSubObjectPropertyOfAxiomImpl(p.getInverseProperty(), p, NO_ANNOTATIONS));
46+
return res;
4747
}
4848

4949
@SuppressWarnings("unchecked")

src/main/java/com/github/owlcs/ontapi/owlapi/objects/swrl/SWRLObjectPropertyAtomImpl.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of the ONT API.
33
* The contents of this file are subject to the LGPL License, Version 3.0.
4-
* Copyright (c) 2019, The University of Manchester, owl.cs group.
4+
* Copyright (c) 2020, The University of Manchester, owl.cs group.
55
*
66
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
77
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
@@ -40,15 +40,11 @@ public OWLObjectPropertyExpression getPredicate() {
4040

4141
@Override
4242
public SWRLObjectPropertyAtom getSimplified() {
43-
OWLObjectPropertyExpression prop = getPredicate().getSimplified();
44-
if (prop.equals(getPredicate())) {
43+
// See https://github.com/owlcs/ont-api/issues/17 & https://github.com/owlcs/owlapi/issues/882
44+
OWLObjectPropertyExpression p = getPredicate();
45+
if (p.isNamed()) {
4546
return this;
46-
} else if (prop.isAnonymous()) {
47-
// Flip
48-
return new SWRLObjectPropertyAtomImpl(prop.getInverseProperty().getSimplified(), getSecondArgument(), getFirstArgument());
49-
} else {
50-
// No need to flip
51-
return new SWRLObjectPropertyAtomImpl(prop, getFirstArgument(), getSecondArgument());
5247
}
48+
return new SWRLObjectPropertyAtomImpl(p.getInverseProperty(), getSecondArgument(), getFirstArgument());
5349
}
5450
}

src/test/java/com/github/owlcs/ontapi/tests/TestFactory.java

+23
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,29 @@ public OWLObject create(OWLDataFactory df) {
958958
return df.getSWRLRule(body, head, annotations);
959959
}
960960
}
961+
, new AxiomData() {
962+
@Override
963+
public AxiomType getType() {
964+
return AxiomType.SWRL_RULE;
965+
}
966+
967+
@Override
968+
public String toString() {
969+
// to test https://github.com/owlcs/ont-api/issues/17
970+
return "SWRLRule Axiom single object property atom";
971+
}
972+
973+
@Override
974+
public OWLObject create(OWLDataFactory df) {
975+
OWLObjectPropertyExpression p = df.getOWLObjectInverseOf(df.getOWLObjectProperty("P"));
976+
SWRLIArgument a1 = df.getSWRLVariable("V");
977+
SWRLIArgument a2 = df.getSWRLIndividualArgument(df.getOWLAnonymousIndividual("_:bx"));
978+
979+
List<? extends SWRLAtom> body = Collections.singletonList(df.getSWRLObjectPropertyAtom(p, a1, a2));
980+
List<? extends SWRLAtom> head = Collections.emptyList();
981+
return df.getSWRLRule(body, head);
982+
}
983+
}
961984
, new NamedRange() {
962985
@Override
963986
public OWLObject create(OWLDataFactory df) {

0 commit comments

Comments
 (0)