Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/julianmendez/jcel into us…
Browse files Browse the repository at this point in the history
…e-of-parallelism
  • Loading branch information
Julian Mendez committed Apr 18, 2016
2 parents 4e1ec92 + 0b2ae4e commit 911f8d4
Show file tree
Hide file tree
Showing 70 changed files with 968 additions and 178 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* uses the [OWL API](https://owlapi.sourceforge.net)
* can be used in [Protégé](http://protege.stanford.edu)
* is free software and is licensed under [GNU Lesser General Public License version 3](https://www.gnu.org/licenses/lgpl.txt) and [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt)
* is fully implemented in [Java](http://www.oracle.com/us/technologies/java/standard-edition/overview/index.html)
* is fully implemented in [Java](https://www.oracle.com/java/technologies/java-se.html)
* evaluated by the [SEALS Community](http://www.seals-project.eu/news/storage-and-reasoning-systems-news) having the lowest Average Reasoning Time in 2010


Expand Down
3 changes: 2 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

| version | release date | Java | OWL API | Protégé |
|:--------|:-------------|:----:|:--------------|:--------------|
| v0.24.0 | (unreleased) | 8 | 4.1.3 | 5.0.0-beta-21 |
| v0.24.0 | (unreleased) | 8 | 4.1.3 | 5.0.0-beta-23 |
| v0.23.2 | 2015-12-24 | 7 | 4.1.3 | 5.0.0-beta-21 |
| v0.23.1 | 2015-12-23 | 7 | 3.5.1 | 5.0.0-beta-17 |
| v0.23.0 | 2015-11-30 | 7 | 4.1.3 | 5.0.0-beta-21 |
Expand Down Expand Up @@ -36,6 +36,7 @@
### v0.24.0
*(unreleased)*
* runs on Java 8
* fixes module extractor
* build commands:
```
$ mvn clean install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Set<ExtensionEntry> getExistentialEntries(Integer propertyId, Integer cla
Objects.requireNonNull(classId);
Set<ExtensionEntry> ret = Collections.emptySet();
Map<Integer, Set<ExtensionEntry>> map = this.ohatOfExistential.get(propertyId);
if (!Objects.isNull(map)) {
if (Objects.nonNull(map)) {
ret = map.get(classId);
if (Objects.isNull(ret)) {
ret = Collections.emptySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public boolean isReady() {
}

private boolean isReflexiveTransitiveSubsumed(Integer leftPropertyName, Integer rightPropertyName) {
return !Objects.isNull(this.objectPropertyGraph)
return Objects.nonNull(this.objectPropertyGraph)
&& this.objectPropertyGraph.containsPair(leftPropertyName, rightPropertyName);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.tudresden.inf.lat.jcel.core.algorithm.module;

import java.util.Set;

import de.tudresden.inf.lat.jcel.coreontology.axiom.NormalizedIntegerAxiom;

/**
* This models a wrapper for a normalized axiom.
*
* @author Julian Mendez
*
*/
public interface ExtendedNormalizedAxiom {

/**
* Returns the normalized axiom.
*
* @return the normalized axiom
*/
NormalizedIntegerAxiom getAxiom();

/**
* Returns the class identifiers found on the left-hand side of the given
* axiom.
*
* @return the class identifiers found on the left-hand side of the given
* axiom
*/
Set<Integer> getClassesOnTheLeft();

/**
* Returns the class identifiers found on the right-hand side of the given
* axiom.
*
* @return the class identifiers found on the right-hand side of the given
* axiom
*/
Set<Integer> getClassesOnTheRight();

/**
* Returns the object property identifiers found on the left-hand side of
* the given axiom.
*
* @return the object property identifiers found on the left-hand side of
* the given axiom
*/
Set<Integer> getObjectPropertiesOnTheLeft();

/**
* Returns the object property found on the right-hand side of the given
* axiom.
*
* @return the object property identifiers found on the right-hand side of
* the given axiom
*/
Set<Integer> getObjectPropertiesOnTheRight();

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
package de.tudresden.inf.lat.jcel.core.algorithm.module;

import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

Expand All @@ -69,74 +70,80 @@
* @author Julian Mendez
*
*/
class IdentifierCollector {
public class ExtendedNormalizedAxiomImpl implements ExtendedNormalizedAxiom {

private Set<Integer> classesOnTheLeft = new TreeSet<>();
private Set<Integer> classesOnTheRight = new TreeSet<>();
private Set<Integer> objectPropertiesOnTheLeft = new TreeSet<>();
private Set<Integer> objectPropertiesOnTheRight = new TreeSet<>();
private final NormalizedIntegerAxiom axiom;
private final Set<Integer> classesOnTheLeft = new TreeSet<>();
private final Set<Integer> classesOnTheRight = new TreeSet<>();
private final Set<Integer> objectPropertiesOnTheLeft = new TreeSet<>();
private final Set<Integer> objectPropertiesOnTheRight = new TreeSet<>();

/**
* Constructs a new identifier collector.
*
* @param axiom
* normalized axiom
*/
public IdentifierCollector(NormalizedIntegerAxiom axiom) {
public ExtendedNormalizedAxiomImpl(NormalizedIntegerAxiom axiom) {
Objects.requireNonNull(axiom);
this.axiom = axiom;
axiom.accept(new AuxIdentifierCollector());
}

/**
* Returns the class identifiers found on the left-hand side of the given
* axiom.
*
* @return the class identifiers found on the left-hand side of the given
* axiom
*/
@Override
public NormalizedIntegerAxiom getAxiom() {
return this.axiom;
}

@Override
public Set<Integer> getClassesOnTheLeft() {
return Collections.unmodifiableSet(this.classesOnTheLeft);
}

/**
* Returns the class identifiers found on the right-hand side of the given
* axiom.
*
* @return the class identifiers found on the right-hand side of the given
* axiom
*/
@Override
public Set<Integer> getClassesOnTheRight() {
return Collections.unmodifiableSet(this.classesOnTheRight);
}

/**
* Returns the object property identifiers found on the left-hand side of
* the given axiom.
*
* @return the object property identifiers found on the left-hand side of
* the given axiom
*/
@Override
public Set<Integer> getObjectPropertiesOnTheLeft() {
return Collections.unmodifiableSet(this.objectPropertiesOnTheLeft);
}

/**
* Returns the object property found on the right-hand side of the given
* axiom.
*
* @return the object property identifiers found on the right-hand side of
* the given axiom
*/
@Override
public Set<Integer> getObjectPropertiesOnTheRight() {
return Collections.unmodifiableSet(this.objectPropertiesOnTheRight);
}

@Override
public int hashCode() {
return this.axiom.hashCode();
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof ExtendedNormalizedAxiomImpl)) {
return false;
} else {
ExtendedNormalizedAxiom other = (ExtendedNormalizedAxiom) obj;
return getAxiom().equals(other.getAxiom());
}
}

@Override
public String toString() {
return this.axiom.toString();
}

/**
* This is an auxiliary class used to collect the identifiers.
*
* @author Julian Mendez
*
*/
private class AuxIdentifierCollector implements NormalizedIntegerAxiomVisitor<Boolean> {
class AuxIdentifierCollector implements NormalizedIntegerAxiomVisitor<Boolean> {

AuxIdentifierCollector() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import de.tudresden.inf.lat.jcel.coreontology.axiom.NormalizedIntegerAxiom;
Expand Down Expand Up @@ -98,7 +101,7 @@ public Set<NormalizedIntegerAxiom> extractModule(Collection<NormalizedIntegerAxi

for (NormalizedIntegerAxiom axiom : remainingAxioms) {

IdentifierCollector c = new IdentifierCollector(axiom);
ExtendedNormalizedAxiom c = new ExtendedNormalizedAxiomImpl(axiom);
Set<Integer> classesOnTheLeft = c.getClassesOnTheLeft();
Set<Integer> objectPropertiesOnTheLeft = c.getObjectPropertiesOnTheLeft();

Expand All @@ -118,4 +121,93 @@ public Set<NormalizedIntegerAxiom> extractModule(Collection<NormalizedIntegerAxi
return ret;
}

/**
* Returns a map that relates a class with the set of axioms where this
* class occurs on the left side of the axiom
*
* @param normalizedAxioms
* normalized axioms
* @return a map that relates a class with the set of axioms where this
* class occurs on the left side of the axiom
*/
Map<Integer, Set<ExtendedNormalizedAxiom>> buildMapOfAxioms(Set<ExtendedNormalizedAxiom> normalizedAxioms) {
Map<Integer, Set<ExtendedNormalizedAxiom>> map = new HashMap<>();
normalizedAxioms.forEach(axiom -> {
Set<Integer> classesOnTheLeft = axiom.getClassesOnTheLeft();
classesOnTheLeft.forEach(classId -> {
Set<ExtendedNormalizedAxiom> value = map.get(classId);
if (Objects.isNull(value)) {
value = new HashSet<>();
map.put(classId, value);
}
value.add(axiom);
});
});
return map;
}

Set<NormalizedIntegerAxiom> getAxiomsWithoutEntitiesOnTheLeft(Set<ExtendedNormalizedAxiom> axioms) {
Set<NormalizedIntegerAxiom> ret = new HashSet<>();
axioms.forEach(axiom -> {
if (axiom.getClassesOnTheLeft().isEmpty() && axiom.getObjectPropertiesOnTheLeft().isEmpty()) {
ret.add(axiom.getAxiom());
}
});
return ret;
}

Set<ExtendedNormalizedAxiom> getAxiomsWithClassesOnTheLeft(Set<Integer> classesToVisit,
Map<Integer, Set<ExtendedNormalizedAxiom>> map) {
Set<ExtendedNormalizedAxiom> ret = new HashSet<>();
classesToVisit.forEach(classId -> {
Set<ExtendedNormalizedAxiom> newAxioms = map.get(classId);
if (newAxioms != null) {
ret.addAll(newAxioms);
}
});
return ret;
}

/**
* Returns a module, i.e. a subset of axioms relevant to answer a query.
*
* @param setOfAxioms
* set of axioms
* @param setOfClasses
* set of classes
* @return a module, i.e. a subset of axioms relevant to answer a query
*/
public Set<NormalizedIntegerAxiom> extractModule(Collection<NormalizedIntegerAxiom> setOfAxioms,
Set<Integer> setOfClasses) {

Set<NormalizedIntegerAxiom> ret = new HashSet<>();

Set<ExtendedNormalizedAxiom> axioms = new HashSet<>();
setOfAxioms.forEach(axiom -> axioms.add(new ExtendedNormalizedAxiomImpl(axiom)));

ret.addAll(getAxiomsWithoutEntitiesOnTheLeft(axioms));

Map<Integer, Set<ExtendedNormalizedAxiom>> map = buildMapOfAxioms(axioms);

Set<Integer> visitedClasses = new HashSet<Integer>();
Set<Integer> classesToVisit = new HashSet<Integer>();
classesToVisit.addAll(setOfClasses);
int resultSize = -1;
while (ret.size() > resultSize) {
resultSize = ret.size();

Set<ExtendedNormalizedAxiom> axiomsToVisit = getAxiomsWithClassesOnTheLeft(classesToVisit, map);
visitedClasses.addAll(classesToVisit);
classesToVisit.clear();

axiomsToVisit.forEach(axiom -> {
classesToVisit.addAll(axiom.getClassesOnTheRight());
ret.add(axiom.getAxiom());
});
classesToVisit.removeAll(visitedClasses);
}

return ret;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public boolean addToS(int subClass, int superClass) {
@Override
public boolean contains(VNode node) {
Objects.requireNonNull(node);
return !Objects.isNull(this.invNodeSet.get(node));
return Objects.nonNull(this.invNodeSet.get(node));
}

private void createClassGraph() {
Expand Down
Loading

0 comments on commit 911f8d4

Please sign in to comment.