Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Owlapi keep all unsupported axioms #217

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@
*/
public class OwlToRulesConverter {

/**
* The default value for the maximum number of unssuported axioms to be
* registered during the conversion.
*/
public static final Integer DEFAULT_LIMIT_UNSUPPORTED_AXIOMS_SIZE = 10;

private static Logger LOGGER = LoggerFactory.getLogger(OwlToRulesConverter.class);

final OwlAxiomToRulesConverter owlAxiomToRulesConverter = new OwlAxiomToRulesConverter();

private final boolean failOnUnsupported;
private final List<OWLAxiom> unsupportedAxiomsSample = new ArrayList<>(DEFAULT_LIMIT_UNSUPPORTED_AXIOMS_SIZE);
private int unsupportedAxiomsCount = 0;
private final List<OWLAxiom> unsupportedAxioms = new ArrayList<>();
private Integer limitUnsupportedAxiomsSize = DEFAULT_LIMIT_UNSUPPORTED_AXIOMS_SIZE;

/**
* Constructor.
Expand All @@ -56,7 +63,7 @@ public class OwlToRulesConverter {
* encountering axioms that cannot be converted to
* rules or facts.
*/
public OwlToRulesConverter(boolean failOnUnsupported) {
public OwlToRulesConverter(final boolean failOnUnsupported) {
this.failOnUnsupported = failOnUnsupported;
}

Expand All @@ -80,15 +87,16 @@ public void addOntology(final OWLOntology owlOntology) {
owlOntology.axioms().forEach(owlAxiom -> {
try {
owlAxiom.accept(this.owlAxiomToRulesConverter);
} catch (OwlFeatureNotSupportedException e) {
} catch (final OwlFeatureNotSupportedException e) {
if (this.failOnUnsupported) {
LOGGER.error(e.getMessage());
throw e;
} else {
LOGGER.warn(e.getMessage());
this.unsupportedAxiomsCount++;
if (this.unsupportedAxioms.size() < 10) {
this.unsupportedAxioms.add(owlAxiom);
if (this.limitUnsupportedAxiomsSize == null
|| this.unsupportedAxiomsSample.size() < this.limitUnsupportedAxiomsSize) {
this.unsupportedAxiomsSample.add(owlAxiom);
}
}
}
Expand Down Expand Up @@ -129,14 +137,40 @@ public int getUnsupportedAxiomsCount() {
}

/**
* Returns up to 10 unsupported axioms encountered during the conversion. The
* complete number of unsupported axioms can be queried using
* {@link #getUnsupportedAxiomsCount()}.
* Returns up to {@link #getLimitUnsupportedAxiomsSize()} unsupported axioms
* encountered during the conversion. If
* {@link #getLimitUnsupportedAxiomsSize()} is {@code null}, then it returns all
* unsupported axioms encountered during the translation. The complete number of
* unsupported axioms can be queried using {@link #getUnsupportedAxiomsCount()}.
*
* @return list of first ten unsupported axioms that were encountered
*/
public List<OWLAxiom> getUnsupportedAxiomsSample() {
return this.unsupportedAxioms;
return this.unsupportedAxiomsSample;
}

/**
* Sets the maximum number of unsupported axioms to be registered during
* conversion. The default value is 10 (see
* {@link DEFAULT_LIMIT_UNSUPPORTED_AXIOMS_SIZE}). If set to {@code null}, all
* unsupported axioms encountered during conversion are saved.
*
* @param maxUnsupportedAxiomsSize
*/
public void setLimitUnsupportedAxiomsSize(final Integer maxUnsupportedAxiomsSize) {
this.limitUnsupportedAxiomsSize = maxUnsupportedAxiomsSize;
}

/**
* Getter for the maximum number of unsupported axioms to be registered during
* conversion. The default value is 10 (see
* {@link DEFAULT_LIMIT_UNSUPPORTED_AXIOMS_SIZE}). If set to {@code null}, all
* unsupported axioms encountered during conversion are saved.
*
* @return
*/
public Integer getLimitUnsupportedAxiomsSize() {
return this.limitUnsupportedAxiomsSize;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ public void testObjectPropertyRange() {
@Test(expected = OwlFeatureNotSupportedException.class)
public void testSubClassOfMaxCardinality() {

OWLClassExpression maxCard = df.getOWLObjectMaxCardinality(1, pR);
OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(cA, maxCard);
final OWLClassExpression maxCard = df.getOWLObjectMaxCardinality(1, pR);
final OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(cA, maxCard);

final OwlAxiomToRulesConverter converter = new OwlAxiomToRulesConverter();
axiom.accept(converter);
Expand Down Expand Up @@ -974,8 +974,8 @@ public void testNominalSubClassOfClass() {
*/
@Test
public void testNominalsSubClassOfClass() {
OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(oneOfab, cA);
final OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
final OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(oneOfab, cA);

final OwlAxiomToRulesConverter converter = new OwlAxiomToRulesConverter();
axiom.accept(converter);
Expand All @@ -993,9 +993,9 @@ public void testNominalsSubClassOfClass() {
@Test(expected = OwlFeatureNotSupportedException.class)
// TODO support this feature
public void testNominalsInConjunctionLeftSubClassOfClass() {
OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
OWLObjectIntersectionOf conjunction = df.getOWLObjectIntersectionOf(oneOfab, cB);
OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(conjunction, cA);
final OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
final OWLObjectIntersectionOf conjunction = df.getOWLObjectIntersectionOf(oneOfab, cB);
final OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(conjunction, cA);

final OwlAxiomToRulesConverter converter = new OwlAxiomToRulesConverter();
axiom.accept(converter);
Expand All @@ -1007,9 +1007,9 @@ public void testNominalsInConjunctionLeftSubClassOfClass() {
@Test(expected = OwlFeatureNotSupportedException.class)
// TODO support this feature
public void testNominalsInConjunctionRightSubClassOfClass() {
OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
OWLObjectIntersectionOf conjunction = df.getOWLObjectIntersectionOf(cB, oneOfab);
OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(conjunction, cA);
final OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
final OWLObjectIntersectionOf conjunction = df.getOWLObjectIntersectionOf(cB, oneOfab);
final OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(conjunction, cA);

final OwlAxiomToRulesConverter converter = new OwlAxiomToRulesConverter();
axiom.accept(converter);
Expand All @@ -1020,9 +1020,9 @@ public void testNominalsInConjunctionRightSubClassOfClass() {
*/
@Test(expected = OwlFeatureNotSupportedException.class)
public void testClassSubClassOfNominalsInConjunctionRight() {
OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
OWLObjectIntersectionOf conjunction = df.getOWLObjectIntersectionOf(cB, oneOfab);
OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(cA, conjunction);
final OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
final OWLObjectIntersectionOf conjunction = df.getOWLObjectIntersectionOf(cB, oneOfab);
final OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(cA, conjunction);

final OwlAxiomToRulesConverter converter = new OwlAxiomToRulesConverter();
axiom.accept(converter);
Expand All @@ -1033,8 +1033,8 @@ public void testClassSubClassOfNominalsInConjunctionRight() {
*/
@Test(expected = OwlFeatureNotSupportedException.class)
public void testNominalSuperClassOfClass() {
OWLObjectOneOf oneOfa = df.getOWLObjectOneOf(inda);
OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(cA, oneOfa);
final OWLObjectOneOf oneOfa = df.getOWLObjectOneOf(inda);
final OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(cA, oneOfa);

final OwlAxiomToRulesConverter converter = new OwlAxiomToRulesConverter();
axiom.accept(converter);
Expand All @@ -1045,8 +1045,8 @@ public void testNominalSuperClassOfClass() {
*/
@Test(expected = OwlFeatureNotSupportedException.class)
public void testNominalsSuperClassOfClass() {
OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(cA, oneOfab);
final OWLObjectOneOf oneOfab = df.getOWLObjectOneOf(inda, indb);
final OWLSubClassOfAxiom axiom = df.getOWLSubClassOfAxiom(cA, oneOfab);

final OwlAxiomToRulesConverter converter = new OwlAxiomToRulesConverter();
axiom.accept(converter);
Expand All @@ -1069,5 +1069,4 @@ public void test() {
System.out.println(rule);
}
}

}