Skip to content

Commit

Permalink
Use lambda expressions and streams in normalization rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Mendez committed Dec 13, 2015
1 parent 269bbb2 commit c3f6bb3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,22 @@ private Set<IntegerAxiom> applyRule(Set<IntegerClassExpression> operands, Intege
Set<Annotation> annotations) {
Set<IntegerAxiom> ret = new HashSet<>();
Set<IntegerClassExpression> newOperands = new HashSet<>();
boolean applied = false;
for (IntegerClassExpression classExpression : operands) {
boolean[] applied = new boolean[1];
applied[0] = false;
operands.forEach(classExpression -> {
if (classExpression.isLiteral()) {
newOperands.add(classExpression);
} else {
applied = true;
applied[0] = true;
IntegerClass newClass = getOntologyObjectFactory().getDataTypeFactory()
.createClass(getOntologyObjectFactory().getEntityManager()
.createAnonymousEntity(IntegerEntityType.CLASS, true));
ret.add(getOntologyObjectFactory().getComplexAxiomFactory().createSubClassOfAxiom(classExpression,
newClass, annotations));
newOperands.add(newClass);
}
}
if (applied) {
});
if (applied[0]) {
IntegerObjectIntersectionOf newIntersection = getOntologyObjectFactory().getDataTypeFactory()
.createObjectIntersectionOf(newOperands);
ret.add(getOntologyObjectFactory().getComplexAxiomFactory().createSubClassOfAxiom(newIntersection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

import de.tudresden.inf.lat.jcel.coreontology.axiom.Annotation;
Expand Down Expand Up @@ -123,13 +124,10 @@ private Set<IntegerAxiom> applyRule(IntegerSubClassOfAxiom classAxiom) {
private Set<IntegerAxiom> applyRule(Set<IntegerClassExpression> operands, IntegerClassExpression superClass,
Set<Annotation> annotations) {
Set<IntegerAxiom> ret = new HashSet<>();
IntegerClassExpression aLiteral = null;
for (IntegerClassExpression op : operands) {
if (op.isLiteral()) {
aLiteral = op;
}
}
if (aLiteral != null) {
Optional<IntegerClassExpression> optional = operands.stream().filter(op -> op.isLiteral()).findAny();

if (optional.isPresent()) {
IntegerClassExpression aLiteral = optional.get();
IntegerClass newClass = getOntologyObjectFactory().getDataTypeFactory().createClass(
getOntologyObjectFactory().getEntityManager().createAnonymousEntity(IntegerEntityType.CLASS, true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,16 @@ public Set<IntegerAxiom> apply(IntegerAxiom axiom) {
}

private Set<IntegerAxiom> applyRule(IntegerSubClassOfAxiom classAxiom) {
Set<IntegerAxiom> ret = Collections.emptySet();
Set<IntegerAxiom> ret = new HashSet<>();
IntegerClassExpression subClass = classAxiom.getSubClass();
IntegerClassExpression superClass = classAxiom.getSuperClass();
if (superClass instanceof IntegerObjectIntersectionOf) {
IntegerObjectIntersectionOf intersection = (IntegerObjectIntersectionOf) superClass;
ret = new HashSet<>();
Set<IntegerClassExpression> operands = intersection.getOperands();
for (IntegerClassExpression operand : operands) {
operands.forEach(operand -> {
ret.add(getOntologyObjectFactory().getComplexAxiomFactory().createSubClassOfAxiom(subClass, operand,
classAxiom.getAnnotations()));
}
});
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
Expand Down Expand Up @@ -83,13 +82,12 @@ public Set<IntegerAxiom> apply(IntegerAxiom axiom) {
throw new IllegalArgumentException("Null argument.");
}

Set<IntegerAxiom> ret = Collections.emptySet();
Set<IntegerAxiom> ret = new HashSet<>();
if (axiom instanceof IntegerSubClassOfAxiom) {
ret = new HashSet<>();
Collection<NormalizedIntegerAxiom> normalizedAxioms = simplify((IntegerSubClassOfAxiom) axiom);
for (NormalizedIntegerAxiom normalizedAxiom : normalizedAxioms) {
normalizedAxioms.forEach(normalizedAxiom -> {
ret.add(normalizedAxiom);
}
});
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -80,13 +79,12 @@ public Set<IntegerAxiom> apply(IntegerAxiom axiom) {
throw new IllegalArgumentException("Null argument.");
}

Set<IntegerAxiom> ret = Collections.emptySet();
Set<IntegerAxiom> ret = new HashSet<>();
if (axiom instanceof IntegerSubPropertyChainOfAxiom) {
ret = new HashSet<>();
Collection<NormalizedIntegerAxiom> normalizedAxioms = simplify((IntegerSubPropertyChainOfAxiom) axiom);
for (NormalizedIntegerAxiom normalizedAxiom : normalizedAxioms) {
normalizedAxioms.forEach(normalizedAxiom -> {
ret.add(normalizedAxiom);
}
});
}
return ret;
}
Expand Down

0 comments on commit c3f6bb3

Please sign in to comment.