From: <jen...@us...> - 2008-03-05 18:30:01
|
Revision: 689 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=689&view=rev Author: jenslehmann Date: 2008-03-05 10:29:41 -0800 (Wed, 05 Mar 2008) Log Message: ----------- - a lot of bug fixes - new learning algorithm should be usable now Modified Paths: -------------- trunk/examples/arch/arch.conf trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/FlexibleHeuristic.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/LexicographicHeuristic.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/NodeComparatorStable.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java trunk/src/dl-learner/org/dllearner/parser/kb.jj trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java Modified: trunk/examples/arch/arch.conf =================================================================== --- trunk/examples/arch/arch.conf 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/examples/arch/arch.conf 2008-03-05 18:29:41 UTC (rev 689) @@ -18,6 +18,8 @@ algorithm = refexamples; reasoner = fastInstanceChecker; +// comment this out if the search should start from construction +// refexamples.startClass = "http://localhost/foo#construction"; // export("arch.owl"); import("arch.kb"); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-03-05 18:29:41 UTC (rev 689) @@ -20,6 +20,7 @@ package org.dllearner.algorithms.refexamples; +import java.text.DecimalFormat; import java.util.Set; import java.util.TreeSet; @@ -39,6 +40,8 @@ */ public class ExampleBasedNode { + private static DecimalFormat df = new DecimalFormat(); + // example based variables private Set<Individual> coveredPositives; private Set<Individual> coveredNegatives; @@ -50,7 +53,8 @@ // all properties of a node in the search tree private Description concept; private int horizontalExpansion; - private int coveredNegativeExamples; + // specifies whether the node is too weak (exceeds the max. nr allowed + // misclassifications of positive examples) private boolean isTooWeak; private boolean isQualityEvaluated; private boolean isRedundant; @@ -104,11 +108,12 @@ @Override public String toString() { +// System.out.println(concept); String ret = concept.toString() + " [q:"; if(isTooWeak) ret += "tw"; else - ret += coveredNegativeExamples; + ret += coveredNegatives.size(); ret += ", he:" + horizontalExpansion + ", children:" + children.size() + "]"; return ret; } @@ -124,35 +129,50 @@ } } - public String getTreeString() { - return getTreeString(0).toString(); + public String getTreeString(int nrOfPositiveExamples, int nrOfNegativeExamples) { + return getTreeString(nrOfPositiveExamples, nrOfNegativeExamples, 0,null).toString(); } - private StringBuilder getTreeString(int depth) { + public String getTreeString(int nrOfPositiveExamples, int nrOfNegativeExamples, String baseURI) { + return getTreeString(nrOfPositiveExamples, nrOfNegativeExamples, 0,baseURI).toString(); + } + + private StringBuilder getTreeString(int nrOfPositiveExamples, int nrOfNegativeExamples, int depth, String baseURI) { StringBuilder treeString = new StringBuilder(); for(int i=0; i<depth-1; i++) treeString.append(" "); if(depth!=0) // treeString.append("|-→ "); treeString.append("|--> "); - treeString.append(getShortDescription()+"\n"); + treeString.append(getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)+"\n"); for(ExampleBasedNode child : children) { - treeString.append(child.getTreeString(depth+1)); + treeString.append(child.getTreeString(nrOfPositiveExamples, nrOfNegativeExamples, depth+1,baseURI)); } return treeString; } - private String getShortDescription() { - String ret = concept.toString() + " [q:"; + public String getShortDescription(int nrOfPositiveExamples, int nrOfNegativeExamples, String baseURI) { + String ret = concept.toString(baseURI,null) + " ["; if(isTooWeak) - ret += "tw"; - else - ret += coveredNegativeExamples; + ret += "q:tw"; + else { + double accuracy = 100 * (coveredPositives.size() + nrOfNegativeExamples - coveredNegatives.size())/(double)(nrOfPositiveExamples+nrOfNegativeExamples); + ret += "acc:" + df.format(accuracy) + "% "; + + // comment this out to display the heuristic score with default parameters + double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples); + ret += "h:" +df.format(heuristicScore) + " "; + + int wrongPositives = nrOfPositiveExamples - coveredPositives.size(); + ret += "q:" + wrongPositives + "p-" + coveredNegatives.size() + "n"; + } - ret += " ("+qualityEvaluationMethod+"), he:" + horizontalExpansion + "]"; + ret += " ("+qualityEvaluationMethod+"), he:" + horizontalExpansion; + ret += " c:" + children.size() + "]"; + return ret; - } + } public Set<Individual> getCoveredPositives() { return coveredPositives; @@ -178,9 +198,6 @@ return qualityEvaluationMethod; } - public int getCoveredNegativeExamples() { - return coveredNegativeExamples; - } public int getHorizontalExpansion() { return horizontalExpansion; } @@ -199,6 +216,6 @@ */ public ExampleBasedNode getParent() { return parent; - } + } } \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-03-05 18:29:41 UTC (rev 689) @@ -85,7 +85,7 @@ private File searchTreeFile; private boolean replaceSearchTree = false; private static String defaultSearchTreeFile = "log/searchTree.txt"; - private String heuristic = "lexicographic"; + private String heuristic = "multi"; Set<NamedClass> allowedConcepts; Set<ObjectProperty> allowedRoles; Set<NamedClass> ignoredConcepts; @@ -241,11 +241,16 @@ if(heuristic == "lexicographic") algHeuristic = new LexicographicHeuristic(); - else { + else if(heuristic == "flexible") { if(learningProblem instanceof PosOnlyDefinitionLP) { throw new RuntimeException("does not work with positive examples only yet"); } algHeuristic = new FlexibleHeuristic(((PosNegLP)learningProblem).getNegativeExamples().size(), ((PosNegLP)learningProblem).getPercentPerLengthUnit()); + } else { + if(learningProblem instanceof PosOnlyDefinitionLP) { + throw new RuntimeException("does not work with positive examples only yet"); + } + algHeuristic = new MultiHeuristic(((PosNegLP)learningProblem).getPositiveExamples().size(),((PosNegLP)learningProblem).getNegativeExamples().size()); } // compute used concepts/roles from allowed/ignored Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-03-05 18:29:41 UTC (rev 689) @@ -170,6 +170,9 @@ private long evaluateSetCreationTimeNs = 0; private long improperConceptsRemovalTimeNs = 0; + // prefixes + private String baseURI; + public ExampleBasedROLearner( LearningProblem learningProblem, ReasoningService rs, @@ -212,13 +215,14 @@ this.useTooWeakList = useTooWeakList; this.useOverlyGeneralList = useOverlyGeneralList; this.useShortConceptConstruction = useShortConceptConstruction; + baseURI = rs.getBaseURI(); logger.setLevel(Level.DEBUG); } public void start() { // calculate quality threshold required for a solution - allowedMisclassifications = (int) Math.round(noise * nrOfExamples); + allowedMisclassifications = (int) Math.round(noise * nrOfExamples); // start search with start class if(startDescription == null) { @@ -266,15 +270,15 @@ if(writeSearchTree) { // String treeString = ""; - String treeString = "best expanded node: " + bestNode+ "\n"; + String treeString = "best node: " + bestNode+ "\n"; if(expandedNodes.size()>1) { - treeString += "all expanded nodes:\n"; // due to minimum horizontal expansion:\n"; + treeString += "all expanded nodes:\n"; for(ExampleBasedNode n : expandedNodes) { treeString += " " + n + "\n"; } } expandedNodes.clear(); - treeString += startNode.getTreeString(); + treeString += startNode.getTreeString(nrOfPositiveExamples, nrOfNegativeExamples, baseURI); treeString += "\n"; if(replaceSearchTree) @@ -291,6 +295,7 @@ } if(solutionFound) { + logger.info("best node " + candidatesStable.last().getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); logger.info("\nsolutions:"); for(Description c : solutions) { logger.info(" " + c + " (length " + c.getLength() +", depth " + c.getDepth() + ")"); @@ -305,10 +310,9 @@ System.out.println("Algorithm terminated succesfully."); } + // we apply the operator recursively until all proper refinements up + // to the maxmimum length are reached private void extendNodeProper(ExampleBasedNode node, int maxLength) { - // Rekursionsanfang ist das Konzept am Knoten selbst; danach wird der Operator - // so lange darauf angewandt bis alle proper refinements bis zu maxLength - // gefunden wurden long propCalcNsStart = System.nanoTime(); if(writeSearchTree) @@ -317,54 +321,27 @@ if(node.getChildren().size()>maxNrOfChildren) maxNrOfChildren = node.getChildren().size(); - // Knoten in instabiler Menge muss aktualisiert werden - // => wird jetzt schon vom Algorithmus entfernt - /* - boolean remove = candidates.remove(node); - - if(!remove) { - System.out.println(candidates); - System.out.println(candidatesStable); - System.out.println(node); - - throw new RuntimeException("remove failed"); - }*/ - extendNodeProper(node, node.getConcept(), maxLength, 0); node.setHorizontalExpansion(maxLength); - // wird jetzt schon im Kernalgorithmus hinzugefügt - /* - boolean add = candidates.add(node); - if(!add) { - throw new RuntimeException("add failed"); - }*/ - - // Knoten wird entfernt und wieder hinzugefügt, da sich seine - // Position geändert haben könnte => geht noch nicht wg. ConcurrentModification - // falls Knoten wg. min. horiz. exp. expandiert werden - // candidates.remove(node); - // candidates.add(node); propernessCalcTimeNs += (System.nanoTime()-propCalcNsStart); } - - - // für alle proper refinements von concept bis maxLength werden Kinderknoten - // für node erzeugt; - // recDepth dient nur zur Protokollierung + // for all refinements of concept up to max length, we check whether they are properr + // and call the method recursively if not + // recDepth is used only for statistics private void extendNodeProper(ExampleBasedNode node, Description concept, int maxLength, int recDepth) { - // führe Methode nicht aus, wenn Algorithmus gestoppt wurde (alle rekursiven Funktionsaufrufe - // werden nacheinander abgebrochen, so dass ohne weitere Reasoninganfragen relativ schnell beendet wird) + // do not execute methods if algorithm has been stopped (this means that the algorithm + // will terminate without further reasoning queries) if(stop) return; if(recDepth > maxRecDepth) maxRecDepth = recDepth; - // Refinements berechnen => hier dürfen dürfen refinements <= horizontal expansion - // des Konzepts nicht gelöscht werden! + // compute refinements => we must not delete refinements with low horizontal expansion, + // because they are used in recursive calls of this method later on long refinementCalcTimeNsStart = System.nanoTime(); Set<Description> refinements = operator.refine(concept, maxLength, null); refinementCalcTimeNs += System.nanoTime() - refinementCalcTimeNsStart; @@ -393,18 +370,13 @@ while(it.hasNext()) { Description refinement = it.next(); if(refinement.getLength()>node.getHorizontalExpansion()) { - // TODO: an dieser Stelle könnte man Algorithmen ansetzen lassen, die - // versuchen properness-Anfragen zu vermeiden: - // 1. Konzept kürzen und schauen, ob es Mutterkonzept entspricht - // 2. Blacklist, die überprüft, ob Konzept too weak ist - // (dann ist es auch proper) - // sagt aus, ob festgestellt wurde, ob refinement proper ist // (sagt nicht aus, dass das refinement proper ist!) boolean propernessDetected = false; // 1. short concept construction if(useShortConceptConstruction) { + // kurzes Konzept konstruieren Description shortConcept = ConceptTransformation.getShortConcept(refinement, conceptComparator); int n = conceptComparator.compare(shortConcept, concept); @@ -503,9 +475,11 @@ quality = getNumberOfNegatives(); qualityKnown = true; newNode.setQualityEvaluationMethod(ExampleBasedNode.QualityEvaluationMethod.OVERLY_GENERAL_LIST); + newNode.setCoveredExamples(learningProblem.getPositiveExamples(), learningProblem.getNegativeExamples()); } + } - + // Qualität des Knotens auswerten if(!qualityKnown) { long propCalcReasoningStart2 = System.nanoTime(); @@ -519,23 +493,23 @@ // calculate how many pos. examples are not covered by the // parent node of the refinement - int misclassifications = nrOfPositiveExamples - coveredPositives.size(); + int misclassifiedPositives = nrOfPositiveExamples - coveredPositives.size(); // iterate through all covered examples (examples which are not - // covered do not need to be tested, because they remain uncovered) - // TODO: DIG will be slow if we send each reasoner request individually + // covered do not need to be tested, because they remain uncovered); + // DIG will be slow if we send each reasoner request individually // (however if we send everything in one request, too many instance checks - // are performed => rely on fast instance checker [still to implement]) + // are performed => rely on fast instance checker) for(Individual i : coveredPositives) { // TODO: move code to a separate function if(quality != -1) { boolean covered = rs.instanceCheck(refinement, i); if(!covered) - misclassifications++; + misclassifiedPositives++; else newlyCoveredPositives.add(i); - if(misclassifications > allowedMisclassifications) + if(misclassifiedPositives > allowedMisclassifications) quality = -1; } @@ -561,7 +535,7 @@ + newlyCoveredNegatives.size(); newNode.setCoveredExamples(newlyCoveredPositives, newlyCoveredNegatives); } - + } if(quality == -1) { @@ -575,18 +549,17 @@ solutions.add(refinement); } -// newNode.setCoveredNegativeExamples(quality); + newCandidates.add(newNode); - // candidates.add(newNode); - // candidatesStable.add(newNode); - - - if(quality == getNumberOfNegatives()) + + // we need to make sure that all positives are covered + // before adding something to the overly general list + if((newNode.getCoveredPositives().size() == nrOfPositiveExamples) && quality == getNumberOfNegatives()) overlyGeneralList.add(refinement); - - // System.out.print("."); + } +// System.out.println(newNode.getConcept() + " " + quality); node.addChild(newNode); } } @@ -673,6 +646,7 @@ System.out.println("onnf time percentage: " + df.format(onnfTimePercentage) + "%"); System.out.println("shortening time percentage: " + df.format(shorteningTimePercentage) + "%"); } + System.out.println("properness tests (reasoner/short concept/too weak list): " + propernessTestsReasoner + "/" + propernessTestsAvoidedByShortConceptConstruction + "/" + propernessTestsAvoidedByTooWeakList); System.out.println("concept tests (reasoner/too weak list/overly general list/redundant concepts): " + conceptTestsReasoner + "/" @@ -709,6 +683,22 @@ } return false; } +/* + private Set<Individual> computeQuality(Description refinement, Set<Individual> coveredPositives) { + Set<Individual> ret = new TreeSet<Individual>(); + int misclassifications; + for(Individual i : coveredPositives) { + boolean covered = rs.instanceCheck(refinement, i); + if(!covered) + misclassifications++; + else + ret.add(i); + + if(misclassifications > allowedMisclassifications) + return null; + } + } +*/ public void stop() { stop = true; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/FlexibleHeuristic.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/FlexibleHeuristic.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/FlexibleHeuristic.java 2008-03-05 18:29:41 UTC (rev 689) @@ -66,10 +66,10 @@ if(n1.isQualityEvaluated() && n2.isQualityEvaluated() && !n1.isTooWeak() && !n2.isTooWeak()) { // alle scores sind negativ, größere scores sind besser - double score1 = -n1.getCoveredNegativeExamples()/(double)nrOfNegativeExamples; + double score1 = -n1.getCoveredNegatives().size()/(double)nrOfNegativeExamples; score1 -= percentPerLengthUnit * n1.getConcept().getLength(); - double score2 = -n2.getCoveredNegativeExamples()/(double)nrOfNegativeExamples; + double score2 = -n2.getCoveredNegatives().size()/(double)nrOfNegativeExamples; score2 -= percentPerLengthUnit * n2.getConcept().getLength(); double diff = score1 - score2; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/LexicographicHeuristic.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/LexicographicHeuristic.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/LexicographicHeuristic.java 2008-03-05 18:29:41 UTC (rev 689) @@ -32,9 +32,9 @@ // sicherstellen, dass Qualität ausgewertet wurde if(n1.isQualityEvaluated() && n2.isQualityEvaluated() && !n1.isTooWeak() && !n2.isTooWeak()) { - if(n1.getCoveredNegativeExamples()<n2.getCoveredNegativeExamples()) + if(n1.getCoveredNegatives().size()<n2.getCoveredNegatives().size()) return 1; - else if(n1.getCoveredNegativeExamples()>n2.getCoveredNegativeExamples()) + else if(n1.getCoveredNegatives().size()>n2.getCoveredNegatives().size()) return -1; else { //TODO: es wäre geringfügig effizienter die Länge nicht mehrfach zu berechnen Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java 2008-03-05 18:29:41 UTC (rev 689) @@ -57,6 +57,11 @@ * N = number of negative examples<br /> * </code></p> * + * TODO: Maybe the number of children of a node could be used instead of + * horiz. exp, because if a node has a very high number of children, the + * algorithm gets stuck easily, while it could still be very agile in other + * parts of the search space. + * * @author Jens Lehmann * */ @@ -65,13 +70,18 @@ private ConceptComparator conceptComparator = new ConceptComparator(); // heuristic parameters - private double expansionPenaltyFactor = 0.01; - private double gainBonusFactor = 1.00; + private double expansionPenaltyFactor; + private double gainBonusFactor; + private double nodeChildPenalty = 0.0001; // examples private int nrOfNegativeExamples; private int nrOfExamples; + public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples) { + this(nrOfPositiveExamples, nrOfNegativeExamples, 0.03, 0.5); + } + public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples, double expansionPenaltyFactor, double gainBonusFactor) { this.nrOfNegativeExamples = nrOfNegativeExamples; nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; @@ -104,11 +114,17 @@ double parentAccuracy = getAccuracy(parent.getCoveredPositives().size(),parent.getCoveredNegatives().size()); gain = accuracy - parentAccuracy; } - return accuracy + gainBonusFactor * gain - expansionPenaltyFactor * node.getHorizontalExpansion(); + return accuracy + gainBonusFactor * gain - expansionPenaltyFactor * node.getHorizontalExpansion() - nodeChildPenalty * node.getChildren().size(); } private double getAccuracy(int coveredPositives, int coveredNegatives) { return (coveredPositives + nrOfNegativeExamples - coveredNegatives)/(double)nrOfExamples; } + + public static double getNodeScore(ExampleBasedNode node, int nrOfPositiveExamples, int nrOfNegativeExamples) { + MultiHeuristic multi = new MultiHeuristic(nrOfPositiveExamples, nrOfNegativeExamples); + return multi.getNodeScore(node); + } + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/NodeComparatorStable.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/NodeComparatorStable.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/NodeComparatorStable.java 2008-03-05 18:29:41 UTC (rev 689) @@ -25,44 +25,54 @@ import org.dllearner.utilities.ConceptComparator; /** - * Der Comparator ist stable, weil er nur nach covered negatives, - * Konzeptlänge und Konzeptstring vergleicht, die sich während des Algorithmus nicht - * ändern können. + * This comparator is stable, because it only takes covered examples, concept + * length and the concepts itself (using again a stable comparator) into a + * account, which do not change during the run of the algorithm. * - * @author jl + * @author Jens Lehmann * */ public class NodeComparatorStable implements Comparator<ExampleBasedNode> { - ConceptComparator conceptComparator = new ConceptComparator(); + private ConceptComparator conceptComparator = new ConceptComparator(); - // implementiert public int compare(ExampleBasedNode n1, ExampleBasedNode n2) { - // sicherstellen, dass Qualität ausgewertet wurde + // make sure quality has been evaluated if(n1.isQualityEvaluated() && n2.isQualityEvaluated()) { if(!n1.isTooWeak() && !n2.isTooWeak()) { - if(n1.getCoveredNegativeExamples()<n2.getCoveredNegativeExamples()) + int classificationPointsN1 = n1.getCoveredPositives().size() - n1.getCoveredNegatives().size(); + int classificationPointsN2 = n2.getCoveredPositives().size() - n2.getCoveredNegatives().size(); + + if(classificationPointsN1>classificationPointsN2) return 1; - else if(n1.getCoveredNegativeExamples()>n2.getCoveredNegativeExamples()) + else if(classificationPointsN1<classificationPointsN2) return -1; else { - //TODO: es wäre geringfügig effizienter die Länge nicht mehrfach zu berechnen - if(n1.getConcept().getLength()<n2.getConcept().getLength()) + int lengthN1 = n1.getConcept().getLength(); + int lengthN2 = n2.getConcept().getLength(); + + if(lengthN1<lengthN2) return 1; - else if(n1.getConcept().getLength()>n2.getConcept().getLength()) + else if(lengthN1>lengthN2) return -1; else return conceptComparator.compare(n1.getConcept(), n2.getConcept()); } - } else - return conceptComparator.compare(n1.getConcept(), n2.getConcept()); + } else { + if(n1.isTooWeak() && !n2.isTooWeak()) + return -1; + else if(!n1.isTooWeak() && n2.isTooWeak()) + return 1; + else + return conceptComparator.compare(n1.getConcept(), n2.getConcept()); + } } - throw new RuntimeException("Cannot compare nodes, which have no evaluated quality or are too weak."); + throw new RuntimeException("Cannot compare nodes, which have no evaluated quality."); } - // alle NodeComparators führen zur gleichen Ordnung + // all stable node comparators lead to the same order @Override public boolean equals(Object o) { return (o instanceof NodeComparatorStable); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-03-05 18:29:41 UTC (rev 689) @@ -559,6 +559,14 @@ return atomicRolesList; } + public String getBaseURI() { + return reasoner.getBaseURI(); + } + + public Map<String, String> getPrefixes() { + return reasoner.getPrefixes(); + } + public long getInstanceCheckReasoningTimeNs() { return instanceCheckReasoningTimeNs; } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java 2008-03-05 18:29:41 UTC (rev 689) @@ -53,6 +53,7 @@ public String toString() { String str = ""; str += "score: " + score + "\n"; + str += "accuracy: " + (1 + classificationScore) + "\n"; str += "posAsPos: " + posAsPos + "\n"; str += "positive examples classified as negative: " + posAsNeg + "\n"; str += "negative examples classified as positive: " + negAsPos + "\n"; Modified: trunk/src/dl-learner/org/dllearner/parser/kb.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-03-05 18:29:41 UTC (rev 689) @@ -246,13 +246,14 @@ Description c,c1,c2; NamedClass ac; ObjectProperty ar; + DatatypeProperty dp; String s; int i; } { Top() {return new Thing();} | Bottom() {return new Nothing();} - | ac = AtomicConcept() {return ac;} + | LOOKAHEAD(2) ac = AtomicConcept() {return ac;} // | s=Id() {return new AtomicConcept(s);} // | s=String() {return new AtomicConcept(s);} // Parser geht bis zum n�chsten AND oder OR @@ -278,7 +279,9 @@ // | LE() i=Integer() s=Id() "." c=Concept() // {return new LessEqual(i,new AtomicRole(s),c);} | LE() i=Integer() ar=ObjectProperty() "." c=Concept() - {return new ObjectMaxCardinalityRestriction(i,ar,c);} + {return new ObjectMaxCardinalityRestriction(i,ar,c);} + | LOOKAHEAD(4) "(" dp=DatatypeProperty() "IS" "TRUE" ")" { return new BooleanValueRestriction(dp, true); } + | "(" dp=DatatypeProperty() "IS" "FALSE" ")" { return new BooleanValueRestriction(dp, false); } } void Or() : {} { <OR> } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-05 18:29:41 UTC (rev 689) @@ -301,8 +301,14 @@ } @Override - public SortedSet<Individual> retrieval(Description concept) { - return rs.retrieval(concept); + public SortedSet<Individual> retrieval(Description concept) throws ReasoningMethodUnsupportedException { +// return rs.retrieval(concept); + SortedSet<Individual> inds = new TreeSet<Individual>(); + for(Individual i : individuals) { + if(instanceCheck(concept,i)) + inds.add(i); + } + return inds; } /* Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-05 18:29:41 UTC (rev 689) @@ -546,7 +546,8 @@ @Override public SortedSet<Individual> retrieval(Description concept) { - OWLDescription d = getOWLAPIDescription(concept); +// OWLDescription d = getOWLAPIDescription(concept); + OWLDescription d = OWLAPIDescriptionConvertVisitor.getOWLDescription(concept); Set<OWLIndividual> individuals = null; try { individuals = reasoner.getIndividuals(d, false); Modified: trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2008-03-05 12:07:28 UTC (rev 688) +++ trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2008-03-05 18:29:41 UTC (rev 689) @@ -67,8 +67,35 @@ return ((NamedClass)concept1).getName().compareTo(((NamedClass)concept2).getName()); else return -1; + } else if(concept1 instanceof BooleanValueRestriction) { + if(concept2 instanceof Nothing || concept2 instanceof NamedClass) { + return 1; + } else if(concept2 instanceof BooleanValueRestriction) { + // first criterion: name of the properties + int cmp = rc.compare(((BooleanValueRestriction)concept1).getRestrictedPropertyExpresssion(), ((BooleanValueRestriction)concept2).getRestrictedPropertyExpresssion()); + + // second criterion: value of the properties (it should rarely happen that + // both boolean values are present since this is a contradiction or superfluous) + if(cmp == 0) { + boolean val1 = ((BooleanValueRestriction)concept1).getBooleanValue(); + boolean val2 = ((BooleanValueRestriction)concept2).getBooleanValue(); + if(val1) { + if(val2) + return 0; + else + return 1; + } else { + if(val2) + return -1; + else + return 0; + } + } else + return cmp; + } else + return -1; } else if(concept1 instanceof Thing) { - if(concept2 instanceof Nothing || concept2 instanceof NamedClass) + if(concept2 instanceof Nothing || concept2 instanceof NamedClass || concept2 instanceof BooleanValueRestriction) return 1; else if(concept2 instanceof Thing) return 0; @@ -104,17 +131,6 @@ return roleCompare; } else return -1; - } else if(concept1 instanceof BooleanValueRestriction) { - if(concept2.getChildren().size()<1 || concept2 instanceof Negation || concept2 instanceof ObjectQuantorRestriction) { - return 1; - } else if(concept2 instanceof BooleanValueRestriction) { - int cmp = rc.compare(((BooleanValueRestriction)concept1).getRestrictedPropertyExpresssion(), ((BooleanValueRestriction)concept2).getRestrictedPropertyExpresssion()); - if(cmp == 0) - return compare(concept1.getChild(0), concept2.getChild(0)); - else - return cmp; - } else - return -1; } else if(concept1 instanceof Intersection) { if(concept2.getChildren().size()<2) return 1; @@ -162,12 +178,6 @@ } else throw new RuntimeException(concept1.toString()); } - - /* - private int compareRole(Role r1, Role r2) { - return r1.toString().compareTo(r2.toString()); - } - */ // TODO: Vergleich zwischen ConceptComparators: immer identisch // (testen, ob das bessere Performance bringt) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |