Skip to content

Commit

Permalink
Reduce execution time of basic completion rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Mendez committed Dec 13, 2015
1 parent 96bd127 commit c0d0b62
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ public boolean apply(ClassifierStatus status, int subClass, int superClass) {
}

private boolean applyRule(ClassifierStatus status, int x, int a) {
return status.getExtendedOntology().getGCI0Axioms(a).stream().map(axiom -> {
CompletionRuleMonitor ret = new CompletionRuleMonitor();
status.getExtendedOntology().getGCI0Axioms(a).forEach(axiom -> {

int b = axiom.getSuperClass();
return status.addNewSEntry(x, b);
ret.or(status.addNewSEntry(x, b));

}).reduce(false, (accum, elem) -> (accum || elem));
});
return ret.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ public boolean apply(ClassifierStatus status, int subClass, int superClass) {
}

private boolean applyRule(ClassifierStatus status, int x, int a) {
CompletionRuleMonitor ret = new CompletionRuleMonitor();
Collection<Integer> subsumersOfX = status.getSubsumers(x);
return status.getExtendedOntology().getGCI1Axioms(a).stream().map(axiom -> {
status.getExtendedOntology().getGCI1Axioms(a).forEach(axiom -> {

boolean valid = true;

Expand All @@ -111,12 +112,11 @@ private boolean applyRule(ClassifierStatus status, int x, int a) {

if (valid) {
int b = axiom.getSuperClass();
return status.addNewSEntry(x, b);
} else {
return false;
ret.or(status.addNewSEntry(x, b));
}

}).reduce(false, (accum, elem) -> (accum || elem));
});
return ret.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ public boolean apply(ClassifierStatus status, int subClass, int superClass) {
}

private boolean applyRule(ClassifierStatus status, int x, int a) {
return status.getExtendedOntology().getGCI2Axioms(a).stream().map(axiom -> {
CompletionRuleMonitor ret = new CompletionRuleMonitor();
status.getExtendedOntology().getGCI2Axioms(a).forEach(axiom -> {

int r = axiom.getPropertyInSuperClass();
int b = axiom.getClassInSuperClass();
return status.addNewREntry(r, x, b);
ret.or(status.addNewREntry(r, x, b));

}).reduce(false, (accum, elem) -> (accum || elem));
});
return ret.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ public boolean apply(ClassifierStatus status, int property, int leftClass, int r
}

private boolean applyRule(ClassifierStatus status, int r, int x, int y) {
return status.getSubsumers(y).stream().map(a ->
CompletionRuleMonitor ret = new CompletionRuleMonitor();

status.getExtendedOntology().getGCI3rAAxioms(r, a).stream().map(axiom -> {
status.getSubsumers(y).forEach(a ->

int b = axiom.getSuperClass();
return status.addNewSEntry(x, b);

}).reduce(false, (accum, elem) -> (accum || elem)))
status.getExtendedOntology().getGCI3rAAxioms(r, a).forEach(axiom -> {

.reduce(false, (accum, elem) -> (accum || elem));
int b = axiom.getSuperClass();
ret.or(status.addNewSEntry(x, b));

}));
return ret.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,19 @@ public boolean apply(ClassifierStatus status, int subClass, int superClass) {
}

private boolean applyRule(ClassifierStatus status, int y, int a) {
return status.getObjectPropertiesBySecond(y).stream().map(r ->
CompletionRuleMonitor ret = new CompletionRuleMonitor();

status.getExtendedOntology().getGCI3rAAxioms(r, a).stream().map(axiom ->
status.getObjectPropertiesBySecond(y).forEach(r ->

status.getFirstBySecond(r, y).stream().map(x -> {
status.getExtendedOntology().getGCI3rAAxioms(r, a).forEach(axiom ->

int b = axiom.getSuperClass();
return status.addNewSEntry(x, b);

}).reduce(false, (accum, elem) -> (accum || elem)))
status.getFirstBySecond(r, y).forEach(x -> {

.reduce(false, (accum, elem) -> (accum || elem)))

.reduce(false, (accum, elem) -> (accum || elem));
int b = axiom.getSuperClass();
ret.or(status.addNewSEntry(x, b));

})));
return ret.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ public boolean apply(ClassifierStatus status, int property, int leftClass, int r
}

private boolean applyRule(ClassifierStatus status, int r, int x, int y) {
return status.getExtendedOntology().getRI2rAxioms(r).stream().map(axiom -> {
CompletionRuleMonitor ret = new CompletionRuleMonitor();

status.getExtendedOntology().getRI2rAxioms(r).forEach(axiom -> {

int s = axiom.getSuperProperty();
return status.addNewREntry(s, x, y);
ret.or(status.addNewREntry(s, x, y));

}).reduce(false, (accum, elem) -> (accum || elem));
});
return ret.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,35 @@ public boolean apply(ClassifierStatus status, int property, int leftClass, int r
}

private boolean apply1(ClassifierStatus status, int r, int x, int y) {
return status.getExtendedOntology().getRI3AxiomsByLeft(r).stream().map(axiom -> {
CompletionRuleMonitor ret = new CompletionRuleMonitor();

status.getExtendedOntology().getRI3AxiomsByLeft(r).forEach(axiom -> {

int s = axiom.getRightSubProperty();
int t = axiom.getSuperProperty();

return status.getSecondByFirst(s, y).stream().map(z ->

status.addNewREntry(t, x, z)
status.getSecondByFirst(s, y).forEach(z ->

).reduce(false, (accum, elem) -> (accum || elem));
ret.or(status.addNewREntry(t, x, z)));

}).reduce(false, (accum, elem) -> (accum || elem));
});
return ret.get();
}

private boolean apply2(ClassifierStatus status, int s, int y, int z) {
return status.getExtendedOntology().getRI3AxiomsByRight(s).stream().map(axiom -> {
CompletionRuleMonitor ret = new CompletionRuleMonitor();

status.getExtendedOntology().getRI3AxiomsByRight(s).forEach(axiom -> {

int r = axiom.getLeftSubProperty();
int t = axiom.getSuperProperty();

return status.getFirstBySecond(r, y).stream().map(x ->

status.addNewREntry(t, x, z)
status.getFirstBySecond(r, y).forEach(x ->

).reduce(false, (accum, elem) -> (accum || elem));
ret.or(status.addNewREntry(t, x, z)));

}).reduce(false, (accum, elem) -> (accum || elem));
});
return ret.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,25 @@ public boolean apply(ClassifierStatus status, int property, int leftClass, int r
}

private boolean apply1(ClassifierStatus status, int r, int x, int y) {
if (status.getExtendedOntology().getTransitiveObjectProperties().contains(r)) {
return status.getSecondByFirst(r, y).stream().map(z ->
CompletionRuleMonitor ret = new CompletionRuleMonitor();

status.addNewREntry(r, x, z)
if (status.getExtendedOntology().getTransitiveObjectProperties().contains(r)) {

).reduce(false, (accum, elem) -> (accum || elem));
status.getSecondByFirst(r, y).forEach(z -> ret.or(status.addNewREntry(r, x, z)));

} else {
return false;
}
return ret.get();
}

private boolean apply2(ClassifierStatus status, int r, int y, int z) {
if (status.getExtendedOntology().getTransitiveObjectProperties().contains(r)) {
return status.getFirstBySecond(r, y).stream().map(x ->
CompletionRuleMonitor ret = new CompletionRuleMonitor();

status.addNewREntry(r, x, z)
if (status.getExtendedOntology().getTransitiveObjectProperties().contains(r)) {

).reduce(false, (accum, elem) -> (accum || elem));
status.getFirstBySecond(r, y).forEach(x -> ret.or(status.addNewREntry(r, x, z)));

} else {
return false;
}
return ret.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,18 @@ public boolean apply(ClassifierStatus status, int subClass, int superClass) {
}

private boolean applyRule(ClassifierStatus status, int y, int a) {
if (a == IntegerEntityManager.bottomClassId) {

return status.getObjectPropertiesBySecond(y).stream().map(r ->
CompletionRuleMonitor ret = new CompletionRuleMonitor();

status.getFirstBySecond(r, y).stream().map(x ->
if (a == IntegerEntityManager.bottomClassId) {

status.addNewSEntry(x, IntegerEntityManager.bottomClassId)
status.getObjectPropertiesBySecond(y).forEach(r ->

).reduce(false, (accum, elem) -> (accum || elem))
status.getFirstBySecond(r, y).forEach(x ->

).reduce(false, (accum, elem) -> (accum || elem));
ret.or(status.addNewSEntry(x, IntegerEntityManager.bottomClassId))));

} else {
return false;
}
return ret.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
*
* Copyright (C) 2009-2015 Julian Mendez
*
*
* This file is part of jcel.
*
*
* The contents of this file are subject to the GNU Lesser General Public License
* version 3
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* Alternatively, the contents of this file may be used under the terms
* of the Apache License, Version 2.0, in which case the
* provisions of the Apache License, Version 2.0 are applicable instead of those
* above.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package de.tudresden.inf.lat.jcel.core.completion.basic;

/**
* An object of this class keeps track whether a completion rule has been
* applied.
*
* @author Julian Mendez
*
*/
public class CompletionRuleMonitor {

private Object monitor = new Object();
private boolean state = false;

public CompletionRuleMonitor() {
}

public boolean get() {
return this.state;
}

public synchronized void or(boolean b) {
synchronized (this.monitor) {
this.state |= b;
}
}

@Override
public int hashCode() {
return this.state ? 1 : 0;
}

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

@Override
public String toString() {
return "" + this.state;
}

}

0 comments on commit c0d0b62

Please sign in to comment.