diff --git a/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java b/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java index 4d67f91b0a..182410c3f1 100644 --- a/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java +++ b/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java @@ -21,7 +21,6 @@ import com.google.common.collect.Sets; import com.jamonapi.Monitor; import org.apache.log4j.Level; -import org.apache.log4j.Logger; import org.dllearner.core.*; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.options.CommonConfigOptions; @@ -40,10 +39,10 @@ import org.dllearner.utilities.owl.EvaluatedDescriptionPosNegComparator; import org.dllearner.utilities.owl.OWLClassExpressionLengthMetric; import org.dllearner.utilities.owl.OWLClassExpressionUtils; -import org.semanticweb.owlapi.io.OWLObjectRenderer; import org.semanticweb.owlapi.model.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import java.io.File; import java.text.DecimalFormat; @@ -77,16 +76,11 @@ public class OCEL extends AbstractCELA { // actual algorithm - private static Logger logger = Logger.getLogger(OCEL.class); + private static Logger logger = LoggerFactory.getLogger(OCEL.class); private String logLevel = CommonConfigOptions.logLevelDefault; - - private OWLObjectRenderer renderer; - // basic setup: learning problem and reasoning service - private AbstractReasonerComponent rs; // often the learning problems needn't be accessed directly; instead // use the example sets below and the posonly variable - private PosNegLP learningProblem; private OWLClassExpression startDescription; private int nrOfExamples; private int nrOfPositiveExamples; @@ -110,8 +104,6 @@ public class OCEL extends AbstractCELA { private boolean useShortConceptConstruction = true; // extended Options - @ConfigOption(defaultValue = "10", description = "maximum execution of the algorithm in seconds") - private int maxExecutionTimeInSeconds = CommonConfigOptions.maxExecutionTimeInSecondsDefault; private boolean maxExecutionTimeAlreadyReached = false; private int minExecutionTimeInSeconds = CommonConfigOptions.minExecutionTimeInSecondsDefault; private boolean minExecutionTimeAlreadyReached = false; @@ -147,10 +139,6 @@ public class OCEL extends AbstractCELA { private boolean useCandidateReduction = true; private int candidatePostReductionSize = 30; - // setting to true gracefully stops the algorithm - private boolean stop = false; - private boolean isRunning = false; - // solution protocol private List solutions = new LinkedList<>(); @@ -205,10 +193,6 @@ public class OCEL extends AbstractCELA { private long evaluateSetCreationTimeNs = 0; private long improperConceptsRemovalTimeNs = 0; - // prefixes - private String baseURI; - private Map prefixes; - private boolean terminateOnNoiseReached = true; private double negativeWeight = 1.0; @@ -220,7 +204,6 @@ public class OCEL extends AbstractCELA { private int negationPenalty = 0; - private OWLDataFactory dataFactory = new OWLDataFactoryImpl(); @ConfigOption(description = "adjust the weights of class expression length in refinement", defaultValue = "OCEL default metric") private OWLClassExpressionLengthMetric lengthMetric; @@ -268,7 +251,7 @@ public void init() throws ComponentInitException { // set log level if the option has been set if(!logLevel.equals(CommonConfigOptions.logLevelDefault)) - logger.setLevel(Level.toLevel(logLevel,Level.toLevel(CommonConfigOptions.logLevelDefault))); + org.apache.log4j.Logger.getLogger(OCEL.class).setLevel(Level.toLevel(logLevel,Level.toLevel(CommonConfigOptions.logLevelDefault))); if(searchTreeFile == null) searchTreeFile = new File(defaultSearchTreeFile); @@ -354,14 +337,14 @@ public void init() throws ComponentInitException { // create an algorithm object and pass all configuration // options to it - positiveExamples = learningProblem.getPositiveExamples(); - negativeExamples = learningProblem.getNegativeExamples(); + positiveExamples = ((PosNegLP)learningProblem).getPositiveExamples(); + negativeExamples = ((PosNegLP)learningProblem).getNegativeExamples(); nrOfPositiveExamples = positiveExamples.size(); nrOfNegativeExamples = negativeExamples.size(); nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; - baseURI = rs.getBaseURI(); - prefixes = rs.getPrefixes(); + baseURI = reasoner.getBaseURI(); + prefixes = reasoner.getPrefixes(); // note: used concepts and roles do not need to be passed // as argument, because it is sufficient to prepare the // concept and role hierarchy accordingly @@ -411,13 +394,13 @@ public void start() { if (startDescription == null) { startNode = new ExampleBasedNode(dataFactory.getOWLThing(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); startNode.setCoveredExamples(positiveExamples, negativeExamples); - startNode.setAccuracyMethod(learningProblem.getAccuracyMethod()); + startNode.setAccuracyMethod(((PosNegLP)learningProblem).getAccuracyMethod()); } else { startNode = new ExampleBasedNode(startDescription, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); - Set coveredNegatives = rs.hasType(startDescription, negativeExamples); - Set coveredPositives = rs.hasType(startDescription, positiveExamples); + Set coveredNegatives = reasoner.hasType(startDescription, negativeExamples); + Set coveredPositives = reasoner.hasType(startDescription, positiveExamples); startNode.setCoveredExamples(coveredPositives, coveredNegatives); - startNode.setAccuracyMethod(learningProblem.getAccuracyMethod()); + startNode.setAccuracyMethod(((PosNegLP)learningProblem).getAccuracyMethod()); } searchTree.addNode(null, startNode); @@ -469,8 +452,8 @@ public void start() { // no handling needed, it will just look ugly in the output logger.info("more accurate ("+acc+") class expression found: " + renderer.render(searchTreeStable.best().getConcept())); if(logger.isTraceEnabled()){ - logger.trace(Sets.difference(positiveExamples,bestNodeStable.getCoveredNegatives())); - logger.trace(Sets.difference(negativeExamples,bestNodeStable.getCoveredNegatives())); + logger.trace(Sets.difference(positiveExamples,bestNodeStable.getCoveredNegatives()).toString()); + logger.trace(Sets.difference(negativeExamples,bestNodeStable.getCoveredNegatives()).toString()); } printBestSolutions(5); printStatistics(false); @@ -539,7 +522,7 @@ public void start() { logger.info("Algorithm stopped ("+conceptTests+" descriptions tested).\n"); } else { logger.info("Algorithm terminated successfully ("+conceptTests+" descriptions tested).\n"); - logger.info(rs.toString()); + logger.info(reasoner.toString()); } totalLearningTime.stop(); @@ -660,7 +643,7 @@ private void extendNodeProper(ExampleBasedNode node, OWLClassExpression concept, // Test aller Konzepte auf properness (mit DIG in nur einer Anfrage) if (usePropernessChecks) { long propCalcReasoningStart = System.nanoTime(); - improperConcepts = rs.isSuperClassOf(toEvaluateConcepts, concept); + improperConcepts = reasoner.isSuperClassOf(toEvaluateConcepts, concept); propernessTestsReasoner += toEvaluateConcepts.size(); propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart; @@ -706,7 +689,7 @@ private void extendNodeProper(ExampleBasedNode node, OWLClassExpression concept, qualityKnown = true; newNode.setQualityEvaluationMethod(ExampleBasedNode.QualityEvaluationMethod.OVERLY_GENERAL_LIST); newNode.setCoveredExamples(positiveExamples, negativeExamples); - newNode.setAccuracyMethod(learningProblem.getAccuracyMethod()); + newNode.setAccuracyMethod(((PosNegLP)learningProblem).getAccuracyMethod()); } } @@ -733,7 +716,7 @@ private void extendNodeProper(ExampleBasedNode node, OWLClassExpression concept, for (OWLIndividual i : coveredPositives) { // TODO: move code to a separate function if (quality != -1) { - boolean covered = rs.hasType(refinement, i); + boolean covered = reasoner.hasType(refinement, i); if (!covered) misclassifiedPositives++; else @@ -751,7 +734,7 @@ private void extendNodeProper(ExampleBasedNode node, OWLClassExpression concept, newlyCoveredNegatives = new HashSet<>(); for (OWLIndividual i : coveredNegatives) { - boolean covered = rs.hasType(refinement, i); + boolean covered = reasoner.hasType(refinement, i); if (covered) newlyCoveredNegatives.add(i); } @@ -759,8 +742,8 @@ private void extendNodeProper(ExampleBasedNode node, OWLClassExpression concept, propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart2; newNode.setQualityEvaluationMethod(ExampleBasedNode.QualityEvaluationMethod.REASONER); - if (quality != -1 && !(learningProblem.getAccuracyMethod() instanceof AccMethodNoWeakness) && - learningProblem.getAccuracyMethod().getAccOrTooWeak2( + if (quality != -1 && !(((PosNegLP)learningProblem).getAccuracyMethod() instanceof AccMethodNoWeakness) && + ((PosNegLP)learningProblem).getAccuracyMethod().getAccOrTooWeak2( newlyCoveredPositives.size(), nrOfPositiveExamples - newlyCoveredPositives.size(), newlyCoveredNegatives.size(), nrOfNegativeExamples - newlyCoveredNegatives.size(), 1) == -1) @@ -772,7 +755,7 @@ private void extendNodeProper(ExampleBasedNode node, OWLClassExpression concept, quality = (nrOfPositiveExamples - newlyCoveredPositives.size()) + newlyCoveredNegatives.size(); newNode.setCoveredExamples(newlyCoveredPositives, newlyCoveredNegatives); - newNode.setAccuracyMethod(learningProblem.getAccuracyMethod()); + newNode.setAccuracyMethod(((PosNegLP)learningProblem).getAccuracyMethod()); } } @@ -861,19 +844,19 @@ private void printStatistics(boolean finalStats) { logger.debug(expandedNodeString); logger.debug("algorithm runtime " + Helper.prettyPrintNanoSeconds(algorithmRuntime)); logger.debug("size of candidate set: " + searchTree.size()); - logger.debug("subsumption time: " + Helper.prettyPrintNanoSeconds(rs.getSubsumptionReasoningTimeNs())); - logger.debug("instance check time: " + Helper.prettyPrintNanoSeconds(rs.getInstanceCheckReasoningTimeNs())); - logger.debug("retrieval time: " + Helper.prettyPrintNanoSeconds(rs.getRetrievalReasoningTimeNs())); + logger.debug("subsumption time: " + Helper.prettyPrintNanoSeconds(reasoner.getSubsumptionReasoningTimeNs())); + logger.debug("instance check time: " + Helper.prettyPrintNanoSeconds(reasoner.getInstanceCheckReasoningTimeNs())); + logger.debug("retrieval time: " + Helper.prettyPrintNanoSeconds(reasoner.getRetrievalReasoningTimeNs())); } if (computeBenchmarkInformation) { - long reasoningTime = rs.getOverallReasoningTimeNs(); + long reasoningTime = reasoner.getOverallReasoningTimeNs(); double reasoningPercentage = 100 * reasoningTime / (double) algorithmRuntime; long propWithoutReasoning = propernessCalcTimeNs - propernessCalcReasoningTimeNs; double propPercentage = 100 * propWithoutReasoning / (double) algorithmRuntime; double deletionPercentage = 100 * childConceptsDeletionTimeNs / (double) algorithmRuntime; - long subTime = rs.getSubsumptionReasoningTimeNs(); + long subTime = reasoner.getSubsumptionReasoningTimeNs(); double subPercentage = 100 * subTime / (double) algorithmRuntime; double refinementPercentage = 100 * refinementCalcTimeNs / (double) algorithmRuntime; double redundancyCheckPercentage = 100 * redundancyCheckTimeNs / (double) algorithmRuntime; @@ -1056,10 +1039,6 @@ private void reduceCandidates() { } } - public void stop() { - stop = true; - } - public OWLClassExpression getBestSolution() { return searchTreeStable.best().getConcept(); } @@ -1115,11 +1094,11 @@ public void printBestSolutions(int nrOfSolutions) { } public ScorePosNeg getSolutionScore() { - return learningProblem.computeScore(getBestSolution()); + return ((PosNegLP)learningProblem).computeScore(getBestSolution()); } private ScorePosNeg getScore(OWLClassExpression d) { - return learningProblem.computeScore(d); + return ((PosNegLP)learningProblem).computeScore(d); } public ExampleBasedNode getStartNode() { @@ -1209,10 +1188,6 @@ else if(conceptTests >= maxClassDescriptionTests){ } - public boolean isRunning() { - return isRunning; - } - public boolean isUseTreeTraversal() { return useTreeTraversal; } @@ -1364,16 +1339,6 @@ public void setForceRefinementLengthIncrease(boolean forceRefinementLengthIncrea this.forceRefinementLengthIncrease = forceRefinementLengthIncrease; } - @Override - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - @Override - public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { - this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; - } - public int getMinExecutionTimeInSeconds() { return minExecutionTimeInSeconds; } diff --git a/components-core/src/main/java/org/dllearner/core/AbstractCELA.java b/components-core/src/main/java/org/dllearner/core/AbstractCELA.java index e01282457c..52b672df72 100644 --- a/components-core/src/main/java/org/dllearner/core/AbstractCELA.java +++ b/components-core/src/main/java/org/dllearner/core/AbstractCELA.java @@ -181,16 +181,6 @@ public void changeReasonerComponent(AbstractReasonerComponent reasoningService) * choose to store results.) */ public static final int MAX_NR_OF_RESULTS = 100; - - /** - * Every algorithm must be able to return the score of the - * best solution found. - * - * @return Best score. - */ -// @Deprecated -// public abstract Score getSolutionScore(); - /** * @see #getCurrentlyBestEvaluatedDescription() @@ -358,7 +348,7 @@ protected String descriptionToString(OWLClassExpression description) { protected String getSolutionString() { int current = 1; String str = ""; - for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet().descendingSet()) { + for(EvaluatedDescription ed : getCurrentlyBestEvaluatedDescriptions().descendingSet()) { // temporary code OWLClassExpression description = ed.getDescription(); String descriptionString = descriptionToString(description); diff --git a/pom.xml b/pom.xml index 7cab51fc60..cabd7bd31a 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 1.8 UTF-8 - 1.6.4 + 1.7.16 1.2.16 5.3.0 4.1.4