From: <jen...@us...> - 2007-08-20 15:00:13
|
Revision: 8 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=8&view=rev Author: jenslehmann Date: 2007-08-20 08:00:11 -0700 (Mon, 20 Aug 2007) Log Message: ----------- removed more executable flags Property Changed: ---------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/ConfigurationOption.java trunk/src/dl-learner/org/dllearner/Info.java trunk/src/dl-learner/org/dllearner/LearningProblem.java trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/Score.java trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java Property changes on: trunk/src/dl-learner/org/dllearner/Config.java ___________________________________________________________________ Name: svn:executable - * Property changes on: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java ___________________________________________________________________ Name: svn:executable - * Property changes on: trunk/src/dl-learner/org/dllearner/ConfigurationOption.java ___________________________________________________________________ Name: svn:executable - * Property changes on: trunk/src/dl-learner/org/dllearner/Info.java ___________________________________________________________________ Name: svn:executable - * Property changes on: trunk/src/dl-learner/org/dllearner/LearningProblem.java ___________________________________________________________________ Name: svn:executable - * Property changes on: trunk/src/dl-learner/org/dllearner/Main.java ___________________________________________________________________ Name: svn:executable - * Property changes on: trunk/src/dl-learner/org/dllearner/Score.java ___________________________________________________________________ Name: svn:executable - * Property changes on: trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java ___________________________________________________________________ Name: svn:executable - * Property changes on: trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java ___________________________________________________________________ Name: svn:executable - * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-08-24 14:35:04
|
Revision: 54 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=54&view=rev Author: jenslehmann Date: 2007-08-24 07:35:02 -0700 (Fri, 24 Aug 2007) Log Message: ----------- fixed some warnings Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/dl/Individual.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrieval.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java Modified: trunk/src/dl-learner/org/dllearner/dl/Individual.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Individual.java 2007-08-24 14:17:37 UTC (rev 53) +++ trunk/src/dl-learner/org/dllearner/dl/Individual.java 2007-08-24 14:35:02 UTC (rev 54) @@ -17,7 +17,7 @@ * @author jl * */ -public class Individual implements KBElement, Comparable { +public class Individual implements KBElement, Comparable<Individual> { // public static int idCounter = 0; @@ -48,13 +48,14 @@ return name; } - public int compareTo(Object arg0) { - // TODO Auto-generated method stub - return name.compareTo(((Individual)arg0).name); + public int compareTo(Individual o) { + return name.compareTo(o.name); } - + @Override public boolean equals(Object o) { - return (compareTo(o)==0); + return (compareTo((Individual)o)==0); } + + } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-08-24 14:17:37 UTC (rev 53) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-08-24 14:35:02 UTC (rev 54) @@ -119,8 +119,9 @@ System.exit(0); } else { long importTime = System.currentTimeMillis() - importStartTime; - System.out.println("OK"); + System.out.println("OK (" + importTime + " ms)"); // (" + JenaOWLDIGConverter.nrOfStatementsLastConversion + " statements, "+ importTime + " ms)"); + } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrieval.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrieval.java 2007-08-24 14:17:37 UTC (rev 53) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrieval.java 2007-08-24 14:35:02 UTC (rev 54) @@ -31,7 +31,7 @@ // Algorithmus wird ueber Rekursion und // Delegation zur Helper-Klasse implementiert - public SortedSetTuple<String> calculateSetsADC(Concept concept, SortedSetTuple adcSet) { + public SortedSetTuple<String> calculateSetsADC(Concept concept, SortedSetTuple<String> adcSet) { if(concept instanceof Top) { return new SortedSetTuple<String>(abox.top,abox.bottom); } else if(concept instanceof Bottom) { Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2007-08-24 14:17:37 UTC (rev 53) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2007-08-24 14:35:02 UTC (rev 54) @@ -49,7 +49,7 @@ } public SortedSetTuple<Individual> doubleRetrieval(Concept concept, Concept adc) { - SortedSetTuple adcSet = fastRetrieval.calculateSets(adc); + SortedSetTuple<String> adcSet = fastRetrieval.calculateSets(adc); return Helper.getIndividualTuple(fastRetrieval.calculateSetsADC(concept, adcSet)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-08-26 11:09:13
|
Revision: 58 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=58&view=rev Author: jenslehmann Date: 2007-08-25 09:04:07 -0700 (Sat, 25 Aug 2007) Log Message: ----------- several changes to enable role hierarchy DIG reasoning Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-08-25 16:02:32 UTC (rev 57) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-08-25 16:04:07 UTC (rev 58) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner; import java.io.BufferedReader; @@ -265,6 +285,21 @@ System.out.println("OK (" + Helper.prettyPrintNanoSeconds(subHierTime, true, false) + ")"); + // prepare role hierarchy + System.out.print("Preparing Role Hierarchy ... "); + long roleHierTimeStart = System.nanoTime(); + try { + reasoner.prepareRoleHierarchy(); + // System.out.println(); + // System.out.println(reasoner.getRoleHierarchy()); + } catch (ReasoningMethodUnsupportedException e1) { + System.out.println("Tried to construct the role hierarchy, but the reasoner " + + "does not support it. Currently only DIG reasoners support this feature."); + } + long roleHierTime = System.nanoTime() - roleHierTimeStart; + System.out.println("OK (" + + Helper.prettyPrintNanoSeconds(roleHierTime, true, false) + ")"); + // Beispiele anzeigen boolean oneLineExampleInfo = true; int maxExampleStringLength = posExamples.toString().length(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-08-25 16:02:32 UTC (rev 57) +++ trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-08-25 16:04:07 UTC (rev 58) @@ -90,6 +90,10 @@ throw new ReasoningMethodUnsupportedException(); } + public void prepareRoleHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + public RoleHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-08-25 16:02:32 UTC (rev 57) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-08-25 16:04:07 UTC (rev 58) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.reasoning; import java.io.File; @@ -25,6 +45,7 @@ import org.dllearner.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Helper; +import org.dllearner.utilities.RoleComparator; import org.kr.dl.dig.v1_1.Concepts; import org.kr.dl.dig.v1_1.Csynonyms; import org.kr.dl.dig.v1_1.IdType; @@ -35,6 +56,12 @@ import org.kr.dl.dig.v1_1.Rsynonyms; import org.kr.dl.dig.v1_1.IndividualSetDocument.IndividualSet; +/** + * DIG 1.1 implementation of the reasoner interface. + * + * @author Jens Lehmann + * + */ public class DIGReasoner extends AbstractReasoner { // Variablen für Reasoner @@ -54,11 +81,19 @@ // unterschiedlich sind; // alternativ wäre auch eine Indizierung über Strings möglich ConceptComparator conceptComparator = new ConceptComparator(); + RoleComparator roleComparator = new RoleComparator(); SubsumptionHierarchy subsumptionHierarchy; + RoleHierarchy roleHierarchy; // enthält atomare Konzepte, sowie Top und Bottom Set<Concept> allowedConceptsInSubsumptionHierarchy; - // imports not supported yet + /** + * Creates a DIG reasoner object. + * + * @param kb Internal knowledge base. + * @param url URL of the DIG reasoner e.g. http://localhost:8081. + * @param imports Files to import (format and physical location of each file). + */ public DIGReasoner(KB kb, URL url, Map<URL,OntologyFileFormat> imports) { this.imports = imports; this.kb = kb; @@ -136,6 +171,10 @@ } + /** + * Construct a subsumption hierarchy using DIG queries. After calling this + * method one can ask for children or parents in the subsumption hierarchy. + */ public void prepareSubsumptionHierarchy() { allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); allowedConceptsInSubsumptionHierarchy.addAll(Config.Refinement.allowedConcepts); @@ -172,6 +211,26 @@ subsumptionHierarchy = new SubsumptionHierarchy(Config.Refinement.allowedConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); } + /** + * Constructs a role hierarchy using DIG queries. After calling this method, + * one can query parents or children of roles. + * + * @todo Does not yet take ignored roles into account. + */ + @Override + public void prepareRoleHierarchy() { + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); + + // Refinement atomarer Konzepte + for(AtomicRole role : atomicRoles) { + roleHierarchyDown.put(role, getMoreSpecialRolesDIG(role)); + roleHierarchyUp.put(role, getMoreGeneralRolesDIG(role)); + } + + roleHierarchy = new RoleHierarchy(Config.Refinement.allowedRoles, roleHierarchyUp, roleHierarchyDown); + } + // eigentlich müsste man klonen um sicherzustellen, dass der parent-Link // bei null bleibt; bei der aktuellen Implementierung ist der parent-Link // nicht immer null, was bei GP negative Auswirkungen haben könnte @@ -371,6 +430,11 @@ return subsumptionHierarchy; } + @Override + public RoleHierarchy getRoleHierarchy() { + return roleHierarchy; + } + private TreeSet<Concept> getMoreGeneralConceptsDIG(Concept concept) { String moreGeneralDIG = asksPrefix; moreGeneralDIG += "<parents id=\"query_parents\">"; @@ -448,6 +512,54 @@ return resultsSet; } + private TreeSet<AtomicRole> getMoreGeneralRolesDIG(AtomicRole role) { + String moreGeneralRolesDIG = asksPrefix; + moreGeneralRolesDIG += "<rparents id=\"query_parents\">"; + moreGeneralRolesDIG += "<ratom name=\"" + role.getName() + "\" />"; + moreGeneralRolesDIG += "</rparents></asks>"; + + ResponsesDocument rd = connector.asks(moreGeneralRolesDIG); + TreeSet<AtomicRole> resultsSet = new TreeSet<AtomicRole>(roleComparator); + Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); + + for(int i=0; i<rolesArray.length; i++) { + Named[] atoms = rolesArray[i].getRatomArray(); + + for(Named atom : atoms) { + AtomicRole ar = new AtomicRole(atom.getName()); + //if(Config.Refinement.allowedRoles.contains(ar)) + resultsSet.add(ar); + } + } + + // System.out.println(rd); + + return resultsSet; + } + + private TreeSet<AtomicRole> getMoreSpecialRolesDIG(AtomicRole role) { + String moreSpecialRolesDIG = asksPrefix; + moreSpecialRolesDIG += "<rchildren id=\"query_children\">"; + moreSpecialRolesDIG += "<ratom name=\"" + role.getName() + "\" />"; + moreSpecialRolesDIG += "</rchildren></asks>"; + + ResponsesDocument rd = connector.asks(moreSpecialRolesDIG); + TreeSet<AtomicRole> resultsSet = new TreeSet<AtomicRole>(roleComparator); + Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); + + for(int i=0; i<rolesArray.length; i++) { + Named[] atoms = rolesArray[i].getRatomArray(); + + for(Named atom : atoms) { + AtomicRole ar = new AtomicRole(atom.getName()); + //if(Config.Refinement.allowedRoles.contains(ar)) + resultsSet.add(ar); + } + } + + return resultsSet; + } + public boolean instanceCheck(Concept concept, Individual individual) { String instanceCheckDIG = asksPrefix; instanceCheckDIG += "<instance id= \"query_instance\">"; Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2007-08-25 16:02:32 UTC (rev 57) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2007-08-25 16:04:07 UTC (rev 58) @@ -76,5 +76,4 @@ public void prepareSubsumptionHierarchy() { // hier muss nichts getan werden } - } Modified: trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java 2007-08-25 16:02:32 UTC (rev 57) +++ trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java 2007-08-25 16:04:07 UTC (rev 58) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.reasoning; import java.util.Map; @@ -11,9 +31,9 @@ import org.dllearner.utilities.SortedSetTuple; /** - * Auflisten aller Reasoning-Methoden. + * Reasoner Interface. Lists all available reasoning methods. * - * @author jl + * @author Jens Lehmann * */ public interface Reasoner { @@ -25,6 +45,7 @@ // => erstellt auch vereinfachte Sichten auf Subsumptionhierarchie // (siehe einfacher Traversal in Diplomarbeit) public void prepareSubsumptionHierarchy(); + public void prepareRoleHierarchy() throws ReasoningMethodUnsupportedException; public boolean subsumes(Concept superConcept, Concept subConcept) throws ReasoningMethodUnsupportedException; Modified: trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java 2007-08-25 16:02:32 UTC (rev 57) +++ trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java 2007-08-25 16:04:07 UTC (rev 58) @@ -20,27 +20,74 @@ package org.dllearner.reasoning; import java.util.Set; +import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; -import org.dllearner.dl.AtomicConcept; import org.dllearner.dl.AtomicRole; -import org.dllearner.dl.Concept; import org.dllearner.utilities.RoleComparator; /** * Represents a hierarchy of roles. * + * @todo Currently, the role hierarchy pruning algorithm (analogous to the + * subsumption hierarchy) is not implemented. + * * @author Jens Lehmann * */ public class RoleHierarchy { RoleComparator rc = new RoleComparator(); + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp; + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown; + TreeSet<AtomicRole> mostGeneralRoles = new TreeSet<AtomicRole>(rc); + TreeSet<AtomicRole> mostSpecialRoles = new TreeSet<AtomicRole>(rc); public RoleHierarchy(Set<AtomicRole> atomicRoles, TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp , TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown) { + this.roleHierarchyUp = roleHierarchyUp; + this.roleHierarchyDown = roleHierarchyDown; - + // find most general and most special roles + for(AtomicRole role : atomicRoles) { + if(getMoreGeneralRoles(role).size()==0) + mostGeneralRoles.add(role); + if(getMoreSpecialRoles(role).size()==0) + mostSpecialRoles.add(role); + } } + @SuppressWarnings("unchecked") + public SortedSet<AtomicRole> getMoreGeneralRoles(AtomicRole role) { + // we clone all concepts before returning them such that they cannot be + // modified externally + return (TreeSet<AtomicRole>) roleHierarchyUp.get(role).clone(); + } + + @SuppressWarnings("unchecked") + public SortedSet<AtomicRole> getMoreSpecialRoles(AtomicRole role) { + return (TreeSet<AtomicRole>) roleHierarchyDown.get(role).clone(); + } + + @Override + public String toString() { + String str = ""; + for(AtomicRole role : mostGeneralRoles) { + str += toString(roleHierarchyDown, role, 0); + } + return str; + } + + private String toString(TreeMap<AtomicRole,TreeSet<AtomicRole>> hierarchy, AtomicRole role, int depth) { + String str = ""; + for(int i=0; i<depth; i++) + str += " "; + str += role.toString() + "\n"; + Set<AtomicRole> tmp = hierarchy.get(role); + if(tmp!=null) { + for(AtomicRole c : tmp) + str += toString(hierarchy, c, depth+1); + } + return str; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-08-27 15:04:43
|
Revision: 64 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=64&view=rev Author: jenslehmann Date: 2007-08-27 08:04:36 -0700 (Mon, 27 Aug 2007) Log Message: ----------- rebuild parser and fixed a number of warnings Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/Node.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparator.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparator2.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparatorStable.java trunk/src/dl-learner/org/dllearner/dl/All.java trunk/src/dl-learner/org/dllearner/dl/AtomicRole.java trunk/src/dl-learner/org/dllearner/dl/Bottom.java trunk/src/dl-learner/org/dllearner/dl/Concept.java trunk/src/dl-learner/org/dllearner/dl/ConceptAssertion.java trunk/src/dl-learner/org/dllearner/dl/Conjunction.java trunk/src/dl-learner/org/dllearner/dl/Disjunction.java trunk/src/dl-learner/org/dllearner/dl/Equality.java trunk/src/dl-learner/org/dllearner/dl/Exists.java trunk/src/dl-learner/org/dllearner/dl/FlatABox.java trunk/src/dl-learner/org/dllearner/dl/FunctionalRoleAxiom.java trunk/src/dl-learner/org/dllearner/dl/Inclusion.java trunk/src/dl-learner/org/dllearner/dl/InverseRole.java trunk/src/dl-learner/org/dllearner/dl/InverseRoleAxiom.java trunk/src/dl-learner/org/dllearner/dl/KB.java trunk/src/dl-learner/org/dllearner/dl/MultiConjunction.java trunk/src/dl-learner/org/dllearner/dl/MultiDisjunction.java trunk/src/dl-learner/org/dllearner/dl/Negation.java trunk/src/dl-learner/org/dllearner/dl/RoleAssertion.java trunk/src/dl-learner/org/dllearner/dl/SubRoleAxiom.java trunk/src/dl-learner/org/dllearner/dl/SymmetricRoleAxiom.java trunk/src/dl-learner/org/dllearner/dl/Top.java trunk/src/dl-learner/org/dllearner/dl/TransitiveRoleAxiom.java trunk/src/dl-learner/org/dllearner/parser/SimpleCharStream.java trunk/src/dl-learner/org/dllearner/parser/SimpleNode.java trunk/src/dl-learner/org/dllearner/parser/Token.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java Modified: trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java 2007-08-27 15:04:36 UTC (rev 64) @@ -124,10 +124,12 @@ errorRate = (double) errors/numberOfExamples; } + @Override public double getScore() { return score; } + @Override public String toString() { DecimalFormat df = new DecimalFormat("0.00"); String str = ""; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java 2007-08-27 15:04:36 UTC (rev 64) @@ -19,6 +19,7 @@ return 1; } + @Override public String toString() { return "ADC"; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/Node.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/Node.java 2007-08-27 15:04:36 UTC (rev 64) @@ -88,6 +88,7 @@ return isTooWeak; } + @Override public String toString() { String ret = concept.toString() + " [q:"; if(isTooWeak) Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparator.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparator.java 2007-08-27 15:04:36 UTC (rev 64) @@ -87,7 +87,9 @@ throw new RuntimeException("Cannot compare nodes, which have no evaluated quality or are too weak."); } + // alle NodeComparators führen zur gleichen Ordnung + @Override public boolean equals(Object o) { return (o instanceof NodeComparator); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparator2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparator2.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparator2.java 2007-08-27 15:04:36 UTC (rev 64) @@ -53,6 +53,7 @@ throw new RuntimeException("Cannot compare nodes, which have no evaluated quality or are too weak."); } + @Override public boolean equals(Object o) { return (o instanceof NodeComparator2); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparatorStable.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparatorStable.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/NodeComparatorStable.java 2007-08-27 15:04:36 UTC (rev 64) @@ -43,6 +43,7 @@ } // alle NodeComparators führen zur gleichen Ordnung + @Override public boolean equals(Object o) { return (o instanceof NodeComparatorStable); } Modified: trunk/src/dl-learner/org/dllearner/dl/All.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/All.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/All.java 2007-08-27 15:04:36 UTC (rev 64) @@ -84,6 +84,7 @@ } */ + @Override public String toString() { return "ALL " + role + "." + children.get(0).toString(); } Modified: trunk/src/dl-learner/org/dllearner/dl/AtomicRole.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/AtomicRole.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/AtomicRole.java 2007-08-27 15:04:36 UTC (rev 64) @@ -13,6 +13,7 @@ return 1; } + @Override public String toString() { String name = getName(); String prefixToHide = Helper.findPrefixToHide(name); Modified: trunk/src/dl-learner/org/dllearner/dl/Bottom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Bottom.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/Bottom.java 2007-08-27 15:04:36 UTC (rev 64) @@ -11,7 +11,7 @@ negSet = abox.top; } */ - + @Override public String toString() { return "BOTTOM"; } Modified: trunk/src/dl-learner/org/dllearner/dl/Concept.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Concept.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/Concept.java 2007-08-27 15:04:36 UTC (rev 64) @@ -158,6 +158,7 @@ * werden dabei nicht mitgeklont, sondern nur parent und children. */ @SuppressWarnings("unchecked") + @Override public Object clone() { Concept node = null; try { Modified: trunk/src/dl-learner/org/dllearner/dl/ConceptAssertion.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/ConceptAssertion.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/ConceptAssertion.java 2007-08-27 15:04:36 UTC (rev 64) @@ -22,6 +22,7 @@ return 1 + concept.getLength(); } + @Override public String toString() { return concept.toString() + "(" + individual + ")"; } Modified: trunk/src/dl-learner/org/dllearner/dl/Conjunction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Conjunction.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/Conjunction.java 2007-08-27 15:04:36 UTC (rev 64) @@ -20,6 +20,7 @@ addChild(c2); } + @Override public String toString() { return "(" + children.get(0).toString() + " AND " + children.get(1).toString() + ")"; } Modified: trunk/src/dl-learner/org/dllearner/dl/Disjunction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Disjunction.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/Disjunction.java 2007-08-27 15:04:36 UTC (rev 64) @@ -19,6 +19,7 @@ addChild(c2); } + @Override public String toString() { return "(" + children.get(0).toString() + " OR " + children.get(1).toString() + ")"; } Modified: trunk/src/dl-learner/org/dllearner/dl/Equality.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Equality.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/Equality.java 2007-08-27 15:04:36 UTC (rev 64) @@ -22,6 +22,7 @@ return 1 + concept1.getLength() + concept2.getLength(); } + @Override public String toString() { return concept1.toString() + " = " + concept2.toString(); } Modified: trunk/src/dl-learner/org/dllearner/dl/Exists.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Exists.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/Exists.java 2007-08-27 15:04:36 UTC (rev 64) @@ -85,6 +85,7 @@ } */ + @Override public String toString() { return "EXISTS " + role + "." + children.get(0).toString(); } Modified: trunk/src/dl-learner/org/dllearner/dl/FlatABox.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/FlatABox.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/FlatABox.java 2007-08-27 15:04:36 UTC (rev 64) @@ -76,6 +76,7 @@ return (String) roleArray[nr]; } + @Override public String toString() { String output = ""; output += "domain: " + domain.toString() + "\n"; Modified: trunk/src/dl-learner/org/dllearner/dl/FunctionalRoleAxiom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/FunctionalRoleAxiom.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/FunctionalRoleAxiom.java 2007-08-27 15:04:36 UTC (rev 64) @@ -16,6 +16,7 @@ return 1 + role.getLength(); } + @Override public String toString() { return "Functional(" + role.toString() + ")"; } Modified: trunk/src/dl-learner/org/dllearner/dl/Inclusion.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Inclusion.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/Inclusion.java 2007-08-27 15:04:36 UTC (rev 64) @@ -22,6 +22,7 @@ return 1 + subConcept.getLength() + superConcept.getLength(); } + @Override public String toString() { return subConcept.toString() + " SUBCONCEPTOF " + superConcept.toString(); } Modified: trunk/src/dl-learner/org/dllearner/dl/InverseRole.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/InverseRole.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/InverseRole.java 2007-08-27 15:04:36 UTC (rev 64) @@ -22,6 +22,7 @@ return 2; } + @Override public String toString() { return getName() + "-"; } Modified: trunk/src/dl-learner/org/dllearner/dl/InverseRoleAxiom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/InverseRoleAxiom.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/InverseRoleAxiom.java 2007-08-27 15:04:36 UTC (rev 64) @@ -22,6 +22,7 @@ return 1 + role.getLength() + inverseRole.getLength(); } + @Override public String toString() { return "Inverse(" + inverseRole + "," + role.toString() + ")"; } Modified: trunk/src/dl-learner/org/dllearner/dl/KB.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/KB.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/KB.java 2007-08-27 15:04:36 UTC (rev 64) @@ -156,6 +156,7 @@ return length; } + @Override public String toString() { String str = "TBox["+tbox.size()+"]:\n"; for(Axiom a : tbox) Modified: trunk/src/dl-learner/org/dllearner/dl/MultiConjunction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/MultiConjunction.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/MultiConjunction.java 2007-08-27 15:04:36 UTC (rev 64) @@ -33,6 +33,7 @@ return length + children.size() - 1; } + @Override public String toString() { if(children.size()==0) return "EMPTY_AND"; Modified: trunk/src/dl-learner/org/dllearner/dl/MultiDisjunction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/MultiDisjunction.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/MultiDisjunction.java 2007-08-27 15:04:36 UTC (rev 64) @@ -35,6 +35,7 @@ return length + children.size() - 1; } + @Override public String toString() { if(children.size()==0) return "EMPTY_OR"; Modified: trunk/src/dl-learner/org/dllearner/dl/Negation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Negation.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/Negation.java 2007-08-27 15:04:36 UTC (rev 64) @@ -16,6 +16,7 @@ addChild(c); } + @Override public String toString() { return "(NOT " +children.get(0).toString() + ")"; } Modified: trunk/src/dl-learner/org/dllearner/dl/RoleAssertion.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/RoleAssertion.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/RoleAssertion.java 2007-08-27 15:04:36 UTC (rev 64) @@ -28,6 +28,7 @@ return 2 + role.getLength(); } + @Override public String toString() { return role.toString() + "(" + individual1 + "," + individual2 +")"; } Modified: trunk/src/dl-learner/org/dllearner/dl/SubRoleAxiom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/SubRoleAxiom.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/SubRoleAxiom.java 2007-08-27 15:04:36 UTC (rev 64) @@ -22,6 +22,7 @@ return 1 + role.getLength() + subRole.getLength(); } + @Override public String toString() { return "Subrole(" + subRole + "," + role.toString() + ")"; } Modified: trunk/src/dl-learner/org/dllearner/dl/SymmetricRoleAxiom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/SymmetricRoleAxiom.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/SymmetricRoleAxiom.java 2007-08-27 15:04:36 UTC (rev 64) @@ -16,6 +16,7 @@ return 1 + role.getLength(); } + @Override public String toString() { return "Symmetric(" + role.toString() + ")"; } Modified: trunk/src/dl-learner/org/dllearner/dl/Top.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/Top.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/Top.java 2007-08-27 15:04:36 UTC (rev 64) @@ -12,6 +12,7 @@ } */ + @Override public String toString() { return "TOP"; } Modified: trunk/src/dl-learner/org/dllearner/dl/TransitiveRoleAxiom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/TransitiveRoleAxiom.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/dl/TransitiveRoleAxiom.java 2007-08-27 15:04:36 UTC (rev 64) @@ -16,6 +16,7 @@ return role; } + @Override public String toString() { return "Transitive(" + role.toString() + ")"; } Modified: trunk/src/dl-learner/org/dllearner/parser/SimpleCharStream.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/SimpleCharStream.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/parser/SimpleCharStream.java 2007-08-27 15:04:36 UTC (rev 64) @@ -6,6 +6,7 @@ * contain only ASCII characters (without unicode processing). */ +@SuppressWarnings("all") public class SimpleCharStream { public static final boolean staticFlag = true; Modified: trunk/src/dl-learner/org/dllearner/parser/SimpleNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/SimpleNode.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/parser/SimpleNode.java 2007-08-27 15:04:36 UTC (rev 64) @@ -2,6 +2,7 @@ package org.dllearner.parser; +@SuppressWarnings("all") public class SimpleNode implements Node { protected Node parent; protected Node[] children; Modified: trunk/src/dl-learner/org/dllearner/parser/Token.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/Token.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/parser/Token.java 2007-08-27 15:04:36 UTC (rev 64) @@ -4,7 +4,7 @@ /** * Describes the input token stream. */ - +@SuppressWarnings("all") public class Token { /** Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-08-27 15:04:36 UTC (rev 64) @@ -560,6 +560,7 @@ return resultsSet; } + @Override public boolean instanceCheck(Concept concept, Individual individual) { String instanceCheckDIG = asksPrefix; instanceCheckDIG += "<instance id= \"query_instance\">"; @@ -570,6 +571,7 @@ return parseBooleanAnswer(instanceCheckDIG); } + @Override public Set<Individual> instanceCheck(Concept concept, Set<Individual> individuals) { String instanceCheckDIG = asksPrefix; int id = 0; @@ -596,6 +598,7 @@ return returnSet; } + @Override public SortedSet<Individual> retrieval(Concept concept) { String retrievalDIG = asksPrefix; @@ -614,6 +617,7 @@ } // ToDo: gibt momentan nur einen Wert bei äquivalenten Klassen aus + @Override public Set<AtomicConcept> getConcepts(Individual individual) { String typesDIG = asksPrefix; typesDIG += "<types id=\"query_types\">"; @@ -646,6 +650,7 @@ // keine getter um ein IndividualPairSet zu finden; in der XSD-Datei ist // das in Responsegroup auch nicht definiert // => deswegen wird hier die XML-Cursor-API verwendet + @Override public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) { String relatedIndividualsDIG = asksPrefix; relatedIndividualsDIG += "<relatedIndividuals id=\"related_individuals\">"; @@ -691,7 +696,7 @@ return resultMap; } - + @Override public boolean isSatisfiable() { String satisfiableDIG = asksPrefix; // wenn Top erfüllbar ist, dann gibt es auch ein Modell für die KB Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2007-08-27 15:04:36 UTC (rev 64) @@ -44,15 +44,18 @@ return ReasonerType.FAST_RETRIEVAL; } + @Override public SortedSetTuple<Individual> doubleRetrieval(Concept concept) { return Helper.getIndividualTuple(fastRetrieval.calculateSets(concept)); } + @Override public SortedSetTuple<Individual> doubleRetrieval(Concept concept, Concept adc) { SortedSetTuple<String> adcSet = fastRetrieval.calculateSets(adc); return Helper.getIndividualTuple(fastRetrieval.calculateSetsADC(concept, adcSet)); } + @Override public SortedSet<Individual> retrieval(Concept concept) { return Helper.getIndividualSet(fastRetrieval.calculateSets(concept).getPosSet()); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2007-08-27 15:04:36 UTC (rev 64) @@ -273,6 +273,7 @@ subsumptionHierarchy = new org.dllearner.reasoning.SubsumptionHierarchy(atomicConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); } + @Override public SortedSet<Individual> retrieval(Concept c) { SortedSet<Individual> result = new TreeSet<Individual>(); Description d = getKAON2Description(c); @@ -358,6 +359,7 @@ throw new Error("Subsumption Error in KAON2."); } + @Override public boolean isSatisfiable() { try { return kaon2Reasoner.isSatisfiable(); @@ -396,6 +398,7 @@ } */ + @Override public org.dllearner.reasoning.SubsumptionHierarchy getSubsumptionHierarchy() { return subsumptionHierarchy; } @@ -428,6 +431,7 @@ } } + @Override public Map<org.dllearner.dl.Individual, SortedSet<org.dllearner.dl.Individual>> getRoleMembers(AtomicRole atomicRole) { Map<org.dllearner.dl.Individual, SortedSet<org.dllearner.dl.Individual>> returnMap = new TreeMap<org.dllearner.dl.Individual, SortedSet<org.dllearner.dl.Individual>>(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java 2007-08-27 15:04:36 UTC (rev 64) @@ -97,6 +97,7 @@ subsumptionHierarchyUp = hierarchyUpNew; } + @Override public String toString() { return toString(false); } Modified: trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2007-08-27 11:41:10 UTC (rev 63) +++ trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2007-08-27 15:04:36 UTC (rev 64) @@ -156,6 +156,7 @@ // TODO: Vergleich zwischen ConceptComparators: immer identisch // (testen, ob das bessere Performance bringt) + @Override public boolean equals(Object o) { return (o instanceof ConceptComparator); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-08-29 09:15:31
|
Revision: 103 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=103&view=rev Author: jenslehmann Date: 2007-08-29 02:15:29 -0700 (Wed, 29 Aug 2007) Log Message: ----------- - next version of statistics script (not fully working yet) - some smaller overall improvements Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/Info.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-08-29 08:57:59 UTC (rev 102) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-08-29 09:15:29 UTC (rev 103) @@ -56,7 +56,7 @@ private List<String> setOptions; public ConfigurationManager() { - this(null); + this(new LinkedList<ConfigurationOption>()); } public ConfigurationManager(Collection<ConfigurationOption> confOptions) { Modified: trunk/src/dl-learner/org/dllearner/Info.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Info.java 2007-08-29 08:57:59 UTC (rev 102) +++ trunk/src/dl-learner/org/dllearner/Info.java 2007-08-29 09:15:29 UTC (rev 103) @@ -3,6 +3,6 @@ package org.dllearner; public class Info { - public static final String build = "2007-08-28"; + public static final String build = "2007-08-29"; } \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-08-29 08:57:59 UTC (rev 102) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-08-29 09:15:29 UTC (rev 103) @@ -819,8 +819,7 @@ } public Score getSolutionScore() { - // TODO Auto-generated method stub - return null; + return learningProblem.computeScore(getBestSolution()); } public void stop() { Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-08-29 08:57:59 UTC (rev 102) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-08-29 09:15:29 UTC (rev 103) @@ -101,6 +101,7 @@ rd = ResponsesDocument.Factory.parse(answer); } catch (XmlException e) { e.printStackTrace(); + System.err.println("Exception occured when receiving the following string:\n" + answer); } return rd; } Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-08-29 08:57:59 UTC (rev 102) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-08-29 09:15:29 UTC (rev 103) @@ -26,24 +26,29 @@ import java.util.List; import java.util.Map; import java.util.SortedSet; -import java.util.TreeSet; - import org.dllearner.Config; +import org.dllearner.ConfigurationManager; import org.dllearner.LearningProblem; import org.dllearner.Main; import org.dllearner.OntologyFileFormat; +import org.dllearner.Score; +import org.dllearner.Config.Algorithm; +import org.dllearner.algorithms.LearningAlgorithm; +import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.dl.AtomicConcept; import org.dllearner.dl.Individual; import org.dllearner.dl.KB; import org.dllearner.parser.DLLearner; +import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.Reasoner; import org.dllearner.reasoning.ReasoningMethodUnsupportedException; import org.dllearner.reasoning.ReasoningService; /** * Utility script for creating statistics for publications. - * (Warning: Scripts may run for several hours.) + * (Warning: Scripts may run for several hours. Results may change + * when core algorithms are modified.) * * @author Jens Lehmann * @@ -91,77 +96,140 @@ // - more? String exampleBaseDir = "examples/"; + String gnuplotBaseDir = "log/gnuplot/"; + String statBaseDir = "log/stat/"; File[] confFiles = new File[1]; - confFiles[0] = new File(exampleBaseDir, "trains/trains.conf"); + confFiles[0] = new File(exampleBaseDir + "trains", "trains_owl.conf"); - /* - Stat[][] statAr = new Stat[4][3]; - File[][] fileAr = new File[4][3]; + String[] examples = new String[1]; + examples[0] = "trains"; - fileAr[0][0] = new File(baseDir, "gnuplot/hybrid100classification.data"); - fileAr[0][1] = new File(baseDir, "gnuplot/hybrid100length.data"); - fileAr[0][2] = new File(baseDir, "gnuplot/hybrid100runtime.data"); - fileAr[1][0] = new File(baseDir, "gnuplot/hybrid50classification.data"); - fileAr[1][1] = new File(baseDir, "gnuplot/hybrid50length.data"); - fileAr[1][2] = new File(baseDir, "gnuplot/hybrid50runtime.data"); - fileAr[2][0] = new File(baseDir, "gnuplot/gpclassification.data"); - fileAr[2][1] = new File(baseDir, "gnuplot/gplength.data"); - fileAr[2][2] = new File(baseDir, "gnuplot/gpruntime.data"); - */ + String[] algorithms = new String[3]; + algorithms[0] = "refinement"; + algorithms[1] = "gp"; + algorithms[2] = "hybrid"; - // set reasoner URL - try { - Config.digReasonerURL = new URL("http://localhost:8081"); - } catch (MalformedURLException e) { - e.printStackTrace(); - } + int[] algorithmRuns = {1,10,10}; - String fatherConfFile = "examples/father2.conf"; + // do not plot anything + // File[][][] gnuplotFiles = new File[examples.length][algorithms.length][3]; + // for(int i=0; i<examples.length; i++) { + // for(int j=0; j<algorithms.length; j++) { + // gnuplotFiles[i][j][0] = new File(gnuplotBaseDir, examples[i] + "_classification_" + algorithms[j] + ".data"); + // gnuplotFiles[i][j][1] = new File(gnuplotBaseDir, examples[i] + "_length_" + algorithms[j] + ".data"); + // gnuplotFiles[i][j][2] = new File(gnuplotBaseDir, examples[i] + "_runtime_" + algorithms[j] + ".data"); + // } + //} - // file is parsed, but we use only the specified examples really - // (everything else is ignored) - DLLearner.parseFile(fatherConfFile); - // DLLearner.parseFile(fatherConfFile); + File statFile = new File(statBaseDir, "statistics.txt"); + String statString = "**automatically generated statistics**\n\n"; - Map<URL, OntologyFileFormat> imports = getImports(DLLearner.getFunctionCalls()); + // just set default options + ConfigurationManager confMgr = new ConfigurationManager(); + confMgr.applyOptions(); - // initialise reasoner - Reasoner reasoner = Main.createReasoner(new KB(), imports); - ReasoningService rs = new ReasoningService(reasoner); - - Main.autoDetectConceptsAndRoles(rs); - if (Config.Refinement.improveSubsumptionHierarchy) { - try { - reasoner.prepareSubsumptionHierarchy(); - reasoner.prepareRoleHierarchy(); - reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - e.printStackTrace(); + for(int exampleNr=0; exampleNr < examples.length; exampleNr++) { + + // parse current conf file + DLLearner.parseFile(confFiles[exampleNr].toString()); + + // read which files were imported (internal KB is ignored) and initialise reasoner + Map<URL, OntologyFileFormat> imports = getImports(DLLearner.getFunctionCalls(), confFiles[exampleNr]); + + // detect specified positive and negative examples + SortedSet<Individual> positiveExamples = null; + SortedSet<Individual> negativeExamples = null; + Map<AtomicConcept,SortedSet<Individual>> posExamplesTmp = DLLearner.getPositiveExamples(); + Map<AtomicConcept,SortedSet<Individual>> negExamplesTmp = DLLearner.getNegativeExamples(); + for (AtomicConcept target : posExamplesTmp.keySet()) + positiveExamples = posExamplesTmp.get(target); + for (AtomicConcept target : negExamplesTmp.keySet()) + negativeExamples = negExamplesTmp.get(target); + int nrOfExamples = positiveExamples.size() + negativeExamples.size(); + + statString += "example: " + examples[exampleNr] + "\n\n"; + + for(int algorithmNr=0; algorithmNr < algorithms.length; algorithmNr++) { + + // create reasoner (this has to be done in this inner loop to + // ensure that none of the algorithm benefits from e.g. caching + // of previous reasoning requests + Reasoner reasoner = Main.createReasoner(new KB(), imports); + ReasoningService rs = new ReasoningService(reasoner); + + // prepare reasoner for using subsumption and role hierarchy + // TODO: currently, it is a small unfairness that each algorithm + // uses the same reasoning object (e.g. the second algorithm may + // have a small advantage if the reasoner cached reasoning requests + // of the first algorithm) + Main.autoDetectConceptsAndRoles(rs); + try { + reasoner.prepareSubsumptionHierarchy(); + reasoner.prepareRoleHierarchy(); + // improving the subsumption hierarchy makes only sense + // for the refinement based algorithm + if(algorithmNr==0) + reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + e.printStackTrace(); + } + + // create learning problem + LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); + + LearningAlgorithm learningAlgorithm = null; + if(algorithmNr==0) { + Config.algorithm = Algorithm.REFINEMENT; + learningAlgorithm = new ROLearner(learningProblem); + } else if(algorithmNr==1) { + Config.algorithm = Algorithm.GP; + Config.GP.numberOfIndividuals = 21; + Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; + Config.GP.refinementProbability = 0; + Config.GP.mutationProbability = 0.02; + Config.GP.crossoverProbability = 0.8; + Config.GP.hillClimbingProbability = 0; + learningAlgorithm = new GP(learningProblem); + } else if(algorithmNr==2) { + Config.algorithm = Algorithm.HYBRID_GP; + Config.GP.numberOfIndividuals = 11; + Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; + Config.GP.refinementProbability = 0.65; + Config.GP.mutationProbability = 0.02; + Config.GP.crossoverProbability = 0.2; + Config.GP.hillClimbingProbability = 0; + learningAlgorithm = new GP(learningProblem); + } + + rs.resetStatistics(); + long algorithmStartTime = System.nanoTime(); + learningAlgorithm.start(); + long algorithmTime = System.nanoTime() - algorithmStartTime; + // long algorithmTimeSeconds = algorithmTime / 1000000000; + + int conceptLength = learningAlgorithm.getBestSolution().getLength(); + Score bestScore = learningAlgorithm.getSolutionScore(); + int misClassifications = bestScore.getCoveredNegatives().size() + + bestScore.getNotCoveredPositives().size(); + double classificationRatePercent = 100 * ((nrOfExamples - misClassifications) / (double) nrOfExamples); + + statString += "algorithm: " + algorithms[algorithmNr] + "\n"; + statString += "classification: " + classificationRatePercent + "%\n"; + statString += "concept length: " + conceptLength + "\n"; + statString += "runtime: " + Helper.prettyPrintNanoSeconds(algorithmTime) + "s\n\n"; + + // free knowledge base to avoid memory leaks + ((DIGReasoner) reasoner).releaseKB(); + } + } - SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); - SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); - Map<AtomicConcept,SortedSet<Individual>> posExamplesTmp = DLLearner.getPositiveExamples(); - Map<AtomicConcept,SortedSet<Individual>> negExamplesTmp = DLLearner.getNegativeExamples(); - - for (AtomicConcept target : posExamplesTmp.keySet()) - positiveExamples = posExamplesTmp.get(target); - - for (AtomicConcept target : negExamplesTmp.keySet()) - negativeExamples = negExamplesTmp.get(target); - - - - LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); - ROLearner learner = new ROLearner(learningProblem); - learner.start(); - System.out.println(learner.getBestSolution().toString()); - + Main.createFile(statFile, statString); } - private static Map<URL, OntologyFileFormat> getImports(List<List<String>> functionCalls) { + private static Map<URL, OntologyFileFormat> getImports(List<List<String>> functionCalls, File confFile) { Map<URL, OntologyFileFormat> importedFiles = new HashMap<URL, OntologyFileFormat>(); OntologyFileFormat format = null; @@ -170,15 +238,13 @@ for (List<String> call : functionCalls) { if(call.get(0).equals("import")) { - // alte Methode mit file statt URI - // File f = new File(baseDir, call.get(1)); - + try { String fileString = call.get(1); if(fileString.startsWith("http:")) { url = new URL(fileString); } else { - File f = new File("examples", call.get(1)); + File f = new File(confFile.getParent(), call.get(1)); url = f.toURI().toURL(); } } catch (MalformedURLException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-08-29 13:42:18
|
Revision: 106 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=106&view=rev Author: jenslehmann Date: 2007-08-29 06:40:11 -0700 (Wed, 29 Aug 2007) Log Message: ----------- statistics script (working version) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java trunk/src/dl-learner/org/dllearner/parser/dllearner.jj trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java trunk/src/dl-learner/org/dllearner/utilities/Stat.java Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-08-29 13:40:11 UTC (rev 106) @@ -148,6 +148,13 @@ } public static void parseFile(String filename) { + + positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + confOptions = new LinkedList<ConfigurationOption>(); + functionCalls = new LinkedList<List<String>>(); + kb = new KB(); + try { if(constructorCalled) DLLearner.ReInit(new FileInputStream(filename)); @@ -1577,25 +1584,6 @@ finally { jj_save(11, xla); } } - static final private boolean jj_3R_18() { - if (jj_3R_12()) return true; - return false; - } - - static final private boolean jj_3R_35() { - if (jj_3R_49()) return true; - if (jj_3R_22()) return true; - if (jj_3R_17()) return true; - if (jj_scan_token(COMMAND_END)) return true; - if (jj_3R_14()) return true; - return false; - } - - static final private boolean jj_3R_26() { - if (jj_3R_4()) return true; - return false; - } - static final private boolean jj_3R_34() { if (jj_3R_39()) return true; if (jj_3R_14()) return true; @@ -2028,6 +2016,25 @@ return false; } + static final private boolean jj_3R_18() { + if (jj_3R_12()) return true; + return false; + } + + static final private boolean jj_3R_35() { + if (jj_3R_49()) return true; + if (jj_3R_22()) return true; + if (jj_3R_17()) return true; + if (jj_scan_token(COMMAND_END)) return true; + if (jj_3R_14()) return true; + return false; + } + + static final private boolean jj_3R_26() { + if (jj_3R_4()) return true; + return false; + } + static private boolean jj_initialized_once = false; static public DLLearnerTokenManager token_source; static SimpleCharStream jj_input_stream; Modified: trunk/src/dl-learner/org/dllearner/parser/dllearner.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-08-29 13:40:11 UTC (rev 106) @@ -166,6 +166,13 @@ } public static void parseFile(String filename) { + + positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + confOptions = new LinkedList<ConfigurationOption>(); + functionCalls = new LinkedList<List<String>>(); + kb = new KB(); + try { if(constructorCalled) DLLearner.ReInit(new FileInputStream(filename)); Modified: trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt 2007-08-29 13:40:11 UTC (rev 106) @@ -162,6 +162,13 @@ } public static void parseFile(String filename) { + + positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + confOptions = new LinkedList<ConfigurationOption>(); + functionCalls = new LinkedList<List<String>>(); + kb = new KB(); + try { if(constructorCalled) DLLearner.ReInit(new FileInputStream(filename)); Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-08-29 13:40:11 UTC (rev 106) @@ -99,11 +99,13 @@ String gnuplotBaseDir = "log/gnuplot/"; String statBaseDir = "log/stat/"; - File[] confFiles = new File[1]; - confFiles[0] = new File(exampleBaseDir + "trains", "trains_owl.conf"); + File[] confFiles = new File[2]; + confFiles[0] = new File(exampleBaseDir + "trains", "trains_owl.conf"); + confFiles[1] = new File(exampleBaseDir, "father2.conf"); - String[] examples = new String[1]; + String[] examples = new String[2]; examples[0] = "trains"; + examples[1] = "father"; String[] algorithms = new String[3]; algorithms[0] = "refinement"; @@ -151,77 +153,89 @@ statString += "example: " + examples[exampleNr] + "\n\n"; for(int algorithmNr=0; algorithmNr < algorithms.length; algorithmNr++) { - - // create reasoner (this has to be done in this inner loop to - // ensure that none of the algorithm benefits from e.g. caching - // of previous reasoning requests - Reasoner reasoner = Main.createReasoner(new KB(), imports); - ReasoningService rs = new ReasoningService(reasoner); + + Stat classification = new Stat(); + Stat length = new Stat(); + Stat runtime = new Stat(); - // prepare reasoner for using subsumption and role hierarchy - // TODO: currently, it is a small unfairness that each algorithm - // uses the same reasoning object (e.g. the second algorithm may - // have a small advantage if the reasoner cached reasoning requests - // of the first algorithm) - Main.autoDetectConceptsAndRoles(rs); - try { - reasoner.prepareSubsumptionHierarchy(); - reasoner.prepareRoleHierarchy(); - // improving the subsumption hierarchy makes only sense - // for the refinement based algorithm - if(algorithmNr==0) - reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - e.printStackTrace(); - } + for(int runNr=0; runNr < algorithmRuns[algorithmNr]; runNr++) { + + // create reasoner (this has to be done in this inner loop to + // ensure that none of the algorithm benefits from e.g. caching + // of previous reasoning requests + Reasoner reasoner = Main.createReasoner(new KB(), imports); + ReasoningService rs = new ReasoningService(reasoner); + + // prepare reasoner for using subsumption and role hierarchy + // TODO: currently, it is a small unfairness that each algorithm + // uses the same reasoning object (e.g. the second algorithm may + // have a small advantage if the reasoner cached reasoning requests + // of the first algorithm) + Main.autoDetectConceptsAndRoles(rs); + try { + reasoner.prepareSubsumptionHierarchy(); + reasoner.prepareRoleHierarchy(); + // improving the subsumption hierarchy makes only sense + // for the refinement based algorithm + if(algorithmNr==0) + reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + e.printStackTrace(); + } + + // create learning problem + LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); + + LearningAlgorithm learningAlgorithm = null; + if(algorithmNr==0) { + Config.algorithm = Algorithm.REFINEMENT; + learningAlgorithm = new ROLearner(learningProblem); + } else if(algorithmNr==1) { + Config.algorithm = Algorithm.GP; + Config.GP.numberOfIndividuals = 21; + Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; + Config.GP.refinementProbability = 0; + Config.GP.mutationProbability = 0.02; + Config.GP.crossoverProbability = 0.8; + Config.GP.hillClimbingProbability = 0; + learningAlgorithm = new GP(learningProblem); + } else if(algorithmNr==2) { + Config.algorithm = Algorithm.HYBRID_GP; + Config.GP.numberOfIndividuals = 11; + Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; + Config.GP.refinementProbability = 0.65; + Config.GP.mutationProbability = 0.02; + Config.GP.crossoverProbability = 0.2; + Config.GP.hillClimbingProbability = 0; + learningAlgorithm = new GP(learningProblem); + } + + rs.resetStatistics(); + long algorithmStartTime = System.nanoTime(); + learningAlgorithm.start(); + long algorithmTime = System.nanoTime() - algorithmStartTime; + // long algorithmTimeSeconds = algorithmTime / 1000000000; + + int conceptLength = learningAlgorithm.getBestSolution().getLength(); + Score bestScore = learningAlgorithm.getSolutionScore(); + int misClassifications = bestScore.getCoveredNegatives().size() + + bestScore.getNotCoveredPositives().size(); + double classificationRatePercent = 100 * ((nrOfExamples - misClassifications) / (double) nrOfExamples); + + classification.addNumber(classificationRatePercent); + length.addNumber(conceptLength); + runtime.addNumber(algorithmTime); + + // free knowledge base to avoid memory leaks + ((DIGReasoner) reasoner).releaseKB(); - // create learning problem - LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); + } - LearningAlgorithm learningAlgorithm = null; - if(algorithmNr==0) { - Config.algorithm = Algorithm.REFINEMENT; - learningAlgorithm = new ROLearner(learningProblem); - } else if(algorithmNr==1) { - Config.algorithm = Algorithm.GP; - Config.GP.numberOfIndividuals = 21; - Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; - Config.GP.refinementProbability = 0; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.8; - Config.GP.hillClimbingProbability = 0; - learningAlgorithm = new GP(learningProblem); - } else if(algorithmNr==2) { - Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = 11; - Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; - Config.GP.refinementProbability = 0.65; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.2; - Config.GP.hillClimbingProbability = 0; - learningAlgorithm = new GP(learningProblem); - } - - rs.resetStatistics(); - long algorithmStartTime = System.nanoTime(); - learningAlgorithm.start(); - long algorithmTime = System.nanoTime() - algorithmStartTime; - // long algorithmTimeSeconds = algorithmTime / 1000000000; - - int conceptLength = learningAlgorithm.getBestSolution().getLength(); - Score bestScore = learningAlgorithm.getSolutionScore(); - int misClassifications = bestScore.getCoveredNegatives().size() - + bestScore.getNotCoveredPositives().size(); - double classificationRatePercent = 100 * ((nrOfExamples - misClassifications) / (double) nrOfExamples); - - statString += "algorithm: " + algorithms[algorithmNr] + "\n"; - statString += "classification: " + classificationRatePercent + "%\n"; - statString += "concept length: " + conceptLength + "\n"; - statString += "runtime: " + Helper.prettyPrintNanoSeconds(algorithmTime) + "s\n\n"; + statString += "algorithm: " + algorithms[algorithmNr] + " (runs: " + algorithmRuns[algorithmNr] + ")\n"; + statString += "classification: " + classification.getMean() + "% (standard deviation: " + classification.getStandardDeviation() + "%)\n"; + statString += "concept length: " + length.getMean() + " (standard deviation: " + length.getStandardDeviation() + ")\n"; + statString += "runtime: " + Helper.prettyPrintNanoSeconds(Math.round(runtime.getMean())) + " (standard deviation: " + Helper.prettyPrintNanoSeconds(Math.round(runtime.getStandardDeviation())) + ")\n\n"; - // free knowledge base to avoid memory leaks - ((DIGReasoner) reasoner).releaseKB(); - } } Modified: trunk/src/dl-learner/org/dllearner/utilities/Stat.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Stat.java 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/utilities/Stat.java 2007-08-29 13:40:11 UTC (rev 106) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.utilities; /** @@ -57,20 +77,21 @@ * * @return The stanard deviation of all numbers. */ - public double getStandardDeviation() { - // TODO: Standardabweichung ist anscheinend nicht korrekt, siehe - // http://de.wikipedia.org/wiki/Standardabweichung. Es muss N-1 verwendet - // werden. - /* - double mean = getMean(); - double tmp = squareSum / count - mean * mean; - if(tmp==0) - return 0; - else - return Math.sqrt(tmp); - */ - // korrekter Code nach http://de.wikipedia.org/wiki/Standardabweichung - return Math.sqrt((count*squareSum-sum*sum)/(count*(count-1))); + public double getStandardDeviation() { + if(count <= 1) + return 0.0; + + // formula from http://de.wikipedia.org/wiki/Standardabweichung + double val = (count*squareSum-sum*sum)/(count*(count-1)); + double root = Math.sqrt(val); + + // due to rounding errors it can happen that "val" is negative + // this means that the real value is 0 (or very close to it), so + // we return 0 + if(Double.isNaN(root)) + return 0.0; + else + return root; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-08-31 14:36:08
|
Revision: 124 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=124&view=rev Author: jenslehmann Date: 2007-08-31 07:28:38 -0700 (Fri, 31 Aug 2007) Log Message: ----------- modified DIG reasoner to not send empty tells when the internal KB is empty added method for printing all configuration values Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-08-31 14:25:18 UTC (rev 123) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-08-31 14:28:38 UTC (rev 124) @@ -1,6 +1,7 @@ package org.dllearner; import java.io.File; +import java.lang.reflect.Field; import java.net.URL; import java.util.LinkedList; import java.util.List; @@ -19,7 +20,7 @@ public static int maxLength = 7; public static int maxDepth; - + // Punktabzug für "ungenaue" Klassifizierungen, also positiv als neutral, // neutral als negativ und negativ als neutral public static double accuracyPenalty = 1; @@ -27,71 +28,79 @@ // Punktabzug für fehlerhafte Klassifizierungen, also positiv als negativ // und negativ als positiv public static double errorPenalty = 3; - + public static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; - + public static LearningProblemType learningProblemType = LearningProblemType.TWO_VALUED; - + public static boolean penalizeNeutralExamples = false; - + public static boolean showCorrectClassifications = false; - + // wieviel Prozent darf ein um eine Einheit längeres Konzept schlechter // sein (aktuell: 5% sind eine Verlängerung um 1 wert) - // Problem: dieser Parameter hat für GP und Refinement zwar die gleiche Bedeutung, + // Problem: dieser Parameter hat für GP und Refinement zwar die gleiche + // Bedeutung, // aber es sind unterschiedliche Werte angebracht; // bei GP sollte der Wert so sein, dass am Ende das gewünschte Konzept // tatsächlich die beste Fitness hat, also eher niedrig (<0.005); - // bei Refinement in flexible heuristic soll es so sein, dass schlechtere Konzepte - // probiert werden sollen, sobald horizontal expansion eines gut klassifizierenden - // Knotens steigt => da ist also gewünscht das kürzere aber schlechtere Knoten - // ev. einen Vorsprung haben => demzufolge ist dort ein hoher Wert (ca. 0.05) + // bei Refinement in flexible heuristic soll es so sein, dass schlechtere + // Konzepte + // probiert werden sollen, sobald horizontal expansion eines gut + // klassifizierenden + // Knotens steigt => da ist also gewünscht das kürzere aber schlechtere + // Knoten + // ev. einen Vorsprung haben => demzufolge ist dort ein hoher Wert (ca. + // 0.05) // angebracht // public static double percentPerLengthUnit = 0.0025; public static double percentPerLengthUnit = 0.05; - - public enum Algorithm {GP, BRUTE_FORCE, RANDOM_GUESSER, REFINEMENT, HYBRID_GP}; - + + public enum Algorithm { + GP, BRUTE_FORCE, RANDOM_GUESSER, REFINEMENT, HYBRID_GP + }; + public static Algorithm algorithm = Algorithm.REFINEMENT; - + // Rückgabetyp des gelernten Konzepts public static String returnType = ""; - + public static boolean statisticMode = false; - + // if set to true a retrieval algorithm is used for classification // instead of single instance checks (default is now false, because // we can send all instance checks in a single request), for KAON2 // as reasoner it should in many cases be set to true public static boolean useRetrievalForClassification = false; - + // welche Art von Reasoning wird benutzt (eigener Algorithmus, // KAON2-API, DIG-Interface) public static ReasonerType reasonerType = ReasonerType.DIG; - + // bei fast retrieval muss trotzdem irgendein Reasoner gesetzt // werden um die flat ABox zu erzeugen public static ReasonerType startUpReasoningType = ReasonerType.KAON2; - + public static URL digReasonerURL = null; - + // unique names assumption public static boolean una = false; - + // open world assumption; momentan wird closed world assumption nur // fuer Rollen unterstuetzt public static boolean owa = true; - - // an-/abschalten von System.nanoTime()-Aufrufen außerhalb des Reasoningservice + + // an-/abschalten von System.nanoTime()-Aufrufen außerhalb des + // Reasoningservice public static boolean useNonReasonerBenchmarks = false; - + // erlaubt das abschalten von Benchmarks bei der Subsumptionhierarchie, // da diese ohnehin gecacht wird, also die System.nanoTime()-Aufrufe nur // Zeit kosten // public static boolean useHierarchyReasonerBenchmarks = false; - + public static List<String> hidePrefixes = new LinkedList<String>(); - + // Informationen (Rollen, Konzepte, Individuen, Anzahl Axiome) über // Wissensbasis anzeigen => alles konfigurierbar um Output in Grenzen // zu halten @@ -100,97 +109,106 @@ public static boolean showIndividuals = false; public static boolean showSubsumptionHierarchy = false; // zeigt die interne Wissensbasis an (d.h. keine externen OWL-Dateien) - public static boolean showInternalKB = false; + public static boolean showInternalKB = false; public static int maxLineLength = 100; - + public static boolean writeDIGProtocol = false; - public static File digProtocolFile = new File("digProtocol.txt"); - + public static File digProtocolFile = new File("digProtocol.txt"); + // public static String preprocessingModule = ""; - - // TODO: noch nicht implementiert, dass man diese per Config-Datei setzen kann + + // TODO: noch nicht implementiert, dass man diese per Config-Datei setzen + // kann public static class Refinement { - + // Nutzung der Äquivalenz ALL R.C AND ALL R.D = ALL R.(C AND D) public static boolean applyAllFilter = true; - + // Nutzung der Äquivalenz EXISTS R.C OR EXISTS R.D = EXISTS R.(C OR D) public static boolean applyExistsFilter = true; - + public static boolean useTooWeakList = true; - + public static boolean useOverlyGeneralList = true; - + public static boolean useShortConceptConstruction = true; - + public static double horizontalExpansionFactor = 0.6; - + public static boolean improveSubsumptionHierarchy = true; - + public static boolean quiet = false; - + public static boolean writeSearchTree = false; - + public static File searchTreeFile = new File("searchTree.txt"); - - public enum Heuristic { LEXICOGRAPHIC, FLEXIBLE }; - + + public enum Heuristic { + LEXICOGRAPHIC, FLEXIBLE + }; + public static Heuristic heuristic = Heuristic.LEXICOGRAPHIC; - public enum UseDIGMultiInstanceChecks { NEVER, TWOCHECKS, ONECHECK }; - + public enum UseDIGMultiInstanceChecks { + NEVER, TWOCHECKS, ONECHECK + }; + // multi instance check => es wird versucht mehrere instance checks pro // Anfrage auf einmal an den Reasoner zu schicken; Vorteil bei DIG: - // weniger Kommunikation; Nachteil: es müssen alle instanceChecks ausgeführt + // weniger Kommunikation; Nachteil: es müssen alle instanceChecks + // ausgeführt // werden, bevor too weak festgestellt werden kann // TODO: not implemented public static UseDIGMultiInstanceChecks useDIGMultiInstanceChecks = UseDIGMultiInstanceChecks.TWOCHECKS; - + // geplante Optionen um den Suchraum einzuschränken - - // Konzepte, die in der Definition vorkommen können (per Default ("null") alle) + + // Konzepte, die in der Definition vorkommen können (per Default + // ("null") alle) // nicht implementiert public static Set<AtomicConcept> allowedConcepts = null; // ignorierte Konzepte; Default null = keine public static Set<AtomicConcept> ignoredConcepts = null; - // beachte: es können nur entweder die erlaubten oder die ignorierten Konzepte + // beachte: es können nur entweder die erlaubten oder die ignorierten + // Konzepte // gesetzt werden - - // true falls die Konzepte vom Nutzer gesetzt worden (also allowedConcepts + + // true falls die Konzepte vom Nutzer gesetzt worden (also + // allowedConcepts // gleich null), ansonsten false public static boolean allowedConceptsAutoDetect = true; - + // Rollen, die in der Lösung vorkommen können // nicht implementiert public static Set<AtomicRole> allowedRoles = null; public static Set<AtomicRole> ignoredRoles = null; public static boolean allowedRolesAutoDetect = true; - + // max. Verschachtelungstiefe der Lösung // nicht implementiert public static int maxDepth = 0; - + // Konstruktoren an- und abschalten // nicht implementiert public static boolean useAllConstructor = true; public static boolean useExistsConstructor = true; public static boolean useNegation = true; // public static boolean useDisjunction = true; - //public static boolean useConjunction = true; - + // public static boolean useConjunction = true; + // Domain und Range beim Verschachteln von Rollen beachten // nicht implementiert // TODO: Wie soll man das in DIG machen? public static boolean useDomainRange = false; - + // bereits vorher allgemeinere Konzepte festlegen (Default: keine) // nicht implementiert // => ist eigentlich unnötig, da dieses Wissen zur Ontologie hinzugefügt // und dann gelernt werden kann // public static List<AtomicConcept> fixedUpperConcepts; - + } - + public static class GP { // FPS funktioniert momentan noch nicht, es muss sichergestellt werden, @@ -198,7 +216,7 @@ public static SelectionType selectionType = SelectionType.RANK_SELECTION; public static int tournamentSize = 3; - + public static boolean elitism = true; public static AlgorithmType algorithmType = AlgorithmType.STEADY_STATE; @@ -206,32 +224,59 @@ public static double mutationProbability = 0.03d; public static double crossoverProbability = 0.95d; - + public static double hillClimbingProbability = 0.0d; public static double refinementProbability = 0.0; - + public static int numberOfIndividuals = 100; public static int numberOfSelectedIndividuals = 96; public static boolean useFixedNumberOfGenerations = false; - + public static int generations = 20; - + public static int postConvergenceGenerations = 50; - + public static boolean adc = false; public static int initMinDepth = 4; - + public static int initMaxDepth = 6; - + public static int maxConceptLength = 75; + + // bei true werden statt Disjunction MultiDisjunction und statt + // Conjunction + // MultiConjunction im GP benutzt (es gibt derzeit keinen Grund es auf + // false + // zu setzen) + public static boolean useMultiStructures = true; - // bei true werden statt Disjunction MultiDisjunction und statt Conjunction - // MultiConjunction im GP benutzt (es gibt derzeit keinen Grund es auf false - // zu setzen) - public static boolean useMultiStructures = true; } + + public static String print() { + StringBuffer buff = new StringBuffer(); + buff.append("** overview of all set config values**\n\n"); + + Field[] fields = Config.class.getDeclaredFields(); + // Field[] fields = this.getClass().getDeclaredFields(); + for (int i = 0; i < fields.length; i++) { + try { + buff.append(fields[i].getName()).append("\t=>\t").append(fields[i].get(Config.class)) + .append("\n"); + + // System.out.println(fields[i].getName() + " : values: " + + // fields[i].get(this)); + } catch (IllegalAccessException ex) { + ex.printStackTrace(System.out); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(System.out); + } + + } + return buff.toString(); + + } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-08-31 14:25:18 UTC (rev 123) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-08-31 14:28:38 UTC (rev 124) @@ -97,7 +97,7 @@ public DIGReasoner(KB kb, URL url, Map<URL,OntologyFileFormat> imports) { this.imports = imports; this.kb = kb; - connector = new DIGHTTPConnector(url); + connector = new DIGHTTPConnector(url); identifier = connector.getIdentifier(); kbURI = connector.newKB(); @@ -109,21 +109,23 @@ "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"; // erzeuge tell-Anfrage für Knowledgebase - StringBuilder sb = new StringBuilder(); - sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); - sb.append("<tells xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + - "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + - "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); - sb.append(DIGConverter.getDIGString(kb)); - sb.append("</tells>"); + if(kb.getNumberOfAxioms()>0) { + StringBuilder sb = new StringBuilder(); + sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); + sb.append("<tells xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + + "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); + sb.append(DIGConverter.getDIGString(kb)); + sb.append("</tells>"); + + ResponseDocument rd = connector.tells(sb.toString()); + if(!rd.getResponse().isSetOk()) { + System.err.println("DIG-Reasoner cannot read knowledgebase."); + System.exit(0); + } + } - ResponseDocument rd = connector.tells(sb.toString()); - if(!rd.getResponse().isSetOk()) { - System.err.println("DIG-Reasoner cannot read knowledgebase."); - System.exit(0); - } - String importDIGString = ""; // Ontologien mit Hilfe von KAON2 importieren - direkt zur @@ -174,6 +176,8 @@ // es wird jetzt immer der DIG-Reasoner abgefragt (auch ohne Importe), // da so gleich auch äquivalente Konzepte rausgefiltert werden + + // DIG-Abfragen nach Konzepten, Rollen, Individuals atomicConcepts = getAtomicConceptsDIG(); atomicRoles = getAtomicRolesDIG(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-08-31 14:52:09
|
Revision: 123 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=123&view=rev Author: jenslehmann Date: 2007-08-31 07:25:18 -0700 (Fri, 31 Aug 2007) Log Message: ----------- added method for counting axioms small improvements in statistics script Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/dl/KB.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Modified: trunk/src/dl-learner/org/dllearner/dl/KB.java =================================================================== --- trunk/src/dl-learner/org/dllearner/dl/KB.java 2007-08-31 14:21:57 UTC (rev 122) +++ trunk/src/dl-learner/org/dllearner/dl/KB.java 2007-08-31 14:25:18 UTC (rev 123) @@ -201,4 +201,9 @@ return connectedSet; } + + public int getNumberOfAxioms() { + return (abox.size() + tbox.size() + rbox.size()); + } + } Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-08-31 14:21:57 UTC (rev 122) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-08-31 14:25:18 UTC (rev 123) @@ -116,6 +116,7 @@ examples[4] = "poker (49 examples, pair)"; examples[5] = "poker (55 examples, straight)"; examples[6] = "uncle (FORTE data set)"; + int startExampleNr = 0; String[] algorithms = new String[3]; algorithms[0] = "refinement"; @@ -123,6 +124,9 @@ algorithms[2] = "hybrid"; int[] algorithmRuns = {1,10,10}; + int startAlgorithmNr = 0; + + // do not plot anything // File[][][] gnuplotFiles = new File[examples.length][algorithms.length][3]; @@ -143,7 +147,7 @@ ConfigurationManager confMgr = new ConfigurationManager(); confMgr.applyOptions(); - for(int exampleNr=0; exampleNr < examples.length; exampleNr++) { + for(int exampleNr=startExampleNr; exampleNr < examples.length; exampleNr++) { // parse current conf file DLLearner.parseFile(confFiles[exampleNr].toString()); @@ -164,7 +168,7 @@ statString += "example: " + examples[exampleNr] + "\n\n"; - for(int algorithmNr=0; algorithmNr < algorithms.length; algorithmNr++) { + for(int algorithmNr=startAlgorithmNr; algorithmNr < algorithms.length; algorithmNr++) { Stat classification = new Stat(); Stat length = new Stat(); @@ -178,6 +182,13 @@ Reasoner reasoner = Main.createReasoner(new KB(), imports); ReasoningService rs = new ReasoningService(reasoner); + // System.out.println(positiveExamples); + // System.out.println(negativeExamples); + // System.exit(0); + + // create learning problem + LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); + // prepare reasoner for using subsumption and role hierarchy // TODO: currently, it is a small unfairness that each algorithm // uses the same reasoning object (e.g. the second algorithm may @@ -194,10 +205,7 @@ } catch (ReasoningMethodUnsupportedException e) { e.printStackTrace(); } - - // create learning problem - LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); - + LearningAlgorithm learningAlgorithm = null; if(algorithmNr==0) { Config.algorithm = Algorithm.REFINEMENT; @@ -213,6 +221,8 @@ Config.GP.generations = 50; Config.GP.useFixedNumberOfGenerations = true; Config.GP.numberOfIndividuals = 201; + // if(exampleNr == 3 || exampleNr == 4) + // Config.GP.numberOfIndividuals = 51; Config.GP.refinementProbability = 0; Config.GP.mutationProbability = 0.02; Config.GP.crossoverProbability = 0.8; @@ -226,6 +236,8 @@ Config.GP.generations = 50; Config.GP.useFixedNumberOfGenerations = true; Config.GP.numberOfIndividuals = 201; + //if(exampleNr == 3 || exampleNr == 4) + // Config.GP.numberOfIndividuals = 51; Config.GP.refinementProbability = 0.65; Config.GP.mutationProbability = 0.02; Config.GP.crossoverProbability = 0.2; @@ -234,7 +246,8 @@ learningAlgorithm = new GP(learningProblem); } - rs.resetStatistics(); + // rs.resetStatistics(); + long algorithmStartTime = System.nanoTime(); learningAlgorithm.start(); long algorithmTime = System.nanoTime() - algorithmStartTime; @@ -256,7 +269,7 @@ statDetailsString += "example: " + examples[exampleNr] + "\n"; statDetailsString += "algorithm: " + algorithms[algorithmNr] + "\n"; statDetailsString += "learned concept: " + learningAlgorithm.getBestSolution() + "\n"; - statDetailsString += "classification: " + classificationRatePercent + "\n"; + statDetailsString += "classification: " + classificationRatePercent + "%\n"; statDetailsString += "concept length: " + conceptLength + "\n"; statDetailsString += "runtime: " + Helper.prettyPrintNanoSeconds(algorithmTime) + "\n\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-09-21 14:21:56
|
Revision: 146 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=146&view=rev Author: jenslehmann Date: 2007-09-21 07:21:49 -0700 (Fri, 21 Sep 2007) Log Message: ----------- new base structure started Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/ trunk/src/dl-learner/org/dllearner/core/Component.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ConfigOption.java trunk/src/dl-learner/org/dllearner/core/ConfigOptionInstance.java trunk/src/dl-learner/org/dllearner/core/ConfigOptionType.java Added: trunk/src/dl-learner/org/dllearner/core/Component.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Component.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/Component.java 2007-09-21 14:21:49 UTC (rev 146) @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * @author Jens Lehmann + * + */ +public interface Component { + +} Added: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-21 14:21:49 UTC (rev 146) @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * @author Jens Lehmann + * + */ +public class ComponentManager { + +} Added: trunk/src/dl-learner/org/dllearner/core/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ConfigOption.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ConfigOption.java 2007-09-21 14:21:49 UTC (rev 146) @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * @author Jens Lehmann + * + */ +public class ConfigOption { + +} Added: trunk/src/dl-learner/org/dllearner/core/ConfigOptionInstance.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ConfigOptionInstance.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ConfigOptionInstance.java 2007-09-21 14:21:49 UTC (rev 146) @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * @author Jens Lehmann + * + */ +public class ConfigOptionInstance { + +} Added: trunk/src/dl-learner/org/dllearner/core/ConfigOptionType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ConfigOptionType.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ConfigOptionType.java 2007-09-21 14:21:49 UTC (rev 146) @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * @author Jens Lehmann + * + */ +public enum ConfigOptionType { + + INT, + + DOUBLE, + + STRING, + + SET_STRING + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-09-22 10:22:02
|
Revision: 148 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=148&view=rev Author: jenslehmann Date: 2007-09-22 03:22:00 -0700 (Sat, 22 Sep 2007) Log Message: ----------- added string config options and new learning problem structure Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java trunk/src/dl-learner/org/dllearner/learningproblems/ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java trunk/src/dl-learner/org/dllearner/learningproblems/LearningProblemNew.java Added: trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java 2007-09-22 10:22:00 UTC (rev 148) @@ -0,0 +1,34 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * @author Jens Lehmann + * + */ +public final class CommonConfigOptions { + + public static final IntegerConfigOption getVerbosityOption() { + // TODO: temporary code + IntegerConfigOption verbosityOption = new IntegerConfigOption("verbosity"); + return verbosityOption; + } + +} Added: trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java 2007-09-22 10:22:00 UTC (rev 148) @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import java.util.Set; +import java.util.TreeSet; + +/** + * A configuration option, which allows values of type String. Optionally a set + * of allowed strings can be set. By default all strings are allowed. + * + * @author Jens Lehmann + * + */ +public class StringConfigOption extends ConfigOption { + + private Set<String> allowedValues; + + public StringConfigOption(String name) { + super(name); + allowedValues = new TreeSet<String>(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) + */ + @Override + public boolean isValidValue(Object value) { + if(!(value instanceof String)) + return false; + + String stringValue = (String) value; + + if(allowedValues.size() == 0 || allowedValues.contains(stringValue)) + return true; + else + return false; + } + + /** + * @return the allowedValues + */ + public Set<String> getAllowedValues() { + return allowedValues; + } + + /** + * @param allowedValues the allowedValues to set + */ + public void setAllowedValues(Set<String> allowedValues) { + this.allowedValues = allowedValues; + } + +} Added: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-09-22 10:22:00 UTC (rev 148) @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +import java.util.Collection; + +import org.dllearner.core.Component; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; + +/** + * @author Jens Lehmann + * + */ +public abstract class DefinitionLP implements LearningProblemNew, Component { + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + public void applyConfigEntry(ConfigEntry entry) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#getConfigOptions() + */ + public Collection<ConfigOption> getConfigOptions() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#getName() + */ + public String getName() { + // TODO Auto-generated method stub + return null; + } + +} Added: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-09-22 10:22:00 UTC (rev 148) @@ -0,0 +1,35 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +import java.util.Collection; + +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; + +/** + * @author Jens Lehmann + * + */ +public class DefinitionLPThreeValued extends DefinitionLP { + + + +} Added: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-22 10:22:00 UTC (rev 148) @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +/** + * @author Jens Lehmann + * + */ +public class DefinitionLPTwoValued extends DefinitionLP { + + + +} Added: trunk/src/dl-learner/org/dllearner/learningproblems/LearningProblemNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/LearningProblemNew.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/LearningProblemNew.java 2007-09-22 10:22:00 UTC (rev 148) @@ -0,0 +1,31 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +/** + * Marker interface for all learning problems (the "New" at the end of the name + * is temporary for the restructuring process). + * + * @author Jens Lehmann + * + */ +public interface LearningProblemNew { + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-09-23 17:16:13
|
Revision: 149 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=149&view=rev Author: jenslehmann Date: 2007-09-23 10:16:08 -0700 (Sun, 23 Sep 2007) Log Message: ----------- continued implementing the new base structure Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/Component.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/learningproblems/LearningProblemNew.java Modified: trunk/src/dl-learner/org/dllearner/core/Component.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Component.java 2007-09-22 10:22:00 UTC (rev 148) +++ trunk/src/dl-learner/org/dllearner/core/Component.java 2007-09-23 17:16:08 UTC (rev 149) @@ -20,28 +20,33 @@ package org.dllearner.core; import java.util.Collection; +import java.util.LinkedList; /** * @author Jens Lehmann * */ -public interface Component { - +public abstract class Component { + /** * * @return The name of this component. */ - public String getName(); + public static String getName() { + return "unnamed component"; + } /** * Returns all configuration options supported by this component. */ - public Collection<ConfigOption> getConfigOptions(); + public static Collection<ConfigOption> createConfigOptions() { + return new LinkedList<ConfigOption>(); + } /** * Applies a configuration option to this component. * * @param entry A configuration entry. */ - public void applyConfigEntry(ConfigEntry entry); + public abstract void applyConfigEntry(ConfigEntry entry); } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-22 10:22:00 UTC (rev 148) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-23 17:16:08 UTC (rev 149) @@ -19,10 +19,84 @@ */ package org.dllearner.core; +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.LinkedList; +import java.util.List; + /** + * Central manager class for DL-Learner. + * * @author Jens Lehmann * */ public class ComponentManager { + private static String componentsFile = "lib/components.ini"; + + private static ComponentManager cm = new ComponentManager(); + + private ComponentManager() { + + } + + public static ComponentManager getInstance() { + return cm; + } + + private static List<String> readComponentsFile() { + List<String> componentStrings = new LinkedList<String>(); + + try { + FileInputStream fstream = new FileInputStream(componentsFile); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String line; + + while ((line = br.readLine()) != null) { + if(!(line.startsWith("#") || line.startsWith("//") || line.startsWith("%"))) + componentStrings.add(line); + } + + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + return componentStrings; + } + + public LearningProblemNew learningProblem(Class<LearningProblemNew> lp, ReasonerComponent reasoner) { + try { + Constructor<LearningProblemNew> constructor = lp.getConstructor(ReasonerComponent.class); + return constructor.newInstance(reasoner); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + } Added: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-09-23 17:16:08 UTC (rev 149) @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * @author Jens Lehmann + * + */ +public class LearningAlgorithmNew extends Component { + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public void applyConfigEntry(ConfigEntry entry) { + // TODO Auto-generated method stub + + } + +} Copied: trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java (from rev 148, trunk/src/dl-learner/org/dllearner/learningproblems/LearningProblemNew.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-09-23 17:16:08 UTC (rev 149) @@ -0,0 +1,31 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * Marker interface for all learning problems (the "New" at the end of the name + * is temporary for the restructuring process). + * + * @author Jens Lehmann + * + */ +public abstract class LearningProblemNew extends Component { + +} Added: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2007-09-23 17:16:08 UTC (rev 149) @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * @author Jens Lehmann + * + */ +public class ReasonerComponent extends Component { + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public void applyConfigEntry(ConfigEntry entry) { + // TODO Auto-generated method stub + + } + +} Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-09-22 10:22:00 UTC (rev 148) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-09-23 17:16:08 UTC (rev 149) @@ -21,19 +21,20 @@ import java.util.Collection; -import org.dllearner.core.Component; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; +import org.dllearner.core.LearningProblemNew; /** * @author Jens Lehmann * */ -public abstract class DefinitionLP implements LearningProblemNew, Component { +public abstract class DefinitionLP extends LearningProblemNew { /* (non-Javadoc) * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) */ + @Override public void applyConfigEntry(ConfigEntry entry) { // TODO Auto-generated method stub @@ -42,17 +43,9 @@ /* (non-Javadoc) * @see org.dllearner.core.Component#getConfigOptions() */ - public Collection<ConfigOption> getConfigOptions() { - // TODO Auto-generated method stub + public static Collection<ConfigOption> getConfigOptions() { + // TODO: positive and negative examples return null; } - - /* (non-Javadoc) - * @see org.dllearner.core.Component#getName() - */ - public String getName() { - // TODO Auto-generated method stub - return null; - } } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-09-22 10:22:00 UTC (rev 148) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-09-23 17:16:08 UTC (rev 149) @@ -19,17 +19,17 @@ */ package org.dllearner.learningproblems; -import java.util.Collection; - -import org.dllearner.core.ConfigEntry; -import org.dllearner.core.ConfigOption; - /** * @author Jens Lehmann * */ public class DefinitionLPThreeValued extends DefinitionLP { + /* (non-Javadoc) + * @see org.dllearner.core.Component#getName() + */ + public static String getName() { + return "two valued definition learning problem"; + } - } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-22 10:22:00 UTC (rev 148) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-23 17:16:08 UTC (rev 149) @@ -25,6 +25,11 @@ */ public class DefinitionLPTwoValued extends DefinitionLP { + /* (non-Javadoc) + * @see org.dllearner.core.Component#getName() + */ + public static String getName() { + return "two valued definition learning problem"; + } - } Deleted: trunk/src/dl-learner/org/dllearner/learningproblems/LearningProblemNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/LearningProblemNew.java 2007-09-22 10:22:00 UTC (rev 148) +++ trunk/src/dl-learner/org/dllearner/learningproblems/LearningProblemNew.java 2007-09-23 17:16:08 UTC (rev 149) @@ -1,31 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.learningproblems; - -/** - * Marker interface for all learning problems (the "New" at the end of the name - * is temporary for the restructuring process). - * - * @author Jens Lehmann - * - */ -public interface LearningProblemNew { - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-09-25 14:32:28
|
Revision: 152 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=152&view=rev Author: jenslehmann Date: 2007-09-25 07:32:25 -0700 (Tue, 25 Sep 2007) Log Message: ----------- another major step in building the new base structure Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/LearningProblem.java trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/Score.java trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/Node.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java trunk/src/dl-learner/org/dllearner/core/Component.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/ConfigOption.java trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java trunk/src/dl-learner/org/dllearner/core/dl/All.java trunk/src/dl-learner/org/dllearner/core/dl/AssertionalAxiom.java trunk/src/dl-learner/org/dllearner/core/dl/AtomicConcept.java trunk/src/dl-learner/org/dllearner/core/dl/AtomicRole.java trunk/src/dl-learner/org/dllearner/core/dl/Axiom.java trunk/src/dl-learner/org/dllearner/core/dl/Bottom.java trunk/src/dl-learner/org/dllearner/core/dl/Concept.java trunk/src/dl-learner/org/dllearner/core/dl/ConceptAssertion.java trunk/src/dl-learner/org/dllearner/core/dl/Conjunction.java trunk/src/dl-learner/org/dllearner/core/dl/Disjunction.java trunk/src/dl-learner/org/dllearner/core/dl/Equality.java trunk/src/dl-learner/org/dllearner/core/dl/Exists.java trunk/src/dl-learner/org/dllearner/core/dl/FlatABox.java trunk/src/dl-learner/org/dllearner/core/dl/FunctionalRoleAxiom.java trunk/src/dl-learner/org/dllearner/core/dl/GreaterEqual.java trunk/src/dl-learner/org/dllearner/core/dl/Inclusion.java trunk/src/dl-learner/org/dllearner/core/dl/Individual.java trunk/src/dl-learner/org/dllearner/core/dl/InverseRole.java trunk/src/dl-learner/org/dllearner/core/dl/InverseRoleAxiom.java trunk/src/dl-learner/org/dllearner/core/dl/KB.java trunk/src/dl-learner/org/dllearner/core/dl/KBElement.java trunk/src/dl-learner/org/dllearner/core/dl/LessEqual.java trunk/src/dl-learner/org/dllearner/core/dl/MultiConjunction.java trunk/src/dl-learner/org/dllearner/core/dl/MultiDisjunction.java trunk/src/dl-learner/org/dllearner/core/dl/Negation.java trunk/src/dl-learner/org/dllearner/core/dl/NumberRestriction.java trunk/src/dl-learner/org/dllearner/core/dl/Quantification.java trunk/src/dl-learner/org/dllearner/core/dl/RBoxAxiom.java trunk/src/dl-learner/org/dllearner/core/dl/Role.java trunk/src/dl-learner/org/dllearner/core/dl/RoleAssertion.java trunk/src/dl-learner/org/dllearner/core/dl/SubRoleAxiom.java trunk/src/dl-learner/org/dllearner/core/dl/SymmetricRoleAxiom.java trunk/src/dl-learner/org/dllearner/core/dl/TerminologicalAxiom.java trunk/src/dl-learner/org/dllearner/core/dl/Top.java trunk/src/dl-learner/org/dllearner/core/dl/TransitiveRoleAxiom.java trunk/src/dl-learner/org/dllearner/kb/OWLFile.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java trunk/src/dl-learner/org/dllearner/modules/ModuleInvocator.java trunk/src/dl-learner/org/dllearner/modules/PreprocessingModule.java trunk/src/dl-learner/org/dllearner/modules/TestModule.java trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGConverter.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrieval.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java trunk/src/dl-learner/org/dllearner/utilities/ConceptTransformation.java trunk/src/dl-learner/org/dllearner/utilities/Helper.java trunk/src/dl-learner/org/dllearner/utilities/OntologyClassRewriter.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasoningMethodUnsupportedException.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java trunk/src/dl-learner/org/dllearner/core/dl/ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/dl/ trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java trunk/src/dl-learner/org/dllearner/reasoning/ReasoningMethodUnsupportedException.java trunk/src/dl-learner/org/dllearner/reasoning/ReasoningService.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-09-25 14:32:25 UTC (rev 152) @@ -11,8 +11,8 @@ import org.dllearner.ScoreThreeValued.ScoreMethod; import org.dllearner.algorithms.gp.GP.AlgorithmType; import org.dllearner.algorithms.gp.GP.SelectionType; -import org.dllearner.dl.AtomicConcept; -import org.dllearner.dl.AtomicRole; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; import org.dllearner.reasoning.ReasonerType; public class Config { Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-09-25 14:32:25 UTC (rev 152) @@ -16,8 +16,8 @@ import org.dllearner.ScoreThreeValued.ScoreMethod; import org.dllearner.algorithms.gp.GP.AlgorithmType; import org.dllearner.algorithms.gp.GP.SelectionType; -import org.dllearner.dl.AtomicConcept; -import org.dllearner.dl.AtomicRole; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; import org.dllearner.parser.DLLearner; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.ConceptComparator; Modified: trunk/src/dl-learner/org/dllearner/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-09-25 14:32:25 UTC (rev 152) @@ -5,11 +5,11 @@ import java.util.TreeSet; import org.dllearner.Config.Refinement; -import org.dllearner.dl.Concept; -import org.dllearner.dl.Individual; -import org.dllearner.dl.Negation; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.Negation; import org.dllearner.reasoning.ReasonerType; -import org.dllearner.reasoning.ReasoningService; import org.dllearner.utilities.Helper; import org.dllearner.utilities.SortedSetTuple; Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-09-25 14:32:25 UTC (rev 152) @@ -45,16 +45,19 @@ import org.dllearner.algorithms.RandomGuesser; import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; -import org.dllearner.dl.AssertionalAxiom; -import org.dllearner.dl.AtomicConcept; -import org.dllearner.dl.AtomicRole; -import org.dllearner.dl.Concept; -import org.dllearner.dl.ConceptAssertion; -import org.dllearner.dl.FlatABox; -import org.dllearner.dl.Individual; -import org.dllearner.dl.KB; -import org.dllearner.dl.Negation; -import org.dllearner.dl.RoleAssertion; +import org.dllearner.core.Reasoner; +import org.dllearner.core.ReasoningMethodUnsupportedException; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.dl.AssertionalAxiom; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.ConceptAssertion; +import org.dllearner.core.dl.FlatABox; +import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.KB; +import org.dllearner.core.dl.Negation; +import org.dllearner.core.dl.RoleAssertion; import org.dllearner.modules.ModuleInvocator; import org.dllearner.parser.DLLearner; import org.dllearner.parser.ParseException; @@ -62,10 +65,7 @@ import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.FastRetrievalReasoner; import org.dllearner.reasoning.KAON2Reasoner; -import org.dllearner.reasoning.Reasoner; import org.dllearner.reasoning.ReasonerType; -import org.dllearner.reasoning.ReasoningMethodUnsupportedException; -import org.dllearner.reasoning.ReasoningService; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/Score.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Score.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/Score.java 2007-09-25 14:32:25 UTC (rev 152) @@ -2,7 +2,7 @@ import java.util.Set; -import org.dllearner.dl.Individual; +import org.dllearner.core.dl.Individual; public abstract class Score { public abstract double getScore(); Modified: trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java 2007-09-25 14:32:25 UTC (rev 152) @@ -4,7 +4,7 @@ import java.util.Set; import java.util.SortedSet; -import org.dllearner.dl.Individual; +import org.dllearner.core.dl.Individual; import org.dllearner.utilities.Helper; /** Modified: trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java 2007-09-25 14:32:25 UTC (rev 152) @@ -2,7 +2,7 @@ import java.util.Set; -import org.dllearner.dl.Individual; +import org.dllearner.core.dl.Individual; /** * Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-09-25 14:32:25 UTC (rev 152) @@ -8,16 +8,16 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; import org.dllearner.Score; -import org.dllearner.dl.All; -import org.dllearner.dl.AtomicConcept; -import org.dllearner.dl.AtomicRole; -import org.dllearner.dl.Bottom; -import org.dllearner.dl.Concept; -import org.dllearner.dl.Conjunction; -import org.dllearner.dl.Disjunction; -import org.dllearner.dl.Exists; -import org.dllearner.dl.Negation; -import org.dllearner.dl.Top; +import org.dllearner.core.dl.All; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Bottom; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Conjunction; +import org.dllearner.core.dl.Disjunction; +import org.dllearner.core.dl.Exists; +import org.dllearner.core.dl.Negation; +import org.dllearner.core.dl.Top; /** * TODO: Man könnte den Speicherbedarf gegen Null gehen lassen, wenn man gar keine Programme Modified: trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java 2007-09-25 14:32:25 UTC (rev 152) @@ -1,7 +1,7 @@ package org.dllearner.algorithms; import org.dllearner.Score; -import org.dllearner.dl.Concept; +import org.dllearner.core.dl.Concept; /** * TODO: Es gibt 3 Sachen, die eine Loesung ausmachen: die Loesung selbst, Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-25 14:32:25 UTC (rev 152) @@ -4,7 +4,7 @@ import org.dllearner.Score; import org.dllearner.algorithms.gp.Program; import org.dllearner.algorithms.gp.GPUtilities; -import org.dllearner.dl.Concept; +import org.dllearner.core.dl.Concept; public class RandomGuesser implements LearningAlgorithm { Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java 2007-09-25 14:32:25 UTC (rev 152) @@ -1,6 +1,6 @@ package org.dllearner.algorithms.gp; -import org.dllearner.dl.Concept; +import org.dllearner.core.dl.Concept; public class ADC extends Concept { Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-09-25 14:32:25 UTC (rev 152) @@ -48,8 +48,8 @@ import org.dllearner.Score; import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.algorithms.hybridgp.Psi; -import org.dllearner.dl.Concept; -import org.dllearner.dl.Top; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Top; import org.dllearner.utilities.Helper; /** Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-09-25 14:32:25 UTC (rev 152) @@ -14,20 +14,20 @@ import org.dllearner.Main; import org.dllearner.Score; import org.dllearner.ScoreThreeValued; -import org.dllearner.dl.All; -import org.dllearner.dl.AtomicConcept; -import org.dllearner.dl.AtomicRole; -import org.dllearner.dl.Bottom; -import org.dllearner.dl.Concept; -import org.dllearner.dl.Conjunction; -import org.dllearner.dl.Disjunction; -import org.dllearner.dl.Exists; -import org.dllearner.dl.FlatABox; -import org.dllearner.dl.Individual; -import org.dllearner.dl.MultiConjunction; -import org.dllearner.dl.MultiDisjunction; -import org.dllearner.dl.Negation; -import org.dllearner.dl.Top; +import org.dllearner.core.dl.All; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Bottom; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Conjunction; +import org.dllearner.core.dl.Disjunction; +import org.dllearner.core.dl.Exists; +import org.dllearner.core.dl.FlatABox; +import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.MultiConjunction; +import org.dllearner.core.dl.MultiDisjunction; +import org.dllearner.core.dl.Negation; +import org.dllearner.core.dl.Top; import org.dllearner.reasoning.FastRetrieval; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2007-09-25 14:32:25 UTC (rev 152) @@ -21,7 +21,7 @@ package org.dllearner.algorithms.gp; import org.dllearner.Score; -import org.dllearner.dl.Concept; +import org.dllearner.core.dl.Concept; /** * This class represents a program, i.e. an individual. Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-09-25 14:32:25 UTC (rev 152) @@ -8,7 +8,7 @@ import org.dllearner.LearningProblem; import org.dllearner.Score; import org.dllearner.algorithms.gp.Program; -import org.dllearner.dl.Concept; +import org.dllearner.core.dl.Concept; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-09-25 14:32:25 UTC (rev 152) @@ -9,18 +9,18 @@ import org.dllearner.LearningProblem; import org.dllearner.algorithms.refinement.RefinementOperator; -import org.dllearner.dl.All; -import org.dllearner.dl.AtomicConcept; -import org.dllearner.dl.AtomicRole; -import org.dllearner.dl.Bottom; -import org.dllearner.dl.Concept; -import org.dllearner.dl.Exists; -import org.dllearner.dl.MultiConjunction; -import org.dllearner.dl.MultiDisjunction; -import org.dllearner.dl.Negation; -import org.dllearner.dl.Quantification; -import org.dllearner.dl.Top; -import org.dllearner.reasoning.ReasoningService; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.dl.All; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Bottom; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Exists; +import org.dllearner.core.dl.MultiConjunction; +import org.dllearner.core.dl.MultiDisjunction; +import org.dllearner.core.dl.Negation; +import org.dllearner.core.dl.Quantification; +import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; /** Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-09-25 14:32:25 UTC (rev 152) @@ -9,18 +9,18 @@ import org.dllearner.LearningProblem; import org.dllearner.algorithms.refinement.RefinementOperator; -import org.dllearner.dl.All; -import org.dllearner.dl.AtomicConcept; -import org.dllearner.dl.AtomicRole; -import org.dllearner.dl.Bottom; -import org.dllearner.dl.Concept; -import org.dllearner.dl.Exists; -import org.dllearner.dl.MultiConjunction; -import org.dllearner.dl.MultiDisjunction; -import org.dllearner.dl.Negation; -import org.dllearner.dl.Quantification; -import org.dllearner.dl.Top; -import org.dllearner.reasoning.ReasoningService; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.dl.All; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Bottom; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Exists; +import org.dllearner.core.dl.MultiConjunction; +import org.dllearner.core.dl.MultiDisjunction; +import org.dllearner.core.dl.Negation; +import org.dllearner.core.dl.Quantification; +import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; public class PsiUp implements RefinementOperator { Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/Node.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/Node.java 2007-09-25 14:32:25 UTC (rev 152) @@ -3,7 +3,7 @@ import java.util.Set; import java.util.TreeSet; -import org.dllearner.dl.Concept; +import org.dllearner.core.dl.Concept; import org.dllearner.utilities.ConceptComparator; public class Node { Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-09-25 14:32:25 UTC (rev 152) @@ -14,10 +14,10 @@ import org.dllearner.Main; import org.dllearner.Score; import org.dllearner.algorithms.LearningAlgorithm; -import org.dllearner.dl.Concept; -import org.dllearner.dl.MultiConjunction; -import org.dllearner.dl.MultiDisjunction; -import org.dllearner.dl.Top; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.MultiConjunction; +import org.dllearner.core.dl.MultiDisjunction; +import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java 2007-09-25 14:32:25 UTC (rev 152) @@ -2,8 +2,9 @@ import java.util.List; import java.util.Set; -import org.dllearner.dl.Concept; +import org.dllearner.core.dl.Concept; + public interface RefinementOperator { public Set<Concept> refine(Concept concept); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-09-25 14:32:25 UTC (rev 152) @@ -31,21 +31,21 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; -import org.dllearner.dl.All; -import org.dllearner.dl.AtomicConcept; -import org.dllearner.dl.AtomicRole; -import org.dllearner.dl.Bottom; -import org.dllearner.dl.Concept; -import org.dllearner.dl.Conjunction; -import org.dllearner.dl.Disjunction; -import org.dllearner.dl.Exists; -import org.dllearner.dl.MultiConjunction; -import org.dllearner.dl.MultiDisjunction; -import org.dllearner.dl.Negation; -import org.dllearner.dl.Quantification; -import org.dllearner.dl.Role; -import org.dllearner.dl.Top; -import org.dllearner.reasoning.ReasoningService; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.dl.All; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Bottom; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Conjunction; +import org.dllearner.core.dl.Disjunction; +import org.dllearner.core.dl.Exists; +import org.dllearner.core.dl.MultiConjunction; +import org.dllearner.core.dl.MultiDisjunction; +import org.dllearner.core.dl.Negation; +import org.dllearner.core.dl.Quantification; +import org.dllearner.core.dl.Role; +import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java 2007-09-25 14:32:25 UTC (rev 152) @@ -1,6 +1,6 @@ package org.dllearner.algorithms.refinement; -import org.dllearner.dl.Concept; +import org.dllearner.core.dl.Concept; /** * Soll hauptsächlich dazu dienen zu testen, ob ein Konzept im Modified: trunk/src/dl-learner/org/dllearner/core/Component.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Component.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/core/Component.java 2007-09-25 14:32:25 UTC (rev 152) @@ -44,6 +44,11 @@ } /** + * Method to be called after the component has been configured. + */ + public abstract void init(); + + /** * Applies a configuration option to this component. * * @param entry A configuration entry. Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-25 14:32:25 UTC (rev 152) @@ -26,9 +26,16 @@ import java.io.InputStreamReader; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Set; +import org.dllearner.kb.OWLFile; + + /** * Central manager class for DL-Learner. * @@ -41,8 +48,70 @@ private static ComponentManager cm = new ComponentManager(); + private List<Class<? extends Component>> components; + + // list of all configuration options of all components + private Map<Class<? extends Component>,List<ConfigOption<?>>> componentOptions; + private Map<Class<? extends Component>,Map<String,ConfigOption<?>>> componentOptionsByName; + + @SuppressWarnings({"unchecked"}) private ComponentManager() { + // read in components file + List<String> componentsString = readComponentsFile(); + // component list + components = new LinkedList<Class<? extends Component>>(); + + // create classes from strings + for(String componentString : componentsString) { + try { + Class<? extends Component> component = Class.forName(componentString).asSubclass(Component.class); + components.add(component); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // read in all configuration options + componentOptions = new HashMap<Class<? extends Component>,List<ConfigOption<?>>>(); + componentOptionsByName = new HashMap<Class<? extends Component>,Map<String,ConfigOption<?>>>(); + + for(Class<? extends Component> component : components) { + // unfortunately Java does not seem to offer a way to call + // a static method given a class object directly, so we have + // to use reflection + try { + Method createConfig = component.getMethod("createConfigOptions"); + List<ConfigOption<?>> options = (List<ConfigOption<?>>) createConfig.invoke(null); + + componentOptions.put(component, options); + + Map<String,ConfigOption<?>> byName = new HashMap<String,ConfigOption<?>>(); + for(ConfigOption<?> option : options) + byName.put(option.getName(), option); + componentOptionsByName.put(component, byName); + + // componentOptionsByName.put(key, value) + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + } public static ComponentManager getInstance() { @@ -72,6 +141,42 @@ return componentStrings; } + /** + * Convenience method for testing purposes. If you know that the type of the + * value is correct, it is preferable to create a ConfigEntry object and apply + * it to the component (no type checking necessary). + * @param component + * @param optionName + * @param value + */ + public <T> void applyConfigEntry(Component component, String optionName, T value) { + // first we look whether the component is registered + if(components.contains(component)) { + + // look for a config option with the specified name + ConfigOption<?> option = (ConfigOption<?>) componentOptionsByName.get(component).get(optionName); + if(option!=null) { + // check whether the given object has the correct type + if(!option.checkType(value)) { + System.out.println("Warning: value " + value + " is not valid for option " + optionName + " in component " + component); + return; + } + + // we have checked the type, hence it should now be safe to typecast and + // create a ConfigEntry object + try { + @SuppressWarnings({"unchecked"}) + ConfigEntry<T> entry = new ConfigEntry<T>((ConfigOption<T>) option, value); + component.applyConfigEntry(entry); + } catch (InvalidConfigOptionValueException e) { + System.out.println("Warning: value " + value + " is not valid for option " + optionName + " in component " + component); + } + } else + System.out.println("Warning: undefined option " + optionName + " in component " + component); + } else + System.out.println("Warning: unregistered component " + component); + } + public KnowledgeSource knowledgeSource(Class<? extends KnowledgeSource> source) { try { Constructor<? extends KnowledgeSource> constructor = source.getConstructor(); @@ -99,9 +204,37 @@ return null; } - public LearningProblemNew learningProblem(Class<LearningProblemNew> lp, ReasonerComponent reasoner) { + public <T extends ReasonerComponent> ReasoningService reasoningService(Class<T> reasoner, Set<KnowledgeSource> sources) { try { - Constructor<LearningProblemNew> constructor = lp.getConstructor(ReasonerComponent.class); + Constructor<T> constructor = reasoner.getConstructor(ReasonerComponent.class); + T reasonerInstance = constructor.newInstance(sources); + return new ReasoningService(reasonerInstance); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + public <T extends LearningProblemNew> T learningProblem(Class<T> lp, ReasonerComponent reasoner) { + try { + Constructor<T> constructor = lp.getConstructor(ReasonerComponent.class); return constructor.newInstance(reasoner); } catch (SecurityException e) { // TODO Auto-generated catch block Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-25 14:32:25 UTC (rev 152) @@ -39,11 +39,12 @@ // create knowledge source KnowledgeSource source = cm.knowledgeSource(OWLFile.class); + cm.applyConfigEntry(source, "url", "father.owl"); // ... to be continued ... - ReasonerComponent reasoner = new ReasonerComponent(); - ComponentManager.getInstance().learningProblem(LearningProblemNew.class, reasoner); + // ReasonerComponent reasoner = new ReasonerComponent(); + // ComponentManager.getInstance().learningProblem(LearningProblemNew.class, reasoner); } Modified: trunk/src/dl-learner/org/dllearner/core/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ConfigOption.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/core/ConfigOption.java 2007-09-25 14:32:25 UTC (rev 152) @@ -38,6 +38,16 @@ return name; } + /** + * Checks whether the object has the correct type to be used as + * a value for this option (this method is necessary, because + * generic information is erased at runtime in Java). + * + * @param object The object to check. + * @return + */ + public abstract boolean checkType(Object object); + public abstract boolean isValidValue(T value); } Modified: trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-09-25 14:32:25 UTC (rev 152) @@ -91,6 +91,18 @@ this.upperLimit = upperLimit; } + /* (non-Javadoc) + * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) + */ + @Override + public boolean checkType(Object object) { + return (object instanceof Integer); + } + + + + + } Copied: trunk/src/dl-learner/org/dllearner/core/Reasoner.java (from rev 150, trunk/src/dl-learner/org/dllearner/reasoning/Reasoner.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2007-09-25 14:32:25 UTC (rev 152) @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +package org.dllearner.core; + +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; + +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.reasoning.ReasonerType; +import org.dllearner.reasoning.RoleHierarchy; +import org.dllearner.reasoning.SubsumptionHierarchy; +import org.dllearner.utilities.SortedSetTuple; + +/** + * Reasoner Interface. Lists all available reasoning methods. + * + * @author Jens Lehmann + * + */ +public interface Reasoner { + + public ReasonerType getReasonerType(); + + // Methode, die Subsumptionhierarchie initialisiert (sollte nur einmal + // pro erstelltem ReasoningService bzw. Reasoner aufgerufen werden) + // => erstellt auch vereinfachte Sichten auf Subsumptionhierarchie + // (siehe einfacher Traversal in Diplomarbeit) + public void prepareSubsumptionHierarchy(); + public void prepareRoleHierarchy() throws ReasoningMethodUnsupportedException; + + public boolean subsumes(Concept superConcept, Concept subConcept) throws ReasoningMethodUnsupportedException; + + // mehrere subsumption checks - spart bei DIG Anfragen (nur die zweite Methode wird gebraucht) + public Set<Concept> subsumes(Concept superConcept, Set<Concept> subConcepts) throws ReasoningMethodUnsupportedException; + public Set<Concept> subsumes(Set<Concept> superConcepts, Concept subConcept) throws ReasoningMethodUnsupportedException; + + // liefert eine Menge paarweise nicht äquivalenter Konzepte zurück, die über dem Konzept in der + // Subsumption-Hierarchie stehen + // Methoden veraltet, da das jetzt von der SubsumptionHierarchy-Klasse geregelt wird + // public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) throws ReasoningMethodUnsupportedException; + // public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) throws ReasoningMethodUnsupportedException; + + public SubsumptionHierarchy getSubsumptionHierarchy() throws ReasoningMethodUnsupportedException; + + public RoleHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException; + + public SortedSet<Individual> retrieval(Concept concept) throws ReasoningMethodUnsupportedException; + + public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) throws ReasoningMethodUnsupportedException; + + public boolean instanceCheck(Concept concept, Individual individual) throws ReasoningMethodUnsupportedException; + + // mehrere instance checks für ein Konzept - spart bei DIG Anfragen + public Set<Individual> instanceCheck(Concept concept, Set<Individual> individuals) throws ReasoningMethodUnsupportedException; + + public SortedSetTuple<Individual> doubleRetrieval(Concept concept) throws ReasoningMethodUnsupportedException; + + public SortedSetTuple<Individual> doubleRetrieval(Concept concept, Concept adc) throws ReasoningMethodUnsupportedException; + + public boolean isSatisfiable() throws ReasoningMethodUnsupportedException; + + // alle Konzepte, die i als Instanz haben + public Set<AtomicConcept> getConcepts(Individual i) throws ReasoningMethodUnsupportedException; + + public Set<AtomicConcept> getAtomicConcepts(); + + public Set<AtomicRole> getAtomicRoles(); + + public SortedSet<Individual> getIndividuals(); +} Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2007-09-25 09:30:13 UTC (rev 151) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2007-09-25 14:32:25 UTC (rev 152) @@ -19,19 +19,104 @@ */ package org.dllearner.core; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; + +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.reasoning.RoleHierarchy; +import org.dllearner.reasoning.SubsumptionHierarchy; +import org.dllearner.utilities.SortedSetTuple; + /** * @author Jens Lehmann - * + * */ -public class ReasonerComponent extends Component { +public abstract class ReasonerComponent extends Component implements Reasoner { - /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - public <T> void applyConfigEntry(ConfigEntry<T> entry) { - // TODO Auto-generated method stub + public boolean subsumes(Concept superConcept, Concept subConcept) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + public Set<Concept> subsumes(Concept superConcept, Set<Concept> subConcepts) + throws ReasoningMethodUnsupportedException { + Set<Concept> returnSet = new HashSet<Concept>(); + for (Concept subConcept : subConcepts) { + if (subsumes(superConcept, subConcept)) + returnSet.add(subConcept); + } + return returnSet; } + public Set<Concept> subsumes(Set<Concept> superConcepts, Concept subConcept) + throws ReasoningMethodUnsupportedException { + Set<Concept> returnSet = new HashSet<Concept>(); + for (Concept superConcept : superConcepts) { + if (subsumes(superConcept, subConcept)) + returnSet.add(superConcept); + } + return returnSet; + } + + public SortedSet<Individual> retrieval(Concept concept) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public boolean instanceCheck(Concept concept, Individual individual) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<Individual> instanceCheck(Concept concept, Set<Individual> individuals) + throws ReasoningMethodUnsupportedException { + Set<Individual> returnSet = new HashSet<Individual>(); + for (Individual individual : individuals) { + if (instanceCheck(concept, individual)) + returnSet.add(individual); + } + return returnSet; + } + + public SortedSetTuple<Individual> doubleRetrieval(Concept concept) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public SortedSetTuple<Individual> doubleRetrieval(Concept concept, Concept adc) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public boolean isSatisfiable() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public SubsumptionHierarchy getSubsumptionHierarchy() + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public void prepareRoleHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public RoleHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<AtomicConcept> getConcepts(Individual i) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + } Copied: trunk/src/dl-learner/org/dllearner/core/ReasoningMethodUnsupportedException.java (from rev 150, trunk/src/dl-learner/org/dllearner/reasoning/ReasoningMethodUnsupportedException.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningMethodUnsupportedException.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningMethodUnsupportedException.java 2007-09-25 14:32:25 UTC (rev 152) @@ -0,0 +1,7 @@ +package org.dllearner.core; + +public class ReasoningMethodUnsupportedException extends Exception { + + private static final long serialVersionUID = -7045236443032695475L; + +} Copied: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java (from rev 150, trunk/src/dl-learner/org/dllearner/reasoning/ReasoningService.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-09-25 14:32:25 UTC (rev 152) @@ -0,0 +1,493 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +package org.dllearner.core; + +import java.io.File; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.OntologyFileFormat; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.reasoning.DIGReasoner; +import org.dllearner.reasoning.KAON2Reasoner; +import org.dllearner.reasoning.ReasonerType; +import org.dllearner.reasoning.RoleHierarchy; +import org.dllearner.reasoning.SubsumptionHierarchy; +import org.dllearner.utilities.SortedSetTuple; + +/** + * The reasoning service is the interface to the used reasoner. Basically, + * it delegates all incoming reasoner request to the <code>Reasoner</code> + * object which has been specified in the constructor. However, it calculates + * some additional statistics about the time the reasoner needs to answer + * the query. + * + * @author Jens Lehmann + * + */ +public class ReasoningService { + + // statistische Daten + private long instanceCheckReasoningTimeNs = 0; + private int nrOfInstanceChecks = 0; + private int nrOfMultiInstanceChecks = 0; + private long retrievalReasoningTimeNs = 0; + private int nrOfRetrievals = 0; + private long subsumptionReasoningTimeNs = 0; + private int nrOfSubsumptionChecks = 0; + private int nrOfMultiSubsumptionChecks = 0; + // private long subsumptionHierarchyTimeNs = 0; + private int nrOfSubsumptionHierarchyQueries = 0; + + // restliche Reasoning-Zeit + private long otherReasoningTimeNs = 0; + + // Zeit für alle Reasoningaufgabe (normalerweise länger als nur + // obige Sachen) + private long overallReasoningTimeNs = 0; + + // temporäre Variablen (ausgelagert wg. Performance und Vereinfachung) + private long reasoningStartTimeTmp; + private long reasoningDurationTmp; + + // Listenansicht + private List<AtomicConcept> atomicConceptsList; + private List<AtomicRole> atomicRolesList; + + // private SortedSet<Concept> retrievalsSet = new TreeSet<Concept>(new ConceptComparator()); + + // Caching f�r allgemeinere/speziellere atomare Konzepte => wird innerhalb der Reasoner gemacht + // private Map<Concept,Set<Concept>> moreGeneralConcepts = new HashMap<Concept,Set<Concept>>(); + // private Map<Concept,Set<Concept>> moreSpecialConcepts = new HashMap<Concept,Set<Concept>>(); + + private Reasoner reasoner; + + // Beachte: wenn Wissensbasis modifiziert wird, muss ein neues + // Reasoner-Objekt + // angelegt werden (da Wissensbasis sofort entsprechend verwendetem + // Reasoning-Typ + // umgewandelt wird) + public ReasoningService(Reasoner reasoner) { + this.reasoner = reasoner; + + // Listenansicht + atomicConceptsList = new LinkedList<AtomicConcept>(getAtomicConcepts()); + atomicRolesList = new LinkedList<AtomicRole>(getAtomicRoles()); + + resetStatistics(); + } + + // zurücksetzen aller Statistiken (wenn z.B. vorher ein Satisfiability Check gemacht wird, + // der allerdings nicht zum eigentlichen Algorithmus gehört) + public void resetStatistics() { + instanceCheckReasoningTimeNs = 0; + nrOfInstanceChecks = 0; + retrievalReasoningTimeNs = 0; + nrOfRetrievals = 0; + subsumptionReasoningTimeNs = 0; + nrOfSubsumptionChecks = 0; + // subsumptionHierarchyTimeNs = 0; + nrOfSubsumptionHierarchyQueries = 0; + otherReasoningTimeNs = 0; + overallReasoningTimeNs = 0; + } + + public SortedSetTuple<Individual> doubleRetrieval(Concept concept) { + reasoningStartTimeTmp = System.nanoTime(); + SortedSetTuple<Individual> result; + try { + result = reasoner.doubleRetrieval(concept); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + otherReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public SortedSetTuple<Individual> doubleRetrieval(Concept concept, Concept adc) { + reasoningStartTimeTmp = System.nanoTime(); + SortedSetTuple<Individual> result; + try { + result = reasoner.doubleRetrieval(concept, adc); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + otherReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + // nachher wieder entfernen + // public static List<Concept> retrievals = new LinkedList<Concept>(); + + public SortedSet<Individual> retrieval(Concept concept) { + // Test, ob tatsächlich keine doppelten Retrievals ausgeführt werden + // retrievals.add(concept); + + reasoningStartTimeTmp = System.nanoTime(); + SortedSet<Individual> result; + try { + result = reasoner.retrieval(concept); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + nrOfRetrievals++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + retrievalReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public boolean instanceCheck(Concept concept, Individual s) { + reasoningStartTimeTmp = System.nanoTime(); + boolean result = false; + try { + result = reasoner.instanceCheck(concept, s); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + nrOfInstanceChecks++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + instanceCheckReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public Set<Individual> instanceCheck(Concept concept, Set<Individual> s) { + reasoningStartTimeTmp = System.nanoTime(); + Set<Individual> result = null; + try { + result = reasoner.instanceCheck(concept, s); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + nrOfInstanceChecks+=s.size(); + nrOfMultiInstanceChecks++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + instanceCheckReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + // c1 subsummiert c2 + public boolean subsumes(Concept superConcept, Concept subConcept) { + reasoningStartTimeTmp = System.nanoTime(); + boolean result = false; + try { + result = reasoner.subsumes(superConcept, subConcept); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + nrOfSubsumptionChecks++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + subsumptionReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public Set<Concept> subsumes(Set<Concept> superConcepts, Concept subConcept) { + reasoningStartTimeTmp = System.nanoTime(); + Set<Concept> result = null; + try { + result = reasoner.subsumes(superConcepts, subConcept); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + nrOfSubsumptionChecks += superConcepts.size(); + nrOfMultiSubsumptionChecks++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + subsumptionReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + /* + // Problem: wie behandle ich Top und Bottom? + // TODO: schauen wie das in KAON2 gemacht wird + public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { + if(Config.useHierarchyReasonerBenchmarks) + reasoningStartTimeTmp = System.nanoTime(); + SortedSet<Concept> result; + try { + result = reasoner.getMoreGeneralConcepts(concept); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + if(Config.useHierarchyReasonerBenchmarks) { + nrOfSubsumptionHierarchyQueries++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + subsumptionHierarchyTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + } + return result; + } + + public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { + if(Config.useHierarchyReasonerBenchmarks) + reasoningStartTimeTmp = System.nanoTime(); + SortedSet<Concept> result; + try { + result = reasoner.getMoreSpecialConcepts(concept); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + if(Config.useHierarchyReasonerBenchmarks) { + nrOfSubsumptionHierarchyQueries++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + subsumptionHierarchyTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + } + return result; + } + */ + + /** + * Returns more general concepts in the subsumption hierarchy. + * + * @param concept Atomic concept, top, or bottom. + * @return A set of more general concepts. + */ + public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { + return getSubsumptionHierarchy().getMoreGeneralConcepts(concept); + } + + /** + * Returns more special concepts in the subsumption hierarchy. + * + * @param concept Atomic concept, top, or bottom. + * @return A set of more special concepts. + */ + public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { + return getSubsumptionHierarchy().getMoreSpecialConcepts(concept); + } + + /** + * Returns more general concepts in the subsumption hierarchy. + * + * @see RoleHierarchy#getMoreGeneralRoles(AtomicRole) + * @param role Atomic concept, top, or bottom. + * @return A set of more general concepts. + */ + public SortedSet<AtomicRole> getMoreGeneralRoles(AtomicRole role) { + return getRoleHierarchy().getMoreGeneralRoles(role); + } + + /** + * Returns more special concepts in the subsumption hierarchy. + * + * @see RoleHierarchy#getMoreSpecialRoles(AtomicRole) + * @param role Atomic concept, top, or bottom. + * @return A set of more special concepts. + */ + public SortedSet<AtomicRole> getMoreSpecialRoles(AtomicRole role) { + return getRoleHierarchy().getMoreSpecialRoles(role); + } + + /** + * @see RoleHierarchy#getMostGeneralRoles() + * @return The most general roles. + */ + public TreeSet<AtomicRole> getMostGeneralRoles() { + return getRoleHierarchy().getMostGeneralRoles(); + } + + /** + * @see RoleHierarchy#getMostSpecialRoles() + * @return The most special roles. + */ + public TreeSet<AtomicRole> getMostSpecialRoles() { + return getRoleHierarchy().getMostSpecialRoles(); + } + + public SubsumptionHierarchy getSubsumptionHierarchy() { + try { + nrOfSubsumptionHierarchyQueries++; + return reasoner.getSubsumptionHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public RoleHierarchy getRoleHierarchy() { + try { + return reasoner.getRoleHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public boolean isSatisfiable() { + reasoningStartTimeTmp = System.nanoTime(); + boolean result; + try { + result = reasoner.isSatisfiable(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return false; + } + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + otherReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + // gibt zu einer Rolle alle Elemente zur�ck + // private, da es keine Standardoperation ist + public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) { + reasoningStartTimeTmp = System.nanoTime(); + Map<Individual, SortedSet<Individual>> result; + try { + result = reasoner.getRoleMembers(atomicRole); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + otherReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + // speichern einer Ontolgie wird speziell behandelt, da kein Reasoning + public void saveOntology(File file, OntologyFileFormat format) { + if (getReasonerType() == ReasonerType.KAON2) { + ((KAON2Reasoner) reasoner).saveOntology(file, format); + } else if (getReasonerType() == ReasonerType.DIG) { + // DIG erzeugt momentan auch nur einen KAON2-Reasoner und + // exportiert dann mit der obigen Funktion + ((DIGReasoner) reasoner).saveOntology(file, format); + } + } + + public Set<AtomicConcept> getAtomicConcepts() { + return reasoner.getAtomicConcepts(); + } + + public Set<AtomicRole> getAtomicRoles() { + return reasoner.getAtomicRoles(); + } + + public SortedSet<Individual> getIndividuals() { + return reasoner.getIndividuals(); + } + + public ReasonerType getReasonerType() { + return reasoner.getReasonerType(); + } + + public List<AtomicConcept> getAtomicConceptsList() { + return atomicConceptsList; + } + + public List<AtomicRole> getAtomicRolesList() { + return atomicRolesList; + } + + public long getInstanceCheckReasoningTimeNs() { + return instanceCheckReasoningTimeNs; + } + + public long getRetrievalReasoningTimeNs() { + return retrievalReasoningTimeNs; + } + + public int getNrOfInstanceChecks() { + return nrOfInstanceChecks; + } + + public int getNrOfRetrievals() { + return nrOfRetrievals; + } + + public int getNrOfSubsumptionChecks() { + return nrOfSubsumptionChecks; + } + + public long getSubsumptionReasoningTimeNs() { + return subsumptionReasoningTimeNs; + } + + /* + public long getSubsumptionHierarchyTimeNs() { + return subsumptionHierarchyTimeNs; + } + */ + public int getNrOfSubsumptionHierarchyQueries() { + return nrOfSubsumptionHierarchyQueries; + } + + + public long getOver... [truncated message content] |
From: <jen...@us...> - 2007-09-29 18:30:32
|
Revision: 157 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=157&view=rev Author: jenslehmann Date: 2007-09-29 11:30:29 -0700 (Sat, 29 Sep 2007) Log Message: ----------- config options extended Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ConfigOption.java trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java trunk/src/dl-learner/org/dllearner/kb/OWLFile.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-09-29 18:30:29 UTC (rev 157) @@ -58,8 +58,8 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new IntegerConfigOption("numberOfTrees")); - options.add(new IntegerConfigOption("maxDepth")); + options.add(new IntegerConfigOption("numberOfTrees", "number of randomly generated concepts/trees")); + options.add(new IntegerConfigOption("maxDepth", "maximum depth of generated concepts/trees")); return options; } Modified: trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/BooleanConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -27,8 +27,8 @@ */ public class BooleanConfigOption extends ConfigOption<Boolean> { - public BooleanConfigOption(String name) { - super(name); + public BooleanConfigOption(String name, String description) { + super(name, description); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/CommonConfigOptions.java 2007-09-29 18:30:29 UTC (rev 157) @@ -27,7 +27,7 @@ public static final IntegerConfigOption getVerbosityOption() { // TODO: temporary code - IntegerConfigOption verbosityOption = new IntegerConfigOption("verbosity"); + IntegerConfigOption verbosityOption = new IntegerConfigOption("verbosity", "control verbosity of output"); return verbosityOption; } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-29 18:30:29 UTC (rev 157) @@ -42,7 +42,14 @@ /** - * Central manager class for DL-Learner. + * Central manager class for DL-Learner. There are currently four types of components + * in DL-Learner: knowledge sources, reasoners, learning problems, and learning + * algorithms. For accessing these components you should create instances and + * configure them using this class. The component manager is implemented as a + * Singleton and will read the components file (containing a list of all components) + * at startup. This allows interfaces (command line, graphical, web service) to + * easily query the available components, set and get their configuration options, + * and run the algorithm. * * @author Jens Lehmann * @@ -375,4 +382,31 @@ return null; } + private <T,U> T invokeConstructor(Class<T> clazz, Class<U> argumentClass, U argumentObject) { + try { + Constructor<T> constructor = clazz.getConstructor(argumentClass); + return constructor.newInstance(argumentObject); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/ConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -33,17 +33,38 @@ */ public abstract class ConfigOption<T> { - private String name; + protected String name; - public ConfigOption(String name) { + protected String description; + + protected T defaultValue; + + public ConfigOption(String name, String description) { + this(name, description, null); + } + + public ConfigOption(String name, String description, T defaultValue) { this.name = name; + this.description = description; + this.defaultValue = defaultValue; } public String getName() { return name; } + public String getDescription() { + return description; + } + /** + * @return the defaultValue + */ + public T getDefaultValue() { + return defaultValue; + } + + /** * Checks whether the object has the correct type to be used as * a value for this option (this method is necessary, because * generic information is erased at runtime in Java). @@ -55,4 +76,13 @@ public abstract boolean isValidValue(T value); + public static String getRestrictionDescription() { + return "none"; + } + + @Override + public String toString() { + return "option name: " + name + "\ndescription: " + description + "\nvalues: " + getRestrictionDescription() + "\ndefault value: " + defaultValue + "\n"; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -31,8 +31,8 @@ private int lowerLimit = Integer.MIN_VALUE; private int upperLimit = Integer.MAX_VALUE; - public IntegerConfigOption(String name) { - super(name); + public IntegerConfigOption(String name, String description) { + super(name, description); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/StringConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -33,8 +33,8 @@ private Set<String> allowedValues; - public StringConfigOption(String name) { - super(name); + public StringConfigOption(String name, String description) { + super(name, description); allowedValues = new TreeSet<String>(); } Modified: trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/core/StringSetConfigOption.java 2007-09-29 18:30:29 UTC (rev 157) @@ -27,8 +27,8 @@ */ public class StringSetConfigOption extends ConfigOption<Set<String>> { - public StringSetConfigOption(String name) { - super(name); + public StringSetConfigOption(String name, String description) { + super(name, description); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-09-29 18:30:29 UTC (rev 157) @@ -49,7 +49,7 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("url")); + options.add(new StringConfigOption("url", "URL pointing to the OWL file")); return options; } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-09-29 18:30:29 UTC (rev 157) @@ -63,9 +63,12 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringSetConfigOption("positiveExamples")); - options.add(new StringSetConfigOption("negativeExamples")); - options.add(new BooleanConfigOption("useRetrievalForClassficiation")); + options.add(new StringSetConfigOption("positiveExamples", + "positive examples")); + options.add(new StringSetConfigOption("negativeExamples", + "negative examples")); + options.add(new BooleanConfigOption("useRetrievalForClassficiation", + "Specifies whether to use retrieval or instance checks for testing a concept.")); return options; } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-26 16:57:52 UTC (rev 156) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-29 18:30:29 UTC (rev 157) @@ -144,7 +144,7 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("reasonerUrl")); + options.add(new StringConfigOption("reasonerUrl", "URL of the DIG reasoner")); return options; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-01 14:41:41
|
Revision: 159 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=159&view=rev Author: jenslehmann Date: 2007-10-01 07:41:28 -0700 (Mon, 01 Oct 2007) Log Message: ----------- - added method for automatically documenting all config options - some smaller structural changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/dl/RoleHierarchy.java trunk/src/dl-learner/org/dllearner/core/dl/SubsumptionHierarchy.java trunk/src/dl-learner/org/dllearner/utilities/Files.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-01 14:41:28 UTC (rev 159) @@ -22,7 +22,6 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; @@ -70,6 +69,7 @@ import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; +import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; import org.dllearner.utilities.RoleComparator; import org.dllearner.utilities.Stat; @@ -954,7 +954,7 @@ // am Ende => man kann den Test also auch zwischendurch abbrechen for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { - createFile(fileAr[j][k], exportString[j][k].toString()); + Files.createFile(fileAr[j][k], exportString[j][k].toString()); } } } @@ -964,29 +964,6 @@ + Helper.prettyPrintNanoSeconds(overallTime)); } - // creates a file with the given content - public static void createFile(File file, String content) { - try { - FileOutputStream fos = new FileOutputStream(file); - fos.write(content.getBytes()); - fos.close(); - } catch (Exception e) { - System.out.println(e); - System.exit(0); - } - } - - public static void appendFile(File file, String content) { - try { - FileOutputStream fos = new FileOutputStream(file, true); - fos.write(content.getBytes()); - fos.close(); - } catch (Exception e) { - System.out.println(e); - System.exit(0); - } - } - // TODO: query mode umschreiben private void processQueryMode(Reasoner reasoner) { Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -11,7 +11,6 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; -import org.dllearner.Main; import org.dllearner.Score; import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.core.dl.Concept; @@ -20,6 +19,7 @@ import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; +import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; public class ROLearner implements LearningAlgorithm { @@ -330,7 +330,7 @@ searchTree += treeString + "\n"; // TODO: ev. immer nur einen search tree speichern und den an die // Datei anhängen => spart Speicher - Main.createFile(Config.Refinement.searchTreeFile, searchTree); + Files.createFile(Config.Refinement.searchTreeFile, searchTree); } // Anzahl Schleifendurchläufe @@ -343,7 +343,7 @@ // Suchbaum in Datei schreiben if(Config.Refinement.writeSearchTree) - Main.createFile(Config.Refinement.searchTreeFile, searchTree); + Files.createFile(Config.Refinement.searchTreeFile, searchTree); // Ergebnisausgabe /* Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-01 14:41:28 UTC (rev 159) @@ -21,6 +21,7 @@ import java.io.BufferedReader; import java.io.DataInputStream; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -38,6 +39,8 @@ import java.util.TreeMap; import java.util.TreeSet; +import org.dllearner.utilities.Files; + /** * Central manager class for DL-Learner. There are currently four types of * components in DL-Learner: knowledge sources, reasoners, learning problems, @@ -296,6 +299,51 @@ return invokeConstructor(la, new Class[] { constructorArgument }, new Object[] { lp }); } + public void writeConfigDocumentation(File file) { + String doc = ""; + doc += "This file contains an automatically generated files of all components and their config options.\n\n"; + + // go through all types of components and write down their documentation + doc += "*********************\n"; + doc += "* Knowledge Sources *\n"; + doc += "*********************\n\n"; + for(Class<? extends Component> component : knowledgeSources) + doc += getComponentConfigString(component); + + doc += "*************\n"; + doc += "* Reasoners *\n"; + doc += "*************\n\n"; + for(Class<? extends Component> component : reasonerComponents) + doc += getComponentConfigString(component); + + doc += "*********************\n"; + doc += "* Learning Problems *\n"; + doc += "*********************\n\n"; + for(Class<? extends Component> component : learningProblems) + doc += getComponentConfigString(component); + + doc += "***********************\n"; + doc += "* Learning Algorithms *\n"; + doc += "***********************\n\n"; + for(Class<? extends Component> component : learningAlgorithms) + doc += getComponentConfigString(component); + + Files.createFile(file, doc); + } + + private String getComponentConfigString(Class<? extends Component> component) { + String componentDescription = "component: " + invokeStaticMethod(component,"getName") + " (" + component.getName() + ")"; + String str = componentDescription + "\n"; + for(int i=0; i<componentDescription.length(); i++) + str += "="; + str += "\n\n"; + + for(ConfigOption<?> option : componentOptions.get(component)) { + str += option.toString() + "\n"; + } + return str; + } + private Object invokeStaticMethod(Class<?> clazz, String methodName, Object... args) { // unfortunately Java does not seem to offer a way to call // a static method given a class object directly, so we have Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-01 14:41:28 UTC (rev 159) @@ -44,6 +44,8 @@ // get singleton instance of component manager ComponentManager cm = ComponentManager.getInstance(); + cm.writeConfigDocumentation(new File("doc/configOptionsNew.txt")); + // create knowledge source KnowledgeSource source = cm.knowledgeSource(OWLFile.class); String example = "examples/father.owl"; Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -28,9 +28,9 @@ import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.reasoning.ReasonerType; -import org.dllearner.reasoning.RoleHierarchy; -import org.dllearner.reasoning.SubsumptionHierarchy; import org.dllearner.utilities.SortedSetTuple; /** Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2007-10-01 14:41:28 UTC (rev 159) @@ -29,8 +29,8 @@ import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; -import org.dllearner.reasoning.RoleHierarchy; -import org.dllearner.reasoning.SubsumptionHierarchy; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.utilities.SortedSetTuple; /** Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-01 14:41:28 UTC (rev 159) @@ -33,11 +33,11 @@ import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.KAON2Reasoner; import org.dllearner.reasoning.ReasonerType; -import org.dllearner.reasoning.RoleHierarchy; -import org.dllearner.reasoning.SubsumptionHierarchy; import org.dllearner.utilities.SortedSetTuple; /** Copied: trunk/src/dl-learner/org/dllearner/core/dl/RoleHierarchy.java (from rev 152, trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/dl/RoleHierarchy.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/dl/RoleHierarchy.java 2007-10-01 14:41:28 UTC (rev 159) @@ -0,0 +1,109 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.dl; + +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.dllearner.utilities.RoleComparator; + +/** + * Represents a hierarchy of roles. + * + * @todo Currently, the role hierarchy pruning algorithm (analogous to the + * subsumption hierarchy) is not implemented. + * + * @author Jens Lehmann + * + */ +public class RoleHierarchy { + + RoleComparator rc = new RoleComparator(); + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp; + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown; + TreeSet<AtomicRole> mostGeneralRoles = new TreeSet<AtomicRole>(rc); + TreeSet<AtomicRole> mostSpecialRoles = new TreeSet<AtomicRole>(rc); + + public RoleHierarchy(Set<AtomicRole> atomicRoles, TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp , TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown) { + this.roleHierarchyUp = roleHierarchyUp; + this.roleHierarchyDown = roleHierarchyDown; + + // find most general and most special roles + for(AtomicRole role : atomicRoles) { + if(getMoreGeneralRoles(role).size()==0) + mostGeneralRoles.add(role); + if(getMoreSpecialRoles(role).size()==0) + mostSpecialRoles.add(role); + } + } + + @SuppressWarnings("unchecked") + public SortedSet<AtomicRole> getMoreGeneralRoles(AtomicRole role) { + // we clone all concepts before returning them such that they cannot be + // modified externally + return (TreeSet<AtomicRole>) roleHierarchyUp.get(role).clone(); + } + + @SuppressWarnings("unchecked") + public SortedSet<AtomicRole> getMoreSpecialRoles(AtomicRole role) { + return (TreeSet<AtomicRole>) roleHierarchyDown.get(role).clone(); + } + + + + @Override + public String toString() { + String str = ""; + for(AtomicRole role : mostGeneralRoles) { + str += toString(roleHierarchyDown, role, 0); + } + return str; + } + + private String toString(TreeMap<AtomicRole,TreeSet<AtomicRole>> hierarchy, AtomicRole role, int depth) { + String str = ""; + for(int i=0; i<depth; i++) + str += " "; + str += role.toString() + "\n"; + Set<AtomicRole> tmp = hierarchy.get(role); + if(tmp!=null) { + for(AtomicRole c : tmp) + str += toString(hierarchy, c, depth+1); + } + return str; + } + + /** + * @return The most general roles. + */ + public TreeSet<AtomicRole> getMostGeneralRoles() { + return mostGeneralRoles; + } + + /** + * @return The most special roles. + */ + public TreeSet<AtomicRole> getMostSpecialRoles() { + return mostSpecialRoles; + } + +} Copied: trunk/src/dl-learner/org/dllearner/core/dl/SubsumptionHierarchy.java (from rev 152, trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/dl/SubsumptionHierarchy.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/dl/SubsumptionHierarchy.java 2007-10-01 14:41:28 UTC (rev 159) @@ -0,0 +1,125 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.dl; + +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.dllearner.utilities.ConceptComparator; + +/** + * Represents a subsumption hierarchy (ignoring equivalent concepts). + * + * @author Jens Lehmann + * + */ +public class SubsumptionHierarchy { + + ConceptComparator conceptComparator = new ConceptComparator(); + TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + Set<Concept> allowedConceptsInSubsumptionHierarchy; + + public SubsumptionHierarchy(Set<AtomicConcept> atomicConcepts, TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp , TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown) { + this.subsumptionHierarchyUp = subsumptionHierarchyUp; + this.subsumptionHierarchyDown = subsumptionHierarchyDown; + allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); + allowedConceptsInSubsumptionHierarchy.addAll(atomicConcepts); + allowedConceptsInSubsumptionHierarchy.add(new Top()); + allowedConceptsInSubsumptionHierarchy.add(new Bottom()); + } + + @SuppressWarnings("unchecked") + public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { + // we clone all concepts before returning them such that they cannot be + // modified externally + return (TreeSet<Concept>) subsumptionHierarchyUp.get(concept).clone(); + } + + @SuppressWarnings("unchecked") + public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { + return (TreeSet<Concept>) subsumptionHierarchyDown.get(concept).clone(); + } + + public void improveSubsumptionHierarchy() { + TreeMap<Concept,TreeSet<Concept>> hierarchyDownNew = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + // hierarchyDownNew.put(new Top(), new TreeSet<Concept>(conceptComparator)); + TreeMap<Concept,TreeSet<Concept>> hierarchyUpNew = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + + // Einträge für alle Konzepte machen (init) + for(Concept c : allowedConceptsInSubsumptionHierarchy) { + hierarchyDownNew.put(c, new TreeSet<Concept>(conceptComparator)); + hierarchyUpNew.put(c, new TreeSet<Concept>(conceptComparator)); + } + + for(Concept c : allowedConceptsInSubsumptionHierarchy) { + // schauen, ob es mehrere allgemeinere Nachbarn gibt + SortedSet<Concept> moreGeneral = subsumptionHierarchyUp.get(c); + if(moreGeneral != null) { + Concept chosenParent = moreGeneral.first(); + hierarchyDownNew.get(chosenParent).add(c); + } + } + + // for(Concept c : allowedConceptsInSubsumptionHierarchy) { + for(Concept c : allowedConceptsInSubsumptionHierarchy) { + SortedSet<Concept> moreSpecial = subsumptionHierarchyDown.get(c); + if(moreSpecial != null) { + Concept chosenParent = moreSpecial.first(); + hierarchyUpNew.get(chosenParent).add(c); + } + } + + subsumptionHierarchyDown = hierarchyDownNew; + subsumptionHierarchyUp = hierarchyUpNew; + } + + @Override + public String toString() { + return toString(false); + } + + public String toString(boolean showUpwardHierarchy) { + if(showUpwardHierarchy) { + String str = "downward subsumption:\n"; + str += toString(subsumptionHierarchyDown, new Top(), 0); + str += "upward subsumption:\n"; + str += toString(subsumptionHierarchyUp, new Bottom(), 0); + return str; + } else { + return toString(subsumptionHierarchyDown, new Top(), 0); + } + } + + private String toString(TreeMap<Concept,TreeSet<Concept>> hierarchy, Concept concept, int depth) { + String str = ""; + for(int i=0; i<depth; i++) + str += " "; + str += concept.toString() + "\n"; + Set<Concept> tmp = hierarchy.get(concept); + if(tmp!=null) { + for(Concept c : tmp) + str += toString(hierarchy, c, depth+1); + } + return str; + } +} Modified: trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -12,6 +12,8 @@ import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.utilities.SortedSetTuple; public abstract class AbstractReasoner implements Reasoner { Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2007-10-01 14:41:28 UTC (rev 159) @@ -13,7 +13,7 @@ import org.apache.xmlbeans.XmlException; import org.dllearner.Config; -import org.dllearner.Main; +import org.dllearner.utilities.Files; import org.kr.dl.dig.v1_1.GetIdentifierDocument; import org.kr.dl.dig.v1_1.IdRespType; import org.kr.dl.dig.v1_1.IdentifierDocument; @@ -132,7 +132,7 @@ osw.close(); if(Config.writeDIGProtocol) - Main.appendFile(Config.digProtocolFile, "DIG code send to reasoner:\n\n"+send+"\n\n"); + Files.appendFile(Config.digProtocolFile, "DIG code send to reasoner:\n\n"+send+"\n\n"); // Antwort empfangen InputStream is = connection.getInputStream(); @@ -155,7 +155,7 @@ // DIG-Kommunikation protokollieren, falls das eingestellt ist if(Config.writeDIGProtocol) - Main.appendFile(Config.digProtocolFile, "DIG code received from reasoner:\n\n"+answer+"\n\n"); + Files.appendFile(Config.digProtocolFile, "DIG code received from reasoner:\n\n"+answer+"\n\n"); return answer.toString(); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -42,6 +42,8 @@ import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java 2007-10-01 14:41:28 UTC (rev 159) @@ -49,6 +49,8 @@ import org.dllearner.core.dl.Bottom; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.core.dl.Top; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2007-10-01 14:41:28 UTC (rev 159) @@ -78,7 +78,7 @@ Set<AtomicRole> atomicRoles; SortedSet<Individual> individuals; SubsumptionHierarchy kaon2SubsumptionHierarchy = null; - org.dllearner.reasoning.SubsumptionHierarchy subsumptionHierarchy; + org.dllearner.core.dl.SubsumptionHierarchy subsumptionHierarchy; private org.semanticweb.kaon2.api.reasoner.Reasoner kaon2Reasoner; private KAON2Connection kaon2Connection; @@ -270,7 +270,7 @@ subsumptionHierarchyUp.put(ac, (TreeSet<Concept>) getConceptsFromSubsumptionHierarchyNodes(kaon2SubsumptionHierarchy.getNodeFor(kaon2Ac).getParentNodes())); } - subsumptionHierarchy = new org.dllearner.reasoning.SubsumptionHierarchy(atomicConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); + subsumptionHierarchy = new org.dllearner.core.dl.SubsumptionHierarchy(atomicConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); } @Override @@ -399,7 +399,7 @@ */ @Override - public org.dllearner.reasoning.SubsumptionHierarchy getSubsumptionHierarchy() { + public org.dllearner.core.dl.SubsumptionHierarchy getSubsumptionHierarchy() { return subsumptionHierarchy; } Deleted: trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/RoleHierarchy.java 2007-10-01 14:41:28 UTC (rev 159) @@ -1,110 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.reasoning; - -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.dllearner.core.dl.AtomicRole; -import org.dllearner.utilities.RoleComparator; - -/** - * Represents a hierarchy of roles. - * - * @todo Currently, the role hierarchy pruning algorithm (analogous to the - * subsumption hierarchy) is not implemented. - * - * @author Jens Lehmann - * - */ -public class RoleHierarchy { - - RoleComparator rc = new RoleComparator(); - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp; - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown; - TreeSet<AtomicRole> mostGeneralRoles = new TreeSet<AtomicRole>(rc); - TreeSet<AtomicRole> mostSpecialRoles = new TreeSet<AtomicRole>(rc); - - public RoleHierarchy(Set<AtomicRole> atomicRoles, TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp , TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown) { - this.roleHierarchyUp = roleHierarchyUp; - this.roleHierarchyDown = roleHierarchyDown; - - // find most general and most special roles - for(AtomicRole role : atomicRoles) { - if(getMoreGeneralRoles(role).size()==0) - mostGeneralRoles.add(role); - if(getMoreSpecialRoles(role).size()==0) - mostSpecialRoles.add(role); - } - } - - @SuppressWarnings("unchecked") - public SortedSet<AtomicRole> getMoreGeneralRoles(AtomicRole role) { - // we clone all concepts before returning them such that they cannot be - // modified externally - return (TreeSet<AtomicRole>) roleHierarchyUp.get(role).clone(); - } - - @SuppressWarnings("unchecked") - public SortedSet<AtomicRole> getMoreSpecialRoles(AtomicRole role) { - return (TreeSet<AtomicRole>) roleHierarchyDown.get(role).clone(); - } - - - - @Override - public String toString() { - String str = ""; - for(AtomicRole role : mostGeneralRoles) { - str += toString(roleHierarchyDown, role, 0); - } - return str; - } - - private String toString(TreeMap<AtomicRole,TreeSet<AtomicRole>> hierarchy, AtomicRole role, int depth) { - String str = ""; - for(int i=0; i<depth; i++) - str += " "; - str += role.toString() + "\n"; - Set<AtomicRole> tmp = hierarchy.get(role); - if(tmp!=null) { - for(AtomicRole c : tmp) - str += toString(hierarchy, c, depth+1); - } - return str; - } - - /** - * @return The most general roles. - */ - public TreeSet<AtomicRole> getMostGeneralRoles() { - return mostGeneralRoles; - } - - /** - * @return The most special roles. - */ - public TreeSet<AtomicRole> getMostSpecialRoles() { - return mostSpecialRoles; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/reasoning/SubsumptionHierarchy.java 2007-10-01 14:41:28 UTC (rev 159) @@ -1,129 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.reasoning; - -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.dllearner.core.dl.AtomicConcept; -import org.dllearner.core.dl.Bottom; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Top; -import org.dllearner.utilities.ConceptComparator; - -/** - * Represents a subsumption hierarchy (ignoring equivalent concepts). - * - * @author Jens Lehmann - * - */ -public class SubsumptionHierarchy { - - ConceptComparator conceptComparator = new ConceptComparator(); - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - Set<Concept> allowedConceptsInSubsumptionHierarchy; - - public SubsumptionHierarchy(Set<AtomicConcept> atomicConcepts, TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp , TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown) { - this.subsumptionHierarchyUp = subsumptionHierarchyUp; - this.subsumptionHierarchyDown = subsumptionHierarchyDown; - allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); - allowedConceptsInSubsumptionHierarchy.addAll(atomicConcepts); - allowedConceptsInSubsumptionHierarchy.add(new Top()); - allowedConceptsInSubsumptionHierarchy.add(new Bottom()); - } - - @SuppressWarnings("unchecked") - public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { - // we clone all concepts before returning them such that they cannot be - // modified externally - return (TreeSet<Concept>) subsumptionHierarchyUp.get(concept).clone(); - } - - @SuppressWarnings("unchecked") - public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { - return (TreeSet<Concept>) subsumptionHierarchyDown.get(concept).clone(); - } - - public void improveSubsumptionHierarchy() { - TreeMap<Concept,TreeSet<Concept>> hierarchyDownNew = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - // hierarchyDownNew.put(new Top(), new TreeSet<Concept>(conceptComparator)); - TreeMap<Concept,TreeSet<Concept>> hierarchyUpNew = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - - // Einträge für alle Konzepte machen (init) - for(Concept c : allowedConceptsInSubsumptionHierarchy) { - hierarchyDownNew.put(c, new TreeSet<Concept>(conceptComparator)); - hierarchyUpNew.put(c, new TreeSet<Concept>(conceptComparator)); - } - - for(Concept c : allowedConceptsInSubsumptionHierarchy) { - // schauen, ob es mehrere allgemeinere Nachbarn gibt - SortedSet<Concept> moreGeneral = subsumptionHierarchyUp.get(c); - if(moreGeneral != null) { - Concept chosenParent = moreGeneral.first(); - hierarchyDownNew.get(chosenParent).add(c); - } - } - - // for(Concept c : allowedConceptsInSubsumptionHierarchy) { - for(Concept c : allowedConceptsInSubsumptionHierarchy) { - SortedSet<Concept> moreSpecial = subsumptionHierarchyDown.get(c); - if(moreSpecial != null) { - Concept chosenParent = moreSpecial.first(); - hierarchyUpNew.get(chosenParent).add(c); - } - } - - subsumptionHierarchyDown = hierarchyDownNew; - subsumptionHierarchyUp = hierarchyUpNew; - } - - @Override - public String toString() { - return toString(false); - } - - public String toString(boolean showUpwardHierarchy) { - if(showUpwardHierarchy) { - String str = "downward subsumption:\n"; - str += toString(subsumptionHierarchyDown, new Top(), 0); - str += "upward subsumption:\n"; - str += toString(subsumptionHierarchyUp, new Bottom(), 0); - return str; - } else { - return toString(subsumptionHierarchyDown, new Top(), 0); - } - } - - private String toString(TreeMap<Concept,TreeSet<Concept>> hierarchy, Concept concept, int depth) { - String str = ""; - for(int i=0; i<depth; i++) - str += " "; - str += concept.toString() + "\n"; - Set<Concept> tmp = hierarchy.get(concept); - if(tmp!=null) { - for(Concept c : tmp) - str += toString(hierarchy, c, depth+1); - } - return str; - } -} Added: trunk/src/dl-learner/org/dllearner/utilities/Files.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Files.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/Files.java 2007-10-01 14:41:28 UTC (rev 159) @@ -0,0 +1,78 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.utilities; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * @author Jens Lehmann + * + */ +public class Files { + + /** + * Creates a new file with the given content or replaces the content of a + * file. + * + * @param file + * The file to use. + * @param content + * Content of the file. + */ + public static void createFile(File file, String content) { + try { + FileOutputStream fos = new FileOutputStream(file); + fos.write(content.getBytes()); + fos.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * Appends content to a file. + * + * @param file + * The file to create. + * @param content + * Content of the file. + */ + public static void appendFile(File file, String content) { + try { + FileOutputStream fos = new FileOutputStream(file, true); + fos.write(content.getBytes()); + fos.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-09-30 13:11:00 UTC (rev 158) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-01 14:41:28 UTC (rev 159) @@ -291,7 +291,7 @@ statDetailsString += "concept length: " + conceptLength + "\n"; statDetailsString += "runtime: " + Helper.prettyPrintNanoSeconds(algorithmTime) + "\n\n"; - Main.createFile(statDetailsFile, statDetailsString); + Files.createFile(statDetailsFile, statDetailsString); } // end run loop @@ -300,7 +300,7 @@ statString += "concept length: " + length.getMean() + " (standard deviation: " + length.getStandardDeviation() + ")\n"; statString += "runtime: " + Helper.prettyPrintNanoSeconds(Math.round(runtime.getMean())) + " (standard deviation: " + Helper.prettyPrintNanoSeconds(Math.round(runtime.getStandardDeviation())) + ")\n\n"; - Main.createFile(statFile, statString); + Files.createFile(statFile, statString); } // end algorithm loop This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-01 17:14:20
|
Revision: 160 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=160&view=rev Author: jenslehmann Date: 2007-10-01 10:14:03 -0700 (Mon, 01 Oct 2007) Log Message: ----------- changed previous static parser to dynamic parser Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java trunk/src/dl-learner/org/dllearner/parser/dllearner.jj trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-10-01 14:41:28 UTC (rev 159) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-10-01 17:14:03 UTC (rev 160) @@ -12,6 +12,7 @@ import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringReader; @@ -24,21 +25,21 @@ // @SuppressWarnings({"all"}) public @SuppressWarnings("all") class DLLearner/*@bgen(jjtree)*/implements DLLearnerTreeConstants, DLLearnerConstants {/*@bgen(jjtree)*/ - protected static JJTDLLearnerState jjtree = new JJTDLLearnerState(); + protected JJTDLLearnerState jjtree = new JJTDLLearnerState(); private static ConceptComparator conceptComparator = new ConceptComparator(); // hier wird Parse-Fehler angezeigt, obwohl eigentlich alles stimmt?? - private static Map<AtomicConcept,SortedSet<Individual>> positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); - private static Map<AtomicConcept,SortedSet<Individual>> negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + private Map<AtomicConcept,SortedSet<Individual>> positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + private Map<AtomicConcept,SortedSet<Individual>> negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); // Konfigurationsoptionen - private static List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe // werden in einer Liste gespeichert - private static List<List<String>> functionCalls = new LinkedList<List<String>>(); + private List<List<String>> functionCalls = new LinkedList<List<String>>(); // => irgendwie Funktionsname + Argumente speichern // => d.h. man bräuchte für jede Funktion so eine Liste oder das erste Element // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante @@ -47,13 +48,13 @@ // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal // aufgerufen werden; weitere Parsevorgänge erfolgen dann mit ReInit // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser - private static boolean constructorCalled = false; + // private static boolean constructorCalled = false; // Wissensbasis - private static KB kb = new KB(); + private KB kb = new KB(); public static final String internalNamespace = "http://localhost/foo#"; - private static void addPositiveExample(AtomicConcept conceptName, Individual instanceName) { + private void addPositiveExample(AtomicConcept conceptName, Individual instanceName) { if(positiveExamples.containsKey(conceptName)) { positiveExamples.get(conceptName).add(instanceName); } else { @@ -63,7 +64,7 @@ } } - private static void addNegativeExample(AtomicConcept conceptName, Individual instanceName) { + private void addNegativeExample(AtomicConcept conceptName, Individual instanceName) { if(negativeExamples.containsKey(conceptName)) { negativeExamples.get(conceptName).add(instanceName); } else { @@ -73,23 +74,23 @@ } } - public static Map<AtomicConcept,SortedSet<Individual>> getPositiveExamples() { + public Map<AtomicConcept,SortedSet<Individual>> getPositiveExamples() { return positiveExamples; } - public static Map<AtomicConcept,SortedSet<Individual>> getNegativeExamples() { + public Map<AtomicConcept,SortedSet<Individual>> getNegativeExamples() { return negativeExamples; } - public static List<ConfigurationOption> getConfOptions() { + public List<ConfigurationOption> getConfOptions() { return confOptions; } - public static List<List<String>> getFunctionCalls() { + public List<List<String>> getFunctionCalls() { return functionCalls; } - public static KB getKB() { + public KB getKB() { return kb; } @@ -117,19 +118,14 @@ public static SimpleNode parseString(String str) throws ParseException { StringReader sr = new StringReader(str); - // new DLLearner(sr); - DLLearner.ReInit(sr); - SimpleNode n = DLLearner.Start(); + DLLearner learner = new DLLearner(sr); + SimpleNode n = learner.Start(); return n; } public static Concept parseConcept(String str) throws ParseException { StringReader sr = new StringReader(str); - if(constructorCalled) - DLLearner.ReInit(sr); - else - new DLLearner(sr); - constructorCalled = true; + DLLearner learner = new DLLearner(sr); // //SimpleNode n = DLLearner.Start(); //return n; @@ -142,29 +138,22 @@ // TODO Auto-generated catch block e.printStackTrace(); }*/ - Concept c = DLLearner.Concept(); + Concept c = learner.Concept(); return c; } - public static void parseFile(String filename) { - - positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); - negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); - confOptions = new LinkedList<ConfigurationOption>(); - functionCalls = new LinkedList<List<String>>(); - kb = new KB(); - + public static DLLearner parseFile(String filename) { + DLLearner learner = null; try { - if(constructorCalled) - DLLearner.ReInit(new FileInputStream(filename)); - else - new DLLearner(new FileInputStream(filename)); - constructorCalled = true; - DLLearner.Start(); - } catch(Exception e) { + learner = new DLLearner(new FileInputStream(filename)); + learner.Start(); + } catch(FileNotFoundException e) { e.printStackTrace(); + } catch(ParseException e) { + e.printStackTrace(); } + return learner; } public static void main(String args[]) { @@ -188,16 +177,16 @@ long parseStartTime = System.currentTimeMillis(); SimpleNode n = null; + DLLearner learner = null; try { - new DLLearner(new FileInputStream(args[args.length-1])); - constructorCalled = true; + learner = new DLLearner(new FileInputStream(args[args.length-1])); baseDir = f.getParentFile().getPath(); } catch(IOException e) { System.err.println(e); System.exit(0); } try { - n = DLLearner.Start(); + n = learner.Start(); // n.dump(""); // System.out.println("Thank you."); } catch (Exception e) { @@ -228,7 +217,9 @@ // n.dump(""); // neuer Aufruf des Hauptprogramms - new Main(kb,positiveExamples,negativeExamples,confOptions,functionCalls,baseDir,queryMode); + // TODO: remove (in the future, the parser will be called from whatever method + // needs it, instead of starting the learning process itself) + // new Main(kb,positiveExamples,negativeExamples,confOptions,functionCalls,baseDir,queryMode); } /* Grob�berblick: @@ -244,7 +235,7 @@ | Concept() "=" Concept() <COMMAND_END> // TBox - �quivalenz von Konzepten | Concept() "SUBCLASS" Concept() <COMMAND_END> // TBox - Konzept 1 Teilmenge von Konzept 2 */ - static final public SimpleNode Start() throws ParseException { + final public SimpleNode Start() throws ParseException { /*@bgen(jjtree) Start */ SimpleNode jjtn000 = new SimpleNode(JJTSTART); boolean jjtc000 = true; @@ -253,6 +244,7 @@ RBoxAxiom rBoxAxiom; Equality equality; Inclusion inclusion; + ConfigurationOption confOption; try { label_1: while (true) { @@ -281,7 +273,8 @@ break label_1; } if (jj_2_1(2147483647)) { - ConfOption(); + confOption = ConfOption(); + confOptions.add(confOption); } else if (jj_2_2(2147483647)) { FunctionCall(); } else if (jj_2_3(2147483647)) { @@ -357,7 +350,25 @@ throw new Error("Missing return statement in function"); } - static final public void ConfOption() throws ParseException { + final public KB parseKB() throws ParseException { + /*@bgen(jjtree) parseKB */ + SimpleNode jjtn000 = new SimpleNode(JJTPARSEKB); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000);KB kb = null; + try { + jj_consume_token(0); + jjtree.closeNodeScope(jjtn000, true); + jjtc000 = false; + {if (true) return kb;} + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + throw new Error("Missing return statement in function"); + } + + final public ConfigurationOption ConfOption() throws ParseException { /*@bgen(jjtree) ConfOption */ SimpleNode jjtn000 = new SimpleNode(JJTCONFOPTION); boolean jjtc000 = true; @@ -476,7 +487,9 @@ else confOption = new ConfigurationOption(option,value); } - confOptions.add(confOption); + {if (true) return confOption;} + // confOptions.add(confOption); + } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); @@ -496,9 +509,10 @@ jjtree.closeNodeScope(jjtn000, true); } } + throw new Error("Missing return statement in function"); } - static final public void FunctionCall() throws ParseException { + final public void FunctionCall() throws ParseException { /*@bgen(jjtree) FunctionCall */ SimpleNode jjtn000 = new SimpleNode(JJTFUNCTIONCALL); boolean jjtc000 = true; @@ -549,7 +563,7 @@ } } - static final public void PosExample() throws ParseException { + final public void PosExample() throws ParseException { /*@bgen(jjtree) PosExample */ SimpleNode jjtn000 = new SimpleNode(JJTPOSEXAMPLE); boolean jjtc000 = true; @@ -585,7 +599,7 @@ } } - static final public void NegExample() throws ParseException { + final public void NegExample() throws ParseException { /*@bgen(jjtree) NegExample */ SimpleNode jjtn000 = new SimpleNode(JJTNEGEXAMPLE); boolean jjtc000 = true; @@ -621,7 +635,7 @@ } } - static final public ConceptAssertion ABoxConcept() throws ParseException { + final public ConceptAssertion ABoxConcept() throws ParseException { /*@bgen(jjtree) ABoxConcept */ SimpleNode jjtn000 = new SimpleNode(JJTABOXCONCEPT); boolean jjtc000 = true; @@ -657,7 +671,7 @@ throw new Error("Missing return statement in function"); } - static final public RoleAssertion ABoxRole() throws ParseException { + final public RoleAssertion ABoxRole() throws ParseException { /*@bgen(jjtree) ABoxRole */ SimpleNode jjtn000 = new SimpleNode(JJTABOXROLE); boolean jjtc000 = true; @@ -709,7 +723,7 @@ throw new Error("Missing return statement in function"); } - static final public TransitiveRoleAxiom Transitive() throws ParseException { + final public TransitiveRoleAxiom Transitive() throws ParseException { /*@bgen(jjtree) Transitive */ SimpleNode jjtn000 = new SimpleNode(JJTTRANSITIVE); boolean jjtc000 = true; @@ -745,7 +759,7 @@ throw new Error("Missing return statement in function"); } - static final public FunctionalRoleAxiom Functional() throws ParseException { + final public FunctionalRoleAxiom Functional() throws ParseException { /*@bgen(jjtree) Functional */ SimpleNode jjtn000 = new SimpleNode(JJTFUNCTIONAL); boolean jjtc000 = true; @@ -781,7 +795,7 @@ throw new Error("Missing return statement in function"); } - static final public SymmetricRoleAxiom Symmetric() throws ParseException { + final public SymmetricRoleAxiom Symmetric() throws ParseException { /*@bgen(jjtree) Symmetric */ SimpleNode jjtn000 = new SimpleNode(JJTSYMMETRIC); boolean jjtc000 = true; @@ -817,7 +831,7 @@ throw new Error("Missing return statement in function"); } - static final public InverseRoleAxiom Inverse() throws ParseException { + final public InverseRoleAxiom Inverse() throws ParseException { /*@bgen(jjtree) Inverse */ SimpleNode jjtn000 = new SimpleNode(JJTINVERSE); boolean jjtc000 = true; @@ -855,7 +869,7 @@ throw new Error("Missing return statement in function"); } - static final public SubRoleAxiom Subrole() throws ParseException { + final public SubRoleAxiom Subrole() throws ParseException { /*@bgen(jjtree) Subrole */ SimpleNode jjtn000 = new SimpleNode(JJTSUBROLE); boolean jjtc000 = true; @@ -954,7 +968,7 @@ { return new SubRoleAxiom(new AtomicRole(s1),new AtomicRole(s2));} } ****************************************************************/ - static final public Equality TBoxEquiv() throws ParseException { + final public Equality TBoxEquiv() throws ParseException { /*@bgen(jjtree) TBoxEquiv */ SimpleNode jjtn000 = new SimpleNode(JJTTBOXEQUIV); boolean jjtc000 = true; @@ -989,7 +1003,7 @@ throw new Error("Missing return statement in function"); } - static final public Inclusion TBoxSub() throws ParseException { + final public Inclusion TBoxSub() throws ParseException { /*@bgen(jjtree) TBoxSub */ SimpleNode jjtn000 = new SimpleNode(JJTTBOXSUB); boolean jjtc000 = true; @@ -1039,7 +1053,7 @@ } // TODO: Support f�r inverse Rollen - static final public Concept Concept() throws ParseException { + final public Concept Concept() throws ParseException { /*@bgen(jjtree) Concept */ SimpleNode jjtn000 = new SimpleNode(JJTCONCEPT); boolean jjtc000 = true; @@ -1165,7 +1179,7 @@ throw new Error("Missing return statement in function"); } - static final public void Or() throws ParseException { + final public void Or() throws ParseException { /*@bgen(jjtree) Or */ SimpleNode jjtn000 = new SimpleNode(JJTOR); boolean jjtc000 = true; @@ -1179,7 +1193,7 @@ } } - static final public void And() throws ParseException { + final public void And() throws ParseException { /*@bgen(jjtree) And */ SimpleNode jjtn000 = new SimpleNode(JJTAND); boolean jjtc000 = true; @@ -1193,7 +1207,7 @@ } } - static final public void Top() throws ParseException { + final public void Top() throws ParseException { /*@bgen(jjtree) Top */ SimpleNode jjtn000 = new SimpleNode(JJTTOP); boolean jjtc000 = true; @@ -1207,7 +1221,7 @@ } } - static final public void Bottom() throws ParseException { + final public void Bottom() throws ParseException { /*@bgen(jjtree) Bottom */ SimpleNode jjtn000 = new SimpleNode(JJTBOTTOM); boolean jjtc000 = true; @@ -1221,7 +1235,7 @@ } } - static final public void Exists() throws ParseException { + final public void Exists() throws ParseException { /*@bgen(jjtree) Exists */ SimpleNode jjtn000 = new SimpleNode(JJTEXISTS); boolean jjtc000 = true; @@ -1235,7 +1249,7 @@ } } - static final public void All() throws ParseException { + final public void All() throws ParseException { /*@bgen(jjtree) All */ SimpleNode jjtn000 = new SimpleNode(JJTALL); boolean jjtc000 = true; @@ -1249,7 +1263,7 @@ } } - static final public void Not() throws ParseException { + final public void Not() throws ParseException { /*@bgen(jjtree) Not */ SimpleNode jjtn000 = new SimpleNode(JJTNOT); boolean jjtc000 = true; @@ -1263,7 +1277,7 @@ } } - static final public void GE() throws ParseException { + final public void GE() throws ParseException { /*@bgen(jjtree) GE */ SimpleNode jjtn000 = new SimpleNode(JJTGE); boolean jjtc000 = true; @@ -1277,7 +1291,7 @@ } } - static final public void LE() throws ParseException { + final public void LE() throws ParseException { /*@bgen(jjtree) LE */ SimpleNode jjtn000 = new SimpleNode(JJTLE); boolean jjtc000 = true; @@ -1291,7 +1305,7 @@ } } - static final public AtomicConcept AtomicConcept() throws ParseException { + final public AtomicConcept AtomicConcept() throws ParseException { /*@bgen(jjtree) AtomicConcept */ SimpleNode jjtn000 = new SimpleNode(JJTATOMICCONCEPT); boolean jjtc000 = true; @@ -1334,7 +1348,7 @@ throw new Error("Missing return statement in function"); } - static final public AtomicRole AtomicRole() throws ParseException { + final public AtomicRole AtomicRole() throws ParseException { /*@bgen(jjtree) AtomicRole */ SimpleNode jjtn000 = new SimpleNode(JJTATOMICROLE); boolean jjtc000 = true; @@ -1377,7 +1391,7 @@ throw new Error("Missing return statement in function"); } - static final public Individual Individual() throws ParseException { + final public Individual Individual() throws ParseException { /*@bgen(jjtree) Individual */ SimpleNode jjtn000 = new SimpleNode(JJTINDIVIDUAL); boolean jjtc000 = true; @@ -1420,7 +1434,7 @@ throw new Error("Missing return statement in function"); } - static final public String Id() throws ParseException { + final public String Id() throws ParseException { /*@bgen(jjtree) Id */ SimpleNode jjtn000 = new SimpleNode(JJTID); boolean jjtc000 = true; @@ -1439,7 +1453,7 @@ throw new Error("Missing return statement in function"); } - static final public double Double() throws ParseException { + final public double Double() throws ParseException { /*@bgen(jjtree) Double */ SimpleNode jjtn000 = new SimpleNode(JJTDOUBLE); boolean jjtc000 = true; @@ -1457,7 +1471,7 @@ throw new Error("Missing return statement in function"); } - static final public int Integer() throws ParseException { + final public int Integer() throws ParseException { /*@bgen(jjtree) Integer */ SimpleNode jjtn000 = new SimpleNode(JJTINTEGER); boolean jjtc000 = true; @@ -1477,7 +1491,7 @@ throw new Error("Missing return statement in function"); } - static final public String String() throws ParseException { + final public String String() throws ParseException { /*@bgen(jjtree) String */ SimpleNode jjtn000 = new SimpleNode(JJTSTRING); boolean jjtc000 = true; @@ -1500,148 +1514,110 @@ throw new Error("Missing return statement in function"); } - static final private boolean jj_2_1(int xla) { + final private boolean jj_2_1(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_1(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(0, xla); } } - static final private boolean jj_2_2(int xla) { + final private boolean jj_2_2(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_2(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(1, xla); } } - static final private boolean jj_2_3(int xla) { + final private boolean jj_2_3(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_3(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(2, xla); } } - static final private boolean jj_2_4(int xla) { + final private boolean jj_2_4(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_4(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(3, xla); } } - static final private boolean jj_2_5(int xla) { + final private boolean jj_2_5(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_5(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(4, xla); } } - static final private boolean jj_2_6(int xla) { + final private boolean jj_2_6(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_6(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(5, xla); } } - static final private boolean jj_2_7(int xla) { + final private boolean jj_2_7(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_7(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(6, xla); } } - static final private boolean jj_2_8(int xla) { + final private boolean jj_2_8(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_8(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(7, xla); } } - static final private boolean jj_2_9(int xla) { + final private boolean jj_2_9(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_9(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(8, xla); } } - static final private boolean jj_2_10(int xla) { + final private boolean jj_2_10(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_10(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(9, xla); } } - static final private boolean jj_2_11(int xla) { + final private boolean jj_2_11(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_11(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(10, xla); } } - static final private boolean jj_2_12(int xla) { + final private boolean jj_2_12(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_12(); } catch(LookaheadSuccess ls) { return true; } finally { jj_save(11, xla); } } - static final private boolean jj_3R_34() { - if (jj_3R_39()) return true; - if (jj_3R_14()) return true; - return false; - } - - static final private boolean jj_3_12() { - if (jj_scan_token(29)) return true; - if (jj_3R_14()) return true; - if (jj_3R_21()) return true; - return false; - } - - static final private boolean jj_3R_12() { - if (jj_scan_token(STRING)) return true; - return false; - } - - static final private boolean jj_3R_33() { - if (jj_3R_48()) return true; + final private boolean jj_3R_32() { + if (jj_3R_47()) return true; if (jj_3R_17()) return true; if (jj_scan_token(COMMAND_END)) return true; if (jj_3R_14()) return true; return false; } - static final private boolean jj_3R_8() { - if (jj_3R_23()) return true; - return false; - } - - static final private boolean jj_3_11() { - if (jj_scan_token(29)) return true; - if (jj_3R_14()) return true; - if (jj_3R_20()) return true; - return false; - } - - static final private boolean jj_3_10() { + final private boolean jj_3_10() { if (jj_scan_token(26)) return true; if (jj_scan_token(27)) return true; return false; } - static final private boolean jj_3R_32() { - if (jj_3R_47()) return true; - if (jj_3R_17()) return true; - if (jj_scan_token(COMMAND_END)) return true; - if (jj_3R_14()) return true; + final private boolean jj_3R_26() { + if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_25() { - if (jj_3R_12()) return true; - return false; - } - - static final private boolean jj_3_9() { + final private boolean jj_3_9() { Token xsp; xsp = jj_scanpos; if (jj_3R_18()) { @@ -1652,7 +1628,7 @@ return false; } - static final private boolean jj_3R_31() { + final private boolean jj_3R_31() { if (jj_scan_token(29)) return true; if (jj_3R_14()) return true; if (jj_3R_21()) return true; @@ -1661,7 +1637,7 @@ return false; } - static final private boolean jj_3R_30() { + final private boolean jj_3R_30() { if (jj_scan_token(29)) return true; if (jj_3R_14()) return true; if (jj_3R_20()) return true; @@ -1670,32 +1646,37 @@ return false; } - static final private boolean jj_3R_7() { - if (jj_3R_22()) return true; + final private boolean jj_3R_8() { + if (jj_3R_23()) return true; return false; } - static final private boolean jj_3R_22() { + final private boolean jj_3R_22() { if (jj_scan_token(NUMBER)) return true; return false; } - static final private boolean jj_3R_29() { + final private boolean jj_3R_29() { if (jj_3R_46()) return true; return false; } - static final private boolean jj_3R_28() { + final private boolean jj_3R_28() { if (jj_3R_45()) return true; return false; } - static final private boolean jj_3R_27() { + final private boolean jj_3R_25() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_27() { if (jj_3R_44()) return true; return false; } - static final private boolean jj_3R_14() { + final private boolean jj_3R_14() { Token xsp; xsp = jj_scanpos; if (jj_3R_27()) { @@ -1729,17 +1710,27 @@ return false; } - static final private boolean jj_3R_6() { - if (jj_3R_4()) return true; + final private boolean jj_3R_7() { + if (jj_3R_22()) return true; return false; } - static final private boolean jj_3R_43() { + final private boolean jj_3R_23() { + if (jj_scan_token(DOUBLE)) return true; + return false; + } + + final private boolean jj_3R_38() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_6() { if (jj_3R_4()) return true; return false; } - static final private boolean jj_3_8() { + final private boolean jj_3_8() { if (jj_3R_14()) return true; Token xsp; xsp = jj_scanpos; @@ -1750,52 +1741,72 @@ return false; } - static final private boolean jj_3_7() { + final private boolean jj_3R_43() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3_7() { if (jj_3R_14()) return true; if (jj_scan_token(25)) return true; return false; } - static final private boolean jj_3R_13() { + final private boolean jj_3R_13() { if (jj_scan_token(28)) return true; if (jj_3R_12()) return true; return false; } - static final private boolean jj_3R_23() { - if (jj_scan_token(DOUBLE)) return true; + final private boolean jj_3R_4() { + if (jj_scan_token(ID)) return true; return false; } - static final private boolean jj_3R_38() { + final private boolean jj_3R_41() { if (jj_3R_12()) return true; return false; } - static final private boolean jj_3R_42() { - if (jj_3R_12()) return true; + final private boolean jj_3R_37() { + if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_24() { + final private boolean jj_3R_15() { Token xsp; xsp = jj_scanpos; - if (jj_3R_42()) { + if (jj_3R_37()) { jj_scanpos = xsp; - if (jj_3R_43()) return true; + if (jj_3R_38()) return true; } - if (jj_scan_token(28)) return true; return false; } - static final private boolean jj_3R_16() { + final private boolean jj_3R_42() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_16() { if (jj_3R_39()) return true; return false; } - static final private boolean jj_3_6() { + final private boolean jj_3R_24() { Token xsp; xsp = jj_scanpos; + if (jj_3R_42()) { + jj_scanpos = xsp; + if (jj_3R_43()) return true; + } + if (jj_scan_token(28)) return true; + return false; + } + + final private boolean jj_3_6() { + Token xsp; + xsp = jj_scanpos; if (jj_3R_16()) jj_scanpos = xsp; if (jj_3R_17()) return true; if (jj_scan_token(29)) return true; @@ -1804,33 +1815,33 @@ return false; } - static final private boolean jj_3R_4() { - if (jj_scan_token(ID)) return true; - return false; - } - - static final private boolean jj_3R_5() { + final private boolean jj_3R_5() { if (jj_scan_token(COMMAND_END)) return true; if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_41() { + final private boolean jj_3R_52() { if (jj_3R_12()) return true; return false; } - static final private boolean jj_3R_37() { + final private boolean jj_3_4() { + if (jj_scan_token(NEG_EX)) return true; + return false; + } + + final private boolean jj_3R_40() { if (jj_3R_4()) return true; return false; } - static final private boolean jj_3_4() { - if (jj_scan_token(NEG_EX)) return true; + final private boolean jj_3_3() { + if (jj_scan_token(POS_EX)) return true; return false; } - static final private boolean jj_3R_11() { + final private boolean jj_3R_11() { if (jj_scan_token(26)) return true; Token xsp; while (true) { @@ -1846,22 +1857,17 @@ return false; } - static final private boolean jj_3_3() { - if (jj_scan_token(POS_EX)) return true; - return false; - } - - static final private boolean jj_3R_15() { + final private boolean jj_3R_17() { Token xsp; xsp = jj_scanpos; - if (jj_3R_37()) { + if (jj_3R_40()) { jj_scanpos = xsp; - if (jj_3R_38()) return true; + if (jj_3R_41()) return true; } return false; } - static final private boolean jj_3_2() { + final private boolean jj_3_2() { if (jj_3R_4()) return true; if (jj_scan_token(29)) return true; if (jj_3R_12()) return true; @@ -1875,7 +1881,7 @@ return false; } - static final private boolean jj_3_5() { + final private boolean jj_3_5() { if (jj_3R_14()) return true; if (jj_scan_token(29)) return true; if (jj_3R_15()) return true; @@ -1884,7 +1890,7 @@ return false; } - static final private boolean jj_3_1() { + final private boolean jj_3_1() { if (jj_3R_4()) return true; Token xsp; xsp = jj_scanpos; @@ -1911,68 +1917,48 @@ return false; } - static final private boolean jj_3R_52() { - if (jj_3R_12()) return true; - return false; - } - - static final private boolean jj_3R_10() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; - return false; - } - - static final private boolean jj_3R_40() { - if (jj_3R_4()) return true; - return false; - } - - static final private boolean jj_3R_17() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_40()) { - jj_scanpos = xsp; - if (jj_3R_41()) return true; - } - return false; - } - - static final private boolean jj_3R_50() { + final private boolean jj_3R_50() { if (jj_scan_token(LE)) return true; return false; } - static final private boolean jj_3R_47() { + final private boolean jj_3R_47() { if (jj_scan_token(EXISTS)) return true; return false; } - static final private boolean jj_3R_49() { + final private boolean jj_3R_49() { if (jj_scan_token(GE)) return true; return false; } - static final private boolean jj_3R_45() { + final private boolean jj_3R_45() { if (jj_scan_token(BOTTOM)) return true; return false; } - static final private boolean jj_3R_39() { + final private boolean jj_3R_39() { if (jj_scan_token(NOT)) return true; return false; } - static final private boolean jj_3R_51() { + final private boolean jj_3R_10() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3R_51() { if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_48() { + final private boolean jj_3R_48() { if (jj_scan_token(ALL)) return true; return false; } - static final private boolean jj_3R_46() { + final private boolean jj_3R_46() { Token xsp; xsp = jj_scanpos; if (jj_3R_51()) { @@ -1982,32 +1968,27 @@ return false; } - static final private boolean jj_3R_44() { + final private boolean jj_3R_44() { if (jj_scan_token(TOP)) return true; return false; } - static final private boolean jj_3R_20() { + final private boolean jj_3R_20() { if (jj_scan_token(AND)) return true; return false; } - static final private boolean jj_3R_21() { + final private boolean jj_3R_21() { if (jj_scan_token(OR)) return true; return false; } - static final private boolean jj_3R_19() { + final private boolean jj_3R_19() { if (jj_3R_4()) return true; return false; } - static final private boolean jj_3R_9() { - if (jj_3R_12()) return true; - return false; - } - - static final private boolean jj_3R_36() { + final private boolean jj_3R_36() { if (jj_3R_50()) return true; if (jj_3R_22()) return true; if (jj_3R_17()) return true; @@ -2016,12 +1997,12 @@ return false; } - static final private boolean jj_3R_18() { + final private boolean jj_3R_18() { if (jj_3R_12()) return true; return false; } - static final private boolean jj_3R_35() { + final private boolean jj_3R_35() { if (jj_3R_49()) return true; if (jj_3R_22()) return true; if (jj_3R_17()) return true; @@ -2030,22 +2011,54 @@ return false; } - static final private boolean jj_3R_26() { - if (jj_3R_4()) return true; + final private boolean jj_3R_34() { + if (jj_3R_39()) return true; + if (jj_3R_14()) return true; return false; } - static private boolean jj_initialized_once = false; - static public DLLearnerTokenManager token_source; - static SimpleCharStream jj_input_stream; - static public Token token, jj_nt; - static private int jj_ntk; - static private Token jj_scanpos, jj_lastpos; - static private int jj_la; - static public boolean lookingAhead = false; - static private boolean jj_semLA; - static private int jj_gen; - static final private int[] jj_la1 = new int[15]; + final private boolean jj_3_12() { + if (jj_scan_token(29)) return true; + if (jj_3R_14()) return true; + if (jj_3R_21()) return true; + return false; + } + + final private boolean jj_3R_12() { + if (jj_scan_token(STRING)) return true; + return false; + } + + final private boolean jj_3R_33() { + if (jj_3R_48()) return true; + if (jj_3R_17()) return true; + if (jj_scan_token(COMMAND_END)) return true; + if (jj_3R_14()) return true; + return false; + } + + final private boolean jj_3R_9() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3_11() { + if (jj_scan_token(29)) return true; + if (jj_3R_14()) return true; + if (jj_3R_20()) return true; + return false; + } + + public DLLearnerTokenManager token_source; + SimpleCharStream jj_input_stream; + public Token token, jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + public boolean lookingAhead = false; + private boolean jj_semLA; + private int jj_gen; + final private int[] jj_la1 = new int[15]; static private int[] jj_la1_0; static private int[] jj_la1_1; static { @@ -2058,21 +2071,14 @@ private static void jj_la1_1() { jj_la1_1 = new int[] {0x3e,0x3e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x41,0x0,0x0,0x0,0x0,0x0,}; } - static final private JJCalls[] jj_2_rtns = new JJCalls[12]; - static private boolean jj_rescan = false; - static private int jj_gc = 0; + final private JJCalls[] jj_2_rtns = new JJCalls[12]; + private boolean jj_rescan = false; + private int jj_gc = 0; public DLLearner(java.io.InputStream stream) { this(stream, null); } public DLLearner(java.io.InputStream stream, String encoding) { - if (jj_initialized_once) { - System.out.println("ERROR: Second call to constructor of static parser. "); - System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false"); - System.out.println(" during parser generation."); - throw new Error(); - } - jj_initialized_once = true; try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } token_source = new DLLearnerTokenManager(jj_input_stream); token = new Token(); @@ -2082,10 +2088,10 @@ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } - static public void ReInit(java.io.InputStream stream) { + public void ReInit(java.io.InputStream stream) { ReInit(stream, null); } - static public void ReInit(java.io.InputStream stream, String encoding) { + public void ReInit(java.io.InputStream stream, String encoding) { try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } token_source.ReInit(jj_input_stream); token = new Token(); @@ -2097,13 +2103,6 @@ } public DLLearner(java.io.Reader stream) { - if (jj_initialized_once) { - System.out.println("ERROR: Second call to constructor of static parser. "); - System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false"); - System.out.println(" during parser generation."); - throw new Error(); - } - jj_initialized_once = true; jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new DLLearnerTokenManager(jj_input_stream); token = new Token(); @@ -2113,7 +2112,7 @@ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } - static public void ReInit(java.io.Reader stream) { + public void ReInit(java.io.Reader stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); @@ -2125,13 +2124,6 @@ } public DLLearner(DLLearnerTokenManager tm) { - if (jj_initialized_once) { - System.out.println("ERROR: Second call to constructor of static parser. "); - System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false"); - System.out.println(" during parser generation."); - throw new Error(); - } - jj_initialized_once = true; token_source = tm; token = new Token(); jj_ntk = -1; @@ -2150,7 +2142,7 @@ for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } - static final private Token jj_consume_token(int kind) throws ParseException { + final private Token jj_consume_token(int kind) throws ParseException { Token oldToken; if ((oldToken = token).next != null) token = token.next; else token = token.next = token_source.getNextToken(); @@ -2175,8 +2167,8 @@ } static private final class LookaheadSuccess extends java.lang.Error { } - static final private LookaheadSuccess jj_ls = new LookaheadSuccess(); - static final private boolean jj_scan_token(int kind) { + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + final private boolean jj_scan_token(int kind) { if (jj_scanpos == jj_lastpos) { jj_la--; if (jj_scanpos.next == null) { @@ -2197,7 +2189,7 @@ return false; } - static final public Token getNextToken() { + final public Token getNextToken() { if (token.next != null) token = token.next; else token = token.next = token_source.getNextToken(); jj_ntk = -1; @@ -2205,7 +2197,7 @@ return token; } - static final public Token getToken(int index) { + final public Token getToken(int index) { Token t = lookingAhead ? jj_scanpos : token; for (int i = 0; i < index; i++) { if (t.next != null) t = t.next; @@ -2214,20 +2206,20 @@ return t; } - static final private int jj_ntk() { + final private int jj_ntk() { if ((jj_nt=token.next) == null) return (jj_ntk = (token.next=token_source.getNextToken()).kind); else return (jj_ntk = jj_nt.kind); } - static private java.util.Vector<int[]> jj_expentries = new java.util.Vector<int[]>(); - static private int[] jj_expentry; - static private int jj_kind = -1; - static private int[] jj_lasttokens = new int[100]; - static private int jj_endpos; + private java.util.Vector<int[]> jj_expentries = new java.util.Vector<int[]>(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; - static private void jj_add_error_token(int kind, int pos) { + private void jj_add_error_token(int kind, int pos) { if (pos >= 100) return; if (pos == jj_endpos + 1) { jj_lasttokens[jj_endpos++] = kind; @@ -2255,7 +2247,7 @@ } } - static public ParseException generateParseException() { + public ParseException generateParseException() { jj_expentries.removeAllElements(); boolean[] la1tokens = new boolean[39]; if (jj_kind >= 0) { @@ -2291,13 +2283,13 @@ return new ParseException(token, exptokseq, tokenImage); } - static final public void enable_tracing() { + final public void enable_tracing() { } - static final public void disable_tracing() { + final public void disable_tracing() { } - static final private void jj_rescan_token() { + final private void jj_rescan_token() { jj_rescan = true; for (int i = 0; i < 12; i++) { try { @@ -2327,7 +2319,7 @@ jj_rescan = false; } - static final private void jj_save(int index, int xla) { + final private void jj_save(int index, int xla) { JJCalls p = jj_2_rtns[index]; while (p.gen > jj_gen) { if (p.next == null) { p = p.next = new JJCalls(); break; } Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java 2007-10-01 14:41:28 UTC (rev 159) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearnerTokenManager.java 2007-10-01 17:14:03 UTC (rev 160) @@ -10,6 +10,7 @@ import java.util.TreeSet; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringReader; import org.dllearner.Main; @@ -20,9 +21,9 @@ public @SuppressWarnings("all") class DLLearnerTokenManager implements DLLearnerConstants { - public static java.io.PrintStream debugStream = System.out; - public static void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } -private static final int jjStopStringLiteralDfa_0(int pos, long active0) + public java.io.PrintStream debugStream = System.out; + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0) { switch (pos) { @@ -38,17 +39,17 @@ return -1; } } -private static final int jjStartNfa_0(int pos, long active0) +private final int jjStartNfa_0(int pos, long active0) { return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); } -static private final int jjStopAtPos(int pos, int kind) +private final int jjStopAtPos(int pos, int kind) { jjmatchedKind = kind; jjmatchedPos = pos; return pos + 1; } -static private final int jjStartNfaWithStates_0(int pos, int kind, int state) +private final int jjStartNfaWithStates_0(int pos, int kind, int state) { jjmatchedKind = kind; jjmatchedPos = pos; @@ -56,7 +57,7 @@ catch(java.io.IOException e) { return pos + 1; } return jjMoveNfa_0(state, pos + 1); } -static private final int jjMoveStringLiteralDfa0_0() +private final int jjMoveStringLiteralDfa0_0() { switch(curChar) { @@ -102,7 +103,7 @@ return jjMoveNfa_0(0, 0); } } -static private final int jjMoveStringLiteralDfa1_0(long active0) +private final int jjMoveStringLiteralDfa1_0(long active0) { try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { @@ -140,7 +141,7 @@ } return jjStartNfa_0(0, active0); } -static private final int jjMoveStringLiteralDfa2_0(long old0, long active0) +private final int jjMoveStringLiteralDfa2_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(0, old0); @@ -183,7 +184,7 @@ } return jjStartNfa_0(1, active0); } -static private final int jjMoveStringLiteralDfa3_0(long old0, long active0) +private final int jjMoveStringLiteralDfa3_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(1, old0); @@ -213,7 +214,7 @@ } return jjStartNfa_0(2, active0); } -static private final int jjMoveStringLiteralDfa4_0(long old0, long active0) +private final int jjMoveStringLiteralDfa4_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(2, old0); @@ -243,7 +244,7 @@ } return jjStartNfa_0(3, active0); } -static private final int jjMoveStringLiteralDfa5_0(long old0, long active0) +private final int jjMoveStringLiteralDfa5_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(3, old0); @@ -275,7 +276,7 @@ } return jjStartNfa_0(4, active0); } -static private final int jjMoveStringLiteralDfa6_0(long old0, long active0) +private final int jjMoveStringLiteralDfa6_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(4, old0); @@ -307,7 +308,7 @@ } return jjStartNfa_0(5, active0); } -static private final int jjMoveStringLiteralDfa7_0(long old0, long active0) +private final int jjMoveStringLiteralDfa7_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(5, old0); @@ -331,7 +332,7 @@ } return jjStartNfa_0(6, active0); } -static private final int jjMoveStringLiteralDfa8_0(long old0, long active0) +private final int jjMoveStringLiteralDfa8_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(6, old0); @@ -359,7 +360,7 @@ } return jjStartNfa_0(7, active0); } -static private final int jjMoveStringLiteralDfa9_0(long old0, long active0) +private final int jjMoveStringLiteralDfa9_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(7, old0); @@ -389,7 +390,7 @@ } return jjStartNfa_0(8, active0); } -static private final int jjMoveStringLiteralDfa10_0(long old0, long active0) +private final int jjMoveStringLiteralDfa10_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(8, old0); @@ -407,7 +408,7 @@ } return jjStartNfa_0(9, active0); } -static private final int jjMoveStringLiteralDfa11_0(long old0, long active0) +private final int jjMoveStringLiteralDfa11_0(long old0, long active0) { if (((active0 &= old0)) == 0L) return jjStartNfa_0(9, old0); @@ -427,7 +428,7 @@ } return jjStartNfa_0(10, active0); } -static private final void jjCheckNAdd(int state) +private final void jjCheckNAdd(int state) { if (jjrounds[state] != jjround) { @@ -435,24 +436,24 @@ jjrounds[state] = jjround; } } -static private final void jjAddStates(int start, int end) +private final void jjAddStates(int start, int end) { do { jjstateSet[jjnewStateCnt++] = jjnextStates[start]; } while (start++ != end); } -static private final void jjCheckNAddTwoStates(int state1, int state2) +private final void jjCheckNAddTwoStates(int state1, int state2) { jjCheckNAdd(state1); jjCheckNAdd(state2); } -static private final void jjCheckNAddStates(int start, int end) +private final void jjCheckNAddStates(int start, int end) { do { jjCheckNAdd(jjnextStates[start]); } while (start++ != end); } -static private final void jjCheckNAddStates(int start) +private final void jjCheckNAddStates(int start) { jjCheckNAdd(jjnextStates[start]); jjCheckNAdd(jjnextStates[start + 1]); @@ -460,7 +461,7 @@ static final long[] jjbitVec0 = { 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL }; -static private final int jjMoveNfa_0(int startState, int curPos) +private final int jjMoveNfa_0(int startState, int curPos) { int[] nextStates; int startsAt = 0; @@ -853,39 +854,39 @@ static final long[] jjtoSkip = { 0xfeL, }; -static protected SimpleCharStream input_stream; -static private final int[] jjrounds = new int[53]; -static private final int[] jjstateSet = new int[106]; -static protected char curChar; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[53]; +private final int[] jjstateSet = new int[106]; +protected char curChar; public DLLearnerTokenManager(SimpleCharStream stream){ - if (input_stream != null) - throw new TokenMgrError("ERROR: Second call to constructor of static lexer. You must use ReInit() to initialize the static variables.", TokenMgrError.STATIC_LEXER_ERROR); + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); input_stream = stream; } public DLLearnerTokenManager(SimpleCharStream stream, int lexState){ this(stream); SwitchTo(lexState); } -static public void ReInit(SimpleCharStream stream) +public void ReInit(SimpleCharStream stream) { jjmatchedPos = jjnewStateCnt = 0; curLexState = defaultLexState; input_stream = stream; ReInitRounds(); } -static private final void ReInitRounds() +private final void ReInitRounds() { int i; jjround = 0x80000001; for (i = 53; i-- > 0;) jjrounds[i] = 0x80000000; } -static public void ReInit(SimpleCharStream stream, int lexState) +public void ReInit(SimpleCharStream stream, int lexState) { ReInit(stream); SwitchTo(lexState); } -static public void SwitchTo(int lexState) +public void SwitchTo(int lexState) { if (lexState >= 1 || lexState < 0) throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); @@ -893,7 +894,7 @@ curLexState = lexState; } -static protected Token jjFillToken() +protected Token jjFillToken() { Token t = Token.newToken(jjmatchedKind); t.kind = jjmatchedKind; @@ -906,14 +907,14 @@ return t; } -static int curLexState = 0; -static int defaultLexState = 0; -static int jjnewStateCnt; -static int jjround; -static int jjmatchedPos; -static int jjmatchedKind; +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; -public static Token getNextToken() +public Token getNextToken() { int kind; Token specialToken = null; Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java 2007-10-01 14:41:28 UTC (rev 159) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearnerTreeConstants.java 2007-10-01 17:14:03 UTC (rev 160) @@ -5,40 +5,42 @@ public @SuppressWarnings("all") interface DLLearnerTreeConstants { public int JJTSTART = 0; - public int JJTCONFOPTION = 1; - public int JJTFUNCTIONCALL = 2; - public int JJTPOSEXAMPLE = 3; - public int JJTNEGEXAMPLE = 4; - public int JJTABOXCONCEPT = 5; - public int JJTABOXROLE = 6; - public int JJTTRANSITIVE = 7; - public int JJTFUNCTIONAL = 8; - public int JJTSYMMETRIC = 9; - public int JJTINVERSE = 10; - public int JJTSUBROLE = 11; - public int JJTTBOXEQUIV = 12; - public int JJTTBOXSUB = 13; - public int JJTCONCEPT = 14; - public int JJTOR = 15; - public int JJTAND = 16; - public int JJTTOP = 17; - public int JJTBOTTOM = 18; - public int JJTEXISTS = 19; - public int JJTALL = 20; - public int JJTNOT = 21; - public int JJTGE = 22; - public int JJTLE = 23; - public int JJTATOMICCONCEPT = 24; - public int JJTATOMICROLE = 25; - public int JJTINDIVIDUAL = 26; - public int JJTID = 27; - public int JJTDOUBLE = 28; - public int JJTINTEGER = 29; - public int JJTSTRING = 30; + public int JJTPARSEKB = 1; + public int JJTCONFOPTION = 2; + public int JJTFUNCTIONCALL = 3; + public int JJTPOSEXAMPLE = 4; + public int JJTNEGEXAMPLE = 5; + public int JJTABOXCONCEPT = 6; + public int JJTABOXROLE = 7; + public int JJTTRANSITIVE = 8; + public int JJTFUNCTIONAL = 9; + public int JJTSYMMETRIC = 10; + public int JJTINVERSE = 11; + public int JJTSUBROLE = 12; + public int JJTTBOXEQUIV = 13; + public int JJTTBOXSUB = 14; + public int JJTCONCEPT = 15; + public int JJTOR = 16; + public int JJTAND = 17; + public int JJTTOP = 18; + public int JJTBOTTOM = 19; + public int JJTEXISTS = 20; + public int JJTALL = 21; + public int JJTNOT = 22; + public int JJTGE = 23; + public int JJTLE = 24; + public int JJTATOMICCONCEPT = 25; + public int JJTATOMICROLE = 26; + public int JJTINDIVIDUAL = 27; + public int JJTID = 28; + public int JJTDOUBLE = 29; + public int JJTINTEGER = 30; + public int JJTSTRING = 31; public String[] jjtNodeName = { "Start", + "parseKB", "ConfOption", "FunctionCall", "PosExample", Modified: trunk/src/dl-learner/org/dllearner/parser/dllearner.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-10-01 14:41:28 UTC (rev 159) +++ trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-10-01 17:14:03 UTC (rev 160) @@ -8,6 +8,7 @@ options { // MULTI=true; JDK_VERSION = "1.5"; + STATIC = false; } // wenn der Parser ge\ufffdndert wird, dann muss man in einigen Dateien SuppressWarnings @@ -27,6 +28,7 @@ import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringReader; @@ -39,24 +41,24 @@ // @SuppressWarnings({"all"}) public class DLLearner/*@bgen(jjtree)*/implements DLLearnerTreeConstants/*@egen*/ {/*@bgen(jjtree)*/ - protected static JJTDLLearnerState jjtree = new JJTDLLearnerState(); + protected JJTDLLearnerState jjtree = new JJTDLLearnerState(); /*@egen*/ private static ConceptComparator conceptComparator = new ConceptComparator(); // hier wird Parse-Fehler angezeigt, obwohl eigentlich alles stimmt?? - private static Map<AtomicConcept,SortedSet<Individual>> positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); - private static Map<AtomicConcept,SortedSet<Individual>> negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + private Map<AtomicConcept,SortedSet<Individual>> positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + private Map<AtomicConcept,SortedSet<Individual>> negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); // Konfigurationsoptionen - private static List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe // werden in einer Liste gespeichert - private static List<List<String>> functionCalls = new LinkedList<List<String>>(); + private List<List<String>> functionCalls = new LinkedList<List<String>>(); // => irgendwie Funktionsname + Argumente speichern // => d.h. man br\u00e4uchte f\u00fcr jede Funktion so eine Liste oder das erste Element // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante @@ -65,13 +67,13 @@ // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal // aufgerufen werden; weitere Parsevorg\u00e4nge erfolgen dann mit ReInit // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser - private static boolean constructorCalled = false; + // private static boolean constructorCalled = false; // Wissensbasis - private static KB kb = new KB(); + private KB kb = new KB(); public static final String internalNamespace = "http://localhost/foo#"; - private static void addPositiveExample(AtomicConcept conceptName, Individual instanceName) { + private void addPositiveExample(AtomicConcept conceptName, Individual instanceName) { if(positiveExamples.containsKey(conceptName)) { positiveExamples.get(conceptName).add(instanceName); } else { @@ -81,7 +83,7 @@ } } - private static void addNegativeExample(AtomicConcept conceptName, Individual instanceName) { + private void addNegativeExample(AtomicConcept conceptName, Individual instanceName) { if(negativeExamples.containsKey(conceptName)) { negativeExamples.get(conceptName).add(instanceName); } else { @@ -91,23 +93,23 @@ } } - public static Map<AtomicConcept,SortedSet<Individual>> getPositiveExamples() { + public Map<AtomicConcept,SortedSet<Individual>> getPositiveExamples() { return positiveExamples; } - public static Map<AtomicConcept,SortedSet<Individual>> getNegativeExamples() { + public Map<AtomicConcept,SortedSet<Individual>> getNegativeExamples() { return negativeExamples; } - public static List<ConfigurationOption> getConfOptions() { + public List<ConfigurationOption> getConfOptions() { return confOptions; } - public static List<List<String>> getFunctionCalls() { + public List<List<String>> getFunctionCalls() { return functionCalls; } - public static KB getKB() { + public KB getKB() { return kb; } @@ -135,19 +137,14 @@ public static SimpleNode parseString(String str) throws ParseException { StringReader sr = new StringReader(str); - // new DLLearner(sr); - DLLearner... [truncated message content] |
From: <jen...@us...> - 2007-10-02 17:43:00
|
Revision: 162 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=162&view=rev Author: jenslehmann Date: 2007-10-02 10:42:58 -0700 (Tue, 02 Oct 2007) Log Message: ----------- - parser improvements - made alle necessary changes to reflect parser modifications - implemented knowledge source KBFile - started SPARQL Endpoint knowledge source - started CLI package - moved some classes to appropriate packages Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/LearningProblem.java trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/kb/OWLFile.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java trunk/src/dl-learner/org/dllearner/parser/ConfParser.java trunk/src/dl-learner/org/dllearner/parser/KBParser.java trunk/src/dl-learner/org/dllearner/parser/KBParserTokenManager.java trunk/src/dl-learner/org/dllearner/parser/conf.jj trunk/src/dl-learner/org/dllearner/parser/conf.jjt trunk/src/dl-learner/org/dllearner/parser/kb.jj trunk/src/dl-learner/org/dllearner/parser/kb.jjt trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java trunk/src/dl-learner/org/dllearner/reasoning/JenaOWLDIGConverter.java trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDIGConverter.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/utilities/OntologyClassRewriter.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/cli/ trunk/src/dl-learner/org/dllearner/cli/QuickStart.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/Score.java trunk/src/dl-learner/org/dllearner/kb/KBFile.java trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java trunk/src/dl-learner/org/dllearner/QuickStart.java trunk/src/dl-learner/org/dllearner/Score.java trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java trunk/src/dl-learner/org/dllearner/parser/SimpleNode.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-02 17:42:58 UTC (rev 162) @@ -8,12 +8,12 @@ import java.util.Set; import org.dllearner.LearningProblem.LearningProblemType; -import org.dllearner.ScoreThreeValued.ScoreMethod; import org.dllearner.algorithms.gp.GP.AlgorithmType; import org.dllearner.algorithms.gp.GP.SelectionType; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.learningproblems.DefinitionLP.UseMultiInstanceChecks; +import org.dllearner.learningproblems.ScoreThreeValued.ScoreMethod; import org.dllearner.reasoning.ReasonerType; public class Config { Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-02 17:42:58 UTC (rev 162) @@ -13,12 +13,12 @@ import java.util.TreeSet; import org.dllearner.Config.Algorithm; -import org.dllearner.ScoreThreeValued.ScoreMethod; import org.dllearner.algorithms.gp.GP.AlgorithmType; import org.dllearner.algorithms.gp.GP.SelectionType; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; -import org.dllearner.parser.DLLearner; +import org.dllearner.learningproblems.ScoreThreeValued.ScoreMethod; +import org.dllearner.parser.KBParser; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.RoleComparator; @@ -90,7 +90,7 @@ } // der parserinterne Namespace wird immer ausgeblendet - Config.hidePrefixes.add(DLLearner.internalNamespace); + Config.hidePrefixes.add(KBParser.internalNamespace); } @@ -549,20 +549,20 @@ Config.Refinement.allowedConcepts = new TreeSet<AtomicConcept>(new ConceptComparator()); for(String s : setValues) // es wird die gleiche Funktion wie im Parser genommen um Namen auf URIs zu mappen - Config.Refinement.allowedConcepts.add(new AtomicConcept(DLLearner.getInternalURI(s))); + Config.Refinement.allowedConcepts.add(new AtomicConcept(KBParser.getInternalURI(s))); } else if(optionString.equals("refinement.allowedRoles")) { Config.Refinement.allowedRolesAutoDetect = false; Config.Refinement.allowedRoles = new TreeSet<AtomicRole>(new RoleComparator()); for(String s : setValues) - Config.Refinement.allowedRoles.add(new AtomicRole(DLLearner.getInternalURI(s))); + Config.Refinement.allowedRoles.add(new AtomicRole(KBParser.getInternalURI(s))); } else if(optionString.equals("refinement.ignoredConcepts")) { Config.Refinement.ignoredConcepts = new TreeSet<AtomicConcept>(new ConceptComparator()); for(String s : setValues) - Config.Refinement.ignoredConcepts.add(new AtomicConcept(DLLearner.getInternalURI(s))); + Config.Refinement.ignoredConcepts.add(new AtomicConcept(KBParser.getInternalURI(s))); } else if(optionString.equals("refinement.ignoredRoles")) { Config.Refinement.ignoredRoles = new TreeSet<AtomicRole>(new RoleComparator()); for(String s : setValues) - Config.Refinement.ignoredRoles.add(new AtomicRole(DLLearner.getInternalURI(s))); + Config.Refinement.ignoredRoles.add(new AtomicRole(KBParser.getInternalURI(s))); } } Modified: trunk/src/dl-learner/org/dllearner/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-02 17:42:58 UTC (rev 162) @@ -6,9 +6,12 @@ import org.dllearner.Config.Refinement; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.Negation; +import org.dllearner.learningproblems.ScoreThreeValued; +import org.dllearner.learningproblems.ScoreTwoValued; import org.dllearner.learningproblems.DefinitionLP.UseMultiInstanceChecks; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-02 17:42:58 UTC (rev 162) @@ -47,6 +47,7 @@ import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.dl.AssertionalAxiom; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; @@ -57,10 +58,11 @@ import org.dllearner.core.dl.KB; import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.RoleAssertion; +import org.dllearner.kb.OntologyFileFormat; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.DefinitionLPTwoValued; import org.dllearner.modules.ModuleInvocator; -import org.dllearner.parser.DLLearner; +import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.parser.TokenMgrError; import org.dllearner.reasoning.DIGReasoner; @@ -990,7 +992,7 @@ boolean parsedCorrectly = true; try { - concept = DLLearner.parseConcept(queryStr); + concept = KBParser.parseConcept(queryStr); } catch (ParseException e1) { e1.printStackTrace(); System.err @@ -1362,7 +1364,7 @@ Concept c = null; try { - c = DLLearner.parseConcept("EXISTS r.(TOP AND (TOP OR BOTTOM))"); + c = KBParser.parseConcept("EXISTS r.(TOP AND (TOP OR BOTTOM))"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -1393,7 +1395,7 @@ */ Concept c = null; try { - c = DLLearner.parseConcept("EXISTS uncle.TOP"); + c = KBParser.parseConcept("EXISTS uncle.TOP"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); Deleted: trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java =================================================================== --- trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,11 +0,0 @@ -package org.dllearner; - -public enum OntologyFileFormat { - - // RDF-Triples in XML-Datei - RDF_XML, - - // N-Triple-Format (Subformat von N3) - N_TRIPLES - -} Deleted: trunk/src/dl-learner/org/dllearner/QuickStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/QuickStart.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/QuickStart.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,182 +0,0 @@ -package org.dllearner; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileWriter; -import java.io.InputStreamReader; -import java.io.RandomAccessFile; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; - -import org.dllearner.parser.DLLearner; - -/** - * A tool to quickly start a learning exampe. It detects all conf files in - * the examples directory and offers the user to start one of them. - * - * @author Sebastian Hellmann - * @author Jens Lehmann - */ -public class QuickStart { - - static HashMap<String, ArrayList<String>> hm = null; - static String pm = ".";// pathmodifier - - public static void main(String[] args) { - - String lastused = readit(); - String tab = " "; - int the_Number = 0; - ArrayList<String> FinalSelection = new ArrayList<String>(); - FinalSelection.add("na"); - - hm = new HashMap<String, ArrayList<String>>(); - String path = pm + File.separator + "examples"; - File f = new File(path); - getAllConfs(f, path); - - // System.out.println(hm.size()); - Iterator<String> i = hm.keySet().iterator(); - Object[] sort = new Object[hm.size()]; - int count = 0; - while (i.hasNext()) - sort[count++] = i.next(); - Arrays.sort(sort); - Object s; - String s1 = ""; - // String tmp=""; - for (int aa = 0; aa < sort.length; aa++) - // while (i.hasNext()) - { - s = sort[aa]; - s1 = (String) s; - if (s1.startsWith(pm + "\\examples\\") || s1.startsWith(pm + "/examples/")) - System.out.println(s1.substring(10).toUpperCase()); - else - System.out.println(s); - - ArrayList<String> al = hm.get(s); - String[] files = new String[al.size()]; - for (int j = 0; j < al.size(); j++) { - files[j] = al.get(j); - } - Arrays.sort(files); - for (int j = 0; j < files.length; j++) { - the_Number++; - FinalSelection.add(the_Number, s + files[j] + ".conf");// tmp=the_Number+":"+tab+files[j]; - System.out.println(" " + the_Number + ":" + tab + files[j] + ""); - - } - // System.out.println(FinalSelection.get(1)); - - }// end while - System.out.println("Last Used: " + lastused + "\n" - + "->press enter to use it again, else choose number:"); - boolean number = false; - try { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - int target = 0; - String Selected = ""; - while (true) { - String cmd = br.readLine(); - try { - if (cmd.length() == 0) { - number = false; - break; - } - target = Integer.parseInt(cmd); - number = true; - break; - } catch (Exception e) { - System.out.println("Not a number"); - } - ; - }// end while - if (number) { - try { - Selected = FinalSelection.get(target); - } catch (Exception e) { - System.out.println("number does not exist"); - } - ; - writeit(Selected); - System.out.println(Selected); - } else if (!number) { - Selected = lastused; - } - - DLLearner.main(new String[] { Selected }); - - } catch (Exception e) { - e.printStackTrace(); - }// System.out.println(s+" : "+hm.get(s).get(0)); - - // System.out.println(f.isDirectory()+f.getAbsolutePath()); - } - - public static void getAllConfs(File f, String path) { - path = path + File.separator; - // System.out.println(path); - String[] act = f.list(); - for (int i = 0; i < act.length; i++) { - // System.out.println(act[i]); - - if (new File(path + act[i]).isDirectory()) { - - getAllConfs(new File(path + act[i]), path + act[i]); - // al.add(new File(act[i])); - } else if (act[i].endsWith(".conf")) { - if (hm.get(path) == null) { - hm.put(path, new ArrayList<String>()); - } - hm.get(path).add(act[i].substring(0, act[i].length() - 5)); - // System.out.println(act[i].substring(0,act[i].length()-5)); - // System.out.println(hm.get(path).size()); - // hm.put(new - // File(act[i]).getAbsolutePath(),act[i].substring(0,act[i].length()-4)); - } - }// end for - - } - - static void writeit(String lastused) { - try { - FileWriter fw = new FileWriter(".lastUsedExample"); - fw.write(lastused); - fw.flush(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - static String readit() { - String lu = ""; - try { - RandomAccessFile raf = new RandomAccessFile(".lastUsedExample", "r"); - String line = ""; - while ((line = raf.readLine()) != null) { - lu = line; - } - } catch (Exception e) { - writeit("na"); - } - return lu; - } - - static String readCP() { - String lu = ""; - try { - RandomAccessFile raf = new RandomAccessFile("classpath.start", "r"); - String line = ""; - while ((line = raf.readLine()) != null) { - lu += line; - } - } catch (Exception e) { - e.printStackTrace(); - } - return lu; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/Score.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Score.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/Score.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,28 +0,0 @@ -package org.dllearner; - -import java.util.Set; - -import org.dllearner.core.dl.Individual; - -public abstract class Score { - public abstract double getScore(); - - /** - * The score of a concept depends on how good it classifies the - * examples of a learning problem and the length of the concept - * itself. If a given concept is known to have equal classification - * properties than the concept this score object is based on, then - * this method can be used to calculate its score value by using the - * length of this concept as parameter. - * - * @param newLength Length of the concept. - * @return Score. - */ - public abstract Score getModifiedLengthScore(int newLength); - - public abstract Set<Individual> getCoveredPositives(); - public abstract Set<Individual> getCoveredNegatives(); - public abstract Set<Individual> getNotCoveredPositives(); - - // public abstract int getNrOfMiss -} Deleted: trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,198 +0,0 @@ -package org.dllearner; - -import java.text.DecimalFormat; -import java.util.Set; -import java.util.SortedSet; - -import org.dllearner.core.dl.Individual; -import org.dllearner.utilities.Helper; - -/** - * Berechnet die Punktzahl (negativ), indem es die Ergebnisse einer Definition - * mit den Soll-Ergebnissen vergleicht. - * - * TODO: die Implementierung ist momentan dahingehend unguenstig, dass viele Sachen - * nur fuer die optische Aufbereitung berechnet werden; effizienter waere es - * nur die Klassifikationsfehler zu beruecksichtigen und andere statistische Werte nur - * dann wenn sie benoetigt werden - * - * @author Jens Lehmann - * - */ -public class ScoreThreeValued extends Score { - - public enum ScoreMethod {POSITIVE, FULL}; - - private SortedSet<Individual> posClassified; - private SortedSet<Individual> neutClassified; - private SortedSet<Individual> negClassified; - private SortedSet<Individual> posExamples; - private SortedSet<Individual> neutExamples; - private SortedSet<Individual> negExamples; - - private Set<Individual> posAsNeg; - private Set<Individual> negAsPos; - private Set<Individual> posAsNeut; - private Set<Individual> neutAsPos; - private Set<Individual> neutAsNeg; - private Set<Individual> negAsNeut; - private Set<Individual> posAsPos; - private Set<Individual> negAsNeg; - private Set<Individual> neutAsNeut; - - private double score; - private double accuracy; - private double accuracyOnExamples; - private double accuracyOnPositiveExamples; - private double errorRate; - - private int nrOfExamples; - private int conceptLength; - - public ScoreThreeValued(int conceptLength, - SortedSet<Individual> posClassified, - SortedSet<Individual> neutClassified, - SortedSet<Individual> negClassified, - SortedSet<Individual> posExamples, - SortedSet<Individual> neutExamples, - SortedSet<Individual> negExamples) { - this.conceptLength = conceptLength; - this.posClassified = posClassified; - this.neutClassified = neutClassified; - this.negClassified = negClassified; - this.posExamples = posExamples; - this.neutExamples = neutExamples; - this.negExamples = negExamples; - nrOfExamples = posExamples.size()+negExamples.size(); - computeClassificationMatrix(); - computeStatistics(); - } - - private void computeClassificationMatrix() { - posAsNeg = Helper.intersection(posExamples,negClassified); - negAsPos = Helper.intersection(negExamples,posClassified); - posAsNeut = Helper.intersection(posExamples,neutClassified); - neutAsPos = Helper.intersection(neutExamples,posClassified); - neutAsNeg = Helper.intersection(neutExamples,negClassified); - negAsNeut = Helper.intersection(negExamples,neutClassified); - // die 3 Berechnungen sind nicht so wichtig f�r die Punktzahl, d.h. falls - // es Performance bringt, dann kann man sie auch ausgliedern - posAsPos = Helper.intersection(posExamples,posClassified); - negAsNeg = Helper.intersection(negExamples,negClassified); - neutAsNeut = Helper.intersection(neutExamples,neutClassified); - } - - private void computeStatistics() { - score = - posAsNeg.size()*Config.errorPenalty - - negAsPos.size()*Config.errorPenalty - - posAsNeut.size()*Config.accuracyPenalty; - - if(Config.scoreMethod==ScoreMethod.FULL) - score -= negAsNeut.size()*Config.accuracyPenalty; - - if(Config.penalizeNeutralExamples) - score -= (neutAsPos.size()*Config.accuracyPenalty - + neutAsNeg.size()*Config.accuracyPenalty); - - // TODO: man könnte hier statt error penality auch accuracy penalty - // nehmen - double worstValue = nrOfExamples * Config.errorPenalty; - // ergibt Zahl zwischen -1 und 0 - score = score / worstValue; - score -= Config.percentPerLengthUnit * conceptLength; - - // die folgenden Berechnungen k�nnten aus Performancegr�nden auch - // ausgegliedert werden - // int domainSize = abox.domain.size(); - int numberOfExamples = posExamples.size()+negExamples.size(); - int domainSize = numberOfExamples + neutExamples.size(); - int correctlyClassified = posAsPos.size() + negAsNeg.size() + neutAsNeut.size(); - int correctOnExamples = posAsPos.size() + negAsNeg.size(); - int errors = posAsNeg.size() + negAsPos.size(); - - // Accuracy = Quotient von richtig klassifizierten durch Anzahl Domainelemente - accuracy = (double) correctlyClassified/domainSize; - - // Accuracy on Examples = Quotient von richtig klassifizierten durch Anzahl pos. - // und neg. Beispiele - accuracyOnExamples = (double) correctOnExamples/numberOfExamples; - - accuracyOnPositiveExamples = (double) posAsPos.size()/posExamples.size(); - - // Error = Quotient von komplett falsch klassifizierten durch Anzahl pos. - // und neg. Beispiele - errorRate = (double) errors/numberOfExamples; - } - - @Override - public double getScore() { - return score; - } - - @Override - public String toString() { - DecimalFormat df = new DecimalFormat("0.00"); - String str = ""; - str += "score method "; - if(Config.scoreMethod == ScoreMethod.FULL) - str += "full"; - else - str += "positive"; - if(!Config.penalizeNeutralExamples) - str += " (neutral examples not penalized)"; - str += "\n"; - if(Config.showCorrectClassifications) { - str += "Correctly classified:\n"; - str += " positive --> positive: " + posAsPos + "\n"; - str += " neutral --> neutral: " + neutAsNeut + "\n"; - str += " negative --> negative: " + negAsNeg + "\n"; - } - str += "Inaccurately classified (penalty of " + df.format(Config.accuracyPenalty) + " per instance):\n"; - str += " positive --> neutral: " + posAsNeut + "\n"; - if(Config.penalizeNeutralExamples) { - str += " neutral --> positive: " + neutAsPos + "\n"; - str += " neutral --> negative: " + neutAsNeg + "\n"; - } - if(Config.scoreMethod == ScoreMethod.FULL) - str += " negative --> neutral: " + negAsNeut + "\n"; - str += "Classification errors (penalty of " + df.format(Config.errorPenalty) + " per instance):\n"; - str += " positive --> negative: " + posAsNeg + "\n"; - str += " negative --> positive: " + negAsPos + "\n"; - str += "Statistics:\n"; - str += " Score: " + df.format(score) + "\n"; - str += " Accuracy: " + df.format(accuracy*100) + "%\n"; - str += " Accuracy on examples: " + df.format(accuracyOnExamples*100) + "%\n"; - str += " Accuracy on positive examples: " + df.format(accuracyOnPositiveExamples*100) + "%\n"; - str += " Error rate: " + df.format(errorRate*100) + "%\n"; - return str; - } - - public SortedSet<Individual> getNegClassified() { - return negClassified; - } - - public SortedSet<Individual> getPosClassified() { - return posClassified; - } - - @Override - public Set<Individual> getCoveredNegatives() { - return negAsPos; - } - - @Override - public Set<Individual> getCoveredPositives() { - return posAsPos; - } - - @Override - public Set<Individual> getNotCoveredPositives() { - return posAsNeg; - } - - @Override - public Score getModifiedLengthScore(int newLength) { - return new ScoreThreeValued(newLength, posClassified, neutClassified, negClassified, posExamples, neutExamples, negExamples); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/ScoreTwoValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,85 +0,0 @@ -package org.dllearner; - -import java.util.Set; - -import org.dllearner.core.dl.Individual; - -/** - * - * TODO: accuracy-Berechnung (positive+negative Beispiele muessen dafuer bekannt sein) - * - * @author jl - * - */ -public class ScoreTwoValued extends Score { - - private Set<Individual> posAsPos; - private Set<Individual> posAsNeg; - private Set<Individual> negAsPos; - private Set<Individual> negAsNeg; - private double score; - private double classificationScore; - private int nrOfExamples; - private int conceptLength; - - public ScoreTwoValued(int conceptLength, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { - this.conceptLength = conceptLength; - this.posAsPos = posAsPos; - this.posAsNeg = posAsNeg; - this.negAsPos = negAsPos; - this.negAsNeg = negAsNeg; - nrOfExamples = posAsPos.size()+posAsNeg.size()+negAsPos.size()+negAsNeg.size(); - computeScore(); - } - - private void computeScore() { - // - Anzahl falscher Klassifikationen - classificationScore = - posAsNeg.size() - negAsPos.size(); - // Anteil falscher Klassifikationen (Zahl zwischen -1 und 0) - classificationScore = classificationScore / (double) nrOfExamples; - // Berücksichtigung des Längenfaktors - score = classificationScore - Config.percentPerLengthUnit * conceptLength; - } - - @Override - public double getScore() { - return score; - } - - @Override - public String toString() { - String str = ""; - str += "score: " + score + "\n"; - str += "posAsPos: " + posAsPos + "\n"; - str += "positive examples classified as negative: " + posAsNeg + "\n"; - str += "negative examples classified as positive: " + negAsPos + "\n"; - return str; - } - - @Override - public Set<Individual> getCoveredNegatives() { - return negAsPos; - } - - @Override - public Set<Individual> getCoveredPositives() { - return posAsPos; - } - - @Override - public Set<Individual> getNotCoveredPositives() { - return posAsNeg; - } - - /* - @Override - public double getModifiedLengthScore(int newLength) { - return classificationScore - Config.percentPerLengthUnit * newLength; - } - */ - - @Override - public Score getModifiedLengthScore(int newLength) { - return new ScoreTwoValued(newLength, posAsPos, posAsNeg, negAsPos, negAsNeg); - } -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-02 17:42:58 UTC (rev 162) @@ -7,7 +7,7 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; -import org.dllearner.Score; +import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; Modified: trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/LearningAlgorithm.java 2007-10-02 17:42:58 UTC (rev 162) @@ -1,6 +1,6 @@ package org.dllearner.algorithms; -import org.dllearner.Score; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; /** Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-02 17:42:58 UTC (rev 162) @@ -23,7 +23,6 @@ import java.util.LinkedList; import org.dllearner.LearningProblem; -import org.dllearner.Score; import org.dllearner.algorithms.gp.Program; import org.dllearner.algorithms.gp.GPUtilities; import org.dllearner.core.ConfigEntry; @@ -32,6 +31,7 @@ import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.DefinitionLPThreeValued; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-02 17:42:58 UTC (rev 162) @@ -47,7 +47,6 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; -import org.dllearner.Score; import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.algorithms.hybridgp.Psi; import org.dllearner.core.ConfigEntry; @@ -55,6 +54,7 @@ import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-02 17:42:58 UTC (rev 162) @@ -9,9 +9,8 @@ import org.dllearner.Config; import org.dllearner.Main; -import org.dllearner.Score; -import org.dllearner.ScoreThreeValued; import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; @@ -28,6 +27,7 @@ import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.DefinitionLPThreeValued; +import org.dllearner.learningproblems.ScoreThreeValued; import org.dllearner.reasoning.FastRetrieval; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2007-10-02 17:42:58 UTC (rev 162) @@ -20,7 +20,7 @@ package org.dllearner.algorithms.gp; -import org.dllearner.Score; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; /** Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-02 17:42:58 UTC (rev 162) @@ -6,9 +6,9 @@ import java.util.TreeMap; import org.dllearner.LearningProblem; -import org.dllearner.Score; import org.dllearner.algorithms.gp.Program; import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.utilities.ConceptComparator; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-02 17:42:58 UTC (rev 162) @@ -11,8 +11,8 @@ import org.dllearner.Config; import org.dllearner.LearningProblem; -import org.dllearner.Score; import org.dllearner.algorithms.LearningAlgorithm; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.MultiConjunction; import org.dllearner.core.dl.MultiDisjunction; Copied: trunk/src/dl-learner/org/dllearner/cli/QuickStart.java (from rev 160, trunk/src/dl-learner/org/dllearner/QuickStart.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/QuickStart.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,181 @@ +package org.dllearner.cli; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.io.RandomAccessFile; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; + +/** + * A tool to quickly start a learning example. It detects all conf files in + * the examples directory and offers the user to start one of them. + * + * @author Sebastian Hellmann + * @author Jens Lehmann + */ +public class QuickStart { + + static HashMap<String, ArrayList<String>> hm = null; + static String pm = ".";// pathmodifier + + public static void main(String[] args) { + + String lastused = readit(); + String tab = " "; + int the_Number = 0; + ArrayList<String> FinalSelection = new ArrayList<String>(); + FinalSelection.add("na"); + + hm = new HashMap<String, ArrayList<String>>(); + String path = pm + File.separator + "examples"; + File f = new File(path); + getAllConfs(f, path); + + // System.out.println(hm.size()); + Iterator<String> i = hm.keySet().iterator(); + Object[] sort = new Object[hm.size()]; + int count = 0; + while (i.hasNext()) + sort[count++] = i.next(); + Arrays.sort(sort); + Object s; + String s1 = ""; + // String tmp=""; + for (int aa = 0; aa < sort.length; aa++) + // while (i.hasNext()) + { + s = sort[aa]; + s1 = (String) s; + if (s1.startsWith(pm + "\\examples\\") || s1.startsWith(pm + "/examples/")) + System.out.println(s1.substring(10).toUpperCase()); + else + System.out.println(s); + + ArrayList<String> al = hm.get(s); + String[] files = new String[al.size()]; + for (int j = 0; j < al.size(); j++) { + files[j] = al.get(j); + } + Arrays.sort(files); + for (int j = 0; j < files.length; j++) { + the_Number++; + FinalSelection.add(the_Number, s + files[j] + ".conf");// tmp=the_Number+":"+tab+files[j]; + System.out.println(" " + the_Number + ":" + tab + files[j] + ""); + + } + // System.out.println(FinalSelection.get(1)); + + }// end while + System.out.println("Last Used: " + lastused + "\n" + + "->press enter to use it again, else choose number:"); + boolean number = false; + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int target = 0; + String Selected = ""; + while (true) { + String cmd = br.readLine(); + try { + if (cmd.length() == 0) { + number = false; + break; + } + target = Integer.parseInt(cmd); + number = true; + break; + } catch (Exception e) { + System.out.println("Not a number"); + } + ; + }// end while + if (number) { + try { + Selected = FinalSelection.get(target); + } catch (Exception e) { + System.out.println("number does not exist"); + } + ; + writeit(Selected); + System.out.println(Selected); + } else if (!number) { + Selected = lastused; + } + + System.out.println("ToDo: start commandline interface with selected conf file"); + // DLLearner.main(new String[] { Selected }); + + } catch (Exception e) { + e.printStackTrace(); + }// System.out.println(s+" : "+hm.get(s).get(0)); + + // System.out.println(f.isDirectory()+f.getAbsolutePath()); + } + + public static void getAllConfs(File f, String path) { + path = path + File.separator; + // System.out.println(path); + String[] act = f.list(); + for (int i = 0; i < act.length; i++) { + // System.out.println(act[i]); + + if (new File(path + act[i]).isDirectory()) { + + getAllConfs(new File(path + act[i]), path + act[i]); + // al.add(new File(act[i])); + } else if (act[i].endsWith(".conf")) { + if (hm.get(path) == null) { + hm.put(path, new ArrayList<String>()); + } + hm.get(path).add(act[i].substring(0, act[i].length() - 5)); + // System.out.println(act[i].substring(0,act[i].length()-5)); + // System.out.println(hm.get(path).size()); + // hm.put(new + // File(act[i]).getAbsolutePath(),act[i].substring(0,act[i].length()-4)); + } + }// end for + + } + + static void writeit(String lastused) { + try { + FileWriter fw = new FileWriter(".lastUsedExample"); + fw.write(lastused); + fw.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + static String readit() { + String lu = ""; + try { + RandomAccessFile raf = new RandomAccessFile(".lastUsedExample", "r"); + String line = ""; + while ((line = raf.readLine()) != null) { + lu = line; + } + } catch (Exception e) { + writeit("na"); + } + return lu; + } + + static String readCP() { + String lu = ""; + try { + RandomAccessFile raf = new RandomAccessFile("classpath.start", "r"); + String line = ""; + while ((line = raf.readLine()) != null) { + lu += line; + } + } catch (Exception e) { + e.printStackTrace(); + } + return lu; + } + +} Added: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.cli; + +import java.io.File; + +/** + * Startup file for Command Line Interface. + * + * @author Jens Lehmann + * + */ +public class Start { + + /** + * @param args + */ + public static void main(String[] args) { + File file = new File(args[args.length-1]); + + // parse conf file + + // use parsed values to configure components + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-02 17:42:58 UTC (rev 162) @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.LinkedList; -import org.dllearner.Score; import org.dllearner.core.dl.Concept; /** Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-02 17:42:58 UTC (rev 162) @@ -28,13 +28,13 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.OntologyFileFormat; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.RoleHierarchy; import org.dllearner.core.dl.SubsumptionHierarchy; +import org.dllearner.kb.OntologyFileFormat; import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.KAON2Reasoner; import org.dllearner.reasoning.ReasonerType; Added: trunk/src/dl-learner/org/dllearner/core/Score.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Score.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/Score.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,28 @@ +package org.dllearner.core; + +import java.util.Set; + +import org.dllearner.core.dl.Individual; + +public abstract class Score { + public abstract double getScore(); + + /** + * The score of a concept depends on how good it classifies the + * examples of a learning problem and the length of the concept + * itself. If a given concept is known to have equal classification + * properties than the concept this score object is based on, then + * this method can be used to calculate its score value by using the + * length of this concept as parameter. + * + * @param newLength Length of the concept. + * @return Score. + */ + public abstract Score getModifiedLengthScore(int newLength); + + public abstract Set<Individual> getCoveredPositives(); + public abstract Set<Individual> getCoveredNegatives(); + public abstract Set<Individual> getNotCoveredPositives(); + + // public abstract int getNrOfMiss +} Added: trunk/src/dl-learner/org/dllearner/kb/KBFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/KBFile.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,94 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.kb; + +import java.io.File; +import java.io.FileNotFoundException; +import java.net.URI; +import java.util.Collection; +import java.util.LinkedList; + +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.StringConfigOption; +import org.dllearner.core.dl.KB; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.reasoning.DIGConverter; + +/** + * @author Jens Lehmann + * + */ +public class KBFile extends KnowledgeSource { + + private File file; + private KB kb; + + public static String getName() { + return "KB file"; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringConfigOption("filename", "pointer to the KB file")); + return options; + } + + /* + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String option = entry.getOptionName(); + if (option.equals("filename")) { + file = new File((String)entry.getValue()); + } + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + try { + kb = KBParser.parseKBFile(file); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#toDIG() + */ + @Override + public String toDIG(URI kbURI) { + return DIGConverter.getDIGString(kb).toString(); + } + +} Modified: trunk/src/dl-learner/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/kb/OWLFile.java 2007-10-02 17:42:58 UTC (rev 162) @@ -25,7 +25,6 @@ import java.util.Collection; import java.util.LinkedList; -import org.dllearner.OntologyFileFormat; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; Copied: trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java (from rev 160, trunk/src/dl-learner/org/dllearner/OntologyFileFormat.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,11 @@ +package org.dllearner.kb; + +public enum OntologyFileFormat { + + // RDF-Triples in XML file + RDF_XML, + + // N-Triple format (subformat of N3) + N_TRIPLES + +} Added: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,101 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.kb; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.StringConfigOption; +import org.dllearner.core.StringSetConfigOption; + +/** + * Represents a SPARQL Endpoint. + * TODO: move org.dllearner.modules.sparql to this package and + * integrate its classes + * TODO: Is it necessary to create a class DBpediaSparqlEndpoint? + * + * @author Jens Lehmann + * + */ +public class SparqlEndpoint extends KnowledgeSource { + + private URL url; + private Set<String> instances; + + public static String getName() { + return "SPARQL Endpoint"; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); + options.add(new StringSetConfigOption("instances","relevant instances e.g. positive and negative examples in a learning problem")); + return options; + } + + /* + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + @SuppressWarnings({"unchecked"}) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String option = entry.getOptionName(); + if (option.equals("url")) { + String s = (String) entry.getValue(); + try { + url = new URL(s); + } catch (MalformedURLException e) { + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(),"malformed URL " + s); + } //catch (URISyntaxException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + //} + } else if(option.equals("instances")) { + instances = (Set<String>) entry.getValue(); + } + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + // TODO add code for downloading data from SPARQL endpoint + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#toDIG() + */ + @Override + public String toDIG(URI kbURI) { + return null; + } + +} Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-10-02 17:42:58 UTC (rev 162) @@ -21,9 +21,9 @@ import java.util.SortedSet; -import org.dllearner.Score; import org.dllearner.core.LearningProblemNew; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -21,10 +21,10 @@ import java.util.SortedSet; -import org.dllearner.Score; import org.dllearner.core.ConfigEntry; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-10-02 15:30:37 UTC (rev 161) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -25,14 +25,13 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.Score; -import org.dllearner.ScoreTwoValued; import org.dllearner.core.BooleanConfigOption; import org.dllearner.core.CommonConfigMappings; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; Copied: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java (from rev 160, trunk/src/dl-learner/org/dllearner/ScoreThreeValued.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2007-10-02 17:42:58 UTC (rev 162) @@ -0,0 +1,200 @@ +package org.dllearner.learningproblems; + +import java.text.DecimalFormat; +import java.util.Set; +import java.util.SortedSet; + +import org.dllearner.Config; +import org.dllearner.core.Score; +import org.dllearner.core.dl.Individual; +import org.dllearner.utilities.Helper; + +/** + * Berechnet die Punktzahl (negativ), indem es die Ergebnisse einer Definition + * mit den Soll-Ergebnissen vergleicht. + * + * TODO: die Implementierung ist momentan dahingehend unguenstig, dass viele Sachen + * nur fuer die optische Aufbereitung berechnet werden; effizienter waere es + * nur die Klassifikationsfehler zu beruecksichtigen und andere statistische Werte nur + * dann wenn sie benoetigt werden + * + * @author Jens Lehmann + * + */ +public class ScoreThreeValued extends Score { + + public enum ScoreMethod {POSITIVE, FULL}; + + private SortedSet<Individual> posClassified; + private SortedSet<Individual> neutClassified; + private SortedSet<Individual> negClassified; + private SortedSet<Individual> posExamples; + private SortedSet<Individual> neutExamples; + private SortedSet<Individual> negExamples; + + private Set<Individual> posAsNeg; + private Set<Individual> negAsPos; + private Set<Individual> posAsNeut; + private Set<Individual> neutAsPos; + private Set<Individual> neutAsNeg; + private Set<Individual> negAsNeut; + private Set<Individual> posAsPos; + private Set<Individual> negAsNeg; + private Set<Individual> neutAsNeut; + + private double score; + private double accuracy; + private double accuracyOnExamples; + private double accuracyOnPositiveExamples; + private double errorRate; + + private int nrOfExamples; + private int conceptLength; + + public ScoreThreeValued(int conceptLength, + SortedSet<Individual> posClassified, + SortedSet<Individual> neutClassified, + SortedSet<Individual> negClassified, + SortedSet<Individual> posExamples, + SortedSet<Individual> neutExamples, + SortedSet<Individual> negExamples) { + this.conceptLength = conceptLength; + this.posClassified = posClassified; + this.neutClassified = neutClassified; + this.negClassified = negClassified; + this.posExamples = posExamples; + this.neutExamples = neutExamples; + this.negExamples = negExamples; + nrOfExamples = posExamples.size()+negExamples.size(); + computeClassificationMatrix(); + computeStatistics(); + } + + private void computeClassificationMatrix() { + posAsNeg = Helper.intersection(posExamples,negClassified); + negAsPos = Helper.intersection(negExamples,posClassified); + posAsNeut = Helper.intersection(posExamples,neutClassified); + neutAsPos = Helper.intersection(neutExamples,posClassified); + neutAsNeg = Helper.intersection(neutExamples,negClassified); + negAsNeut = Helper.intersection(negExamples,neutClassified); + // die 3 Berechnungen sind nicht so wichtig f�r die Punktzahl, d.h. falls + // es Performance bringt, dann kann man sie auch ausgliedern + posAsPos = Helper.intersection(posExamples,posClassified); + negAsNeg = Helper.intersection(negExamples,negClassified); + neutAsNeut = Helper.intersection(neutExamples,neutClassified); + } + + private void computeStatistics() { + score = - posAsNeg.size()*Config.errorPenalty + - negAsPos.size()*Config.errorPenalty + - posAsNeut.size()*Config.accuracyPenalty; + + if(Config.scoreMethod==ScoreMethod.FULL) + score -= negAsNeut.size()*Config.accuracyPenalty; + + if(Config.penalizeNeutralExamples) + score -= (neutAsPos.size()*Config.accuracyPenalty + + neutAsNeg.size()*Config.accuracyPenalty); + + // TODO: man könnte hier statt error penality auch accuracy penalty + // nehmen + double worstValue = nrOfExamples * Config.errorPenalty; + // ergibt Zahl zwischen -1 und 0 + score = score / worstValue; + score -= Config.percentPerLengthUnit * conceptLength; + + // die folgenden Berechnungen k�nnten aus Performancegr�nden auch + // ausgegliedert werden + // int domainSize = abox.domain.size(); + int numberOfExamples = posExamples.size()+negExamples.size(); + int domainSize = numberOfExamples + neutExamples.size(); + int correctlyClassified = posAsPos.size() + negAsNeg.size() + neutAsNeut.size(); + int correctOnExamples = posAsPos.size() + negAsNeg.size(); + int errors = posAsNeg.size() + negAsPos.size(); + + // Accuracy = Quotient von richtig klassifizierten durch Anzahl Domainelemente + accuracy = (double) correctlyClassified/domainSize; + + // Accuracy on Examples = Quotient von richtig klassifizierten durch Anzahl pos. + // und neg. Beispiele + accuracyOnExamples = (double) correctOnExamples/numberOfExamples; + + accuracyOnPositiveExamples = (double) posAsPos.size()/posExamples.size(); + + // Error = Quotient von komplett falsch klassifizierten durch Anzahl pos. + // und neg. Beispiele + errorRate = (double) errors/numberOfExamples; + } + + @Override + public double getScore() { + return score; + } + + @Override + public String toString() { + DecimalFormat df = new DecimalFormat("0.00"); + String str = ""; + str += "score method "; + if(Config.scoreMethod == ScoreMethod.FULL) + str += "full"; + else + str += "positive"; + if(!Config.penalizeNeutralExamples) + str += " (neutral examples not penalized)"; + str += "\n"; + if(Config.showCorrectClassifications) { + str += "Correctly classified:\n"; + str += " positive --> positive: " + posAsPos + "\n"; + str += " neutral --> neutral: " + neutAsNeut + "\n"; + str += " negative --> negative: " + negAsNeg + "\n"; + } + str += "Inaccurately classified (penalty of " + df.format(Config.accuracyPenalty) + " per instance):\n"; + str += " positive --> neutral: " + posAsNeut + "\n"; + if(Config.penalizeNeutralExamples) { + str += " neutral --> positive: " + neutAsPos + "\n"; + str += " neutral --> negative: " + neutAsNeg + "\n"; + } + if(Config.scoreMethod == ScoreMethod.FULL) + str += " negative --> neutral: " + negAsNeut + "\n"; + str += "Classification errors (penalty of " + df.format(Config.errorPenalty) + " per instance):\n"; + str += " positive --> negative: " + posAsNeg + "\n"; + str += " negative --> positive: " + negAsPos + "\n"; + str += "Statistics:\n"; + str += " Score: " + df.format(score) + "\n"; + str += " Accuracy: " + df.format(accuracy*100) + "%\n"; + str += " Accuracy on exa... [truncated message content] |
From: <jen...@us...> - 2007-10-03 10:45:36
|
Revision: 166 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=166&view=rev Author: jenslehmann Date: 2007-10-03 03:45:34 -0700 (Wed, 03 Oct 2007) Log Message: ----------- all parts of DL-Learner moved to the new learning problem structure Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/LearningProblem.java trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-03 10:45:34 UTC (rev 166) @@ -7,7 +7,6 @@ import java.util.List; import java.util.Set; -import org.dllearner.LearningProblem.LearningProblemType; import org.dllearner.algorithms.gp.GP.AlgorithmType; import org.dllearner.algorithms.gp.GP.SelectionType; import org.dllearner.core.dl.AtomicConcept; @@ -32,7 +31,7 @@ public static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; - public static LearningProblemType learningProblemType = LearningProblemType.TWO_VALUED; + // public static LearningProblemType learningProblemType = LearningProblemType.TWO_VALUED; public static boolean penalizeNeutralExamples = false; Deleted: trunk/src/dl-learner/org/dllearner/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-03 10:45:34 UTC (rev 166) @@ -1,282 +0,0 @@ -package org.dllearner; - -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.Config.Refinement; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.Negation; -import org.dllearner.learningproblems.ScoreThreeValued; -import org.dllearner.learningproblems.ScoreTwoValued; -import org.dllearner.learningproblems.PosNegLP.UseMultiInstanceChecks; -import org.dllearner.reasoning.ReasonerType; -import org.dllearner.utilities.Helper; -import org.dllearner.utilities.SortedSetTuple; - -/** - * Der Score-Calculator nimmt Konzepte (= m�gliche L�sungen des Lernproblems) - * entgegen und gibt Score-Objekte zur�ck. - * - * @author jl - * - */ -public class LearningProblem { - - public enum LearningProblemType {POSITIVE_ONLY, TWO_VALUED, THREE_VALUED}; - - private ReasoningService reasoningService; - - private SortedSet<Individual> positiveExamples; - private SortedSet<Individual> negativeExamples; - private SortedSet<Individual> neutralExamples; - // positive and negative examples - private SortedSet<Individual> posNegExamples; - - public LearningProblem(ReasoningService reasoningService, - SortedSet<Individual> positiveExamples, - SortedSet<Individual> negativeExamples) { - this.reasoningService = reasoningService; - this.positiveExamples = positiveExamples; - this.negativeExamples = negativeExamples; - - posNegExamples = Helper.union(positiveExamples, negativeExamples); - - // neutrale Beispiele berechnen (nur bei three valued interessant) - // auch hier aufpassen, dass man die Mengen immer kopiert - neutralExamples = Helper.intersection(reasoningService.getIndividuals(),positiveExamples); - neutralExamples.retainAll(negativeExamples); - - // System.out.println(positiveExamples); - // System.out.println(negativeExamples); - } - - // gibt -1 zurück, falls Konzept too weak; - // ansonsten die negativen Beispiele, die aus Konzept folgen - // wird verwendet für top-down-approach - // TODO: hier sind vielleicht noch Effizienzverbesserungen gegenüber dem reinen berechnen - // mit computeScore() drin [ist bis jetzt noch mehr oder weniger rüberkopiert] - public int coveredNegativeExamplesOrTooWeak(Concept concept) { - if(!Config.learningProblemType.equals(LearningProblemType.TWO_VALUED)) - throw new RuntimeException("Can use this method only for two valued learning problem."); - - if(Config.useRetrievalForClassification) { - //if(Config.reasonerType == ReasonerType.KAON2 || Config.reasonerType == ReasonerType.FAST_RETRIEVAL) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - // die Menge wird schrittweise konstruiert um Operationen mit der potentiell - // großen Menge aller Individuals zu vermeiden - for(Individual posExample : positiveExamples) { - if(!posClassified.contains(posExample)) - posAsNeg.add(posExample); - } - - // es werden nicht alle positiven Beispiele auch positiv klassifiziert - if(posAsNeg.size()>0) - return -1; - else - return negAsPos.size(); - //} else - // throw new Error("LP not completely implemented"); - } else { - if(Refinement.useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { - // Option wird nur bei DIG-Reasoner genutzt, ansonsten einfach ignoriert - if(Config.reasonerType == ReasonerType.DIG) { - // two checks - if(Config.Refinement.useDIGMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { - Set<Individual> s = reasoningService.instanceCheck(concept, positiveExamples); - // if the concept is too weak, then do not query negative examples - if(s.size()!=positiveExamples.size()) - return -1; - else { - s = reasoningService.instanceCheck(concept, negativeExamples); - return s.size(); - } - // one check - } else { - Set<Individual> s = reasoningService.instanceCheck(concept, posNegExamples); - // test whether all positive examples are covered - if(s.containsAll(positiveExamples)) - return s.size() - positiveExamples.size(); - else - return -1; - } - } - } - - if(Config.reasonerType != ReasonerType.FAST_RETRIEVAL) { - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - for(Individual example : positiveExamples) { - if(!reasoningService.instanceCheck(concept, example)) - posAsNeg.add(example); - } - for(Individual example : negativeExamples) { - if(reasoningService.instanceCheck(concept, example)) - negAsPos.add(example); - } - - if(posAsNeg.size()>0) - return -1; - else - return negAsPos.size(); - } - } - throw new Error("LP not completely implemented"); - } - - public Score computeScore(Concept concept) { - if(Config.learningProblemType.equals(LearningProblemType.TWO_VALUED)) - return computeScoreTwoValued(concept); - else - return computeScoreThreeValued(concept); - } - - public Score computeScore(Concept concept, Concept adc) { - if(Config.learningProblemType.equals(LearningProblemType.TWO_VALUED)) - throw new Error("LP not completely implemented"); - else - return computeScoreThreeValued(concept, adc); - } - - private Score computeScoreTwoValued(Concept concept) { - if(Config.useRetrievalForClassification) { - if(Config.reasonerType == ReasonerType.DIG || Config.reasonerType == ReasonerType.KAON2 || Config.reasonerType == ReasonerType.FAST_RETRIEVAL) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - // die Menge wird schrittweise konstruiert um Operationen mit der potentiell - // großen Menge aller Individuals zu vermeiden - for(Individual posExample : positiveExamples) { - if(!posClassified.contains(posExample)) - posAsNeg.add(posExample); - } - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - for(Individual negExample : negativeExamples) { - if(!posClassified.contains(negExample)) - negAsNeg.add(negExample); - } - return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, negAsNeg); - } else - throw new Error("LP not completely implemented"); - // instance checks zur Klassifikation - } else { - if(Config.reasonerType != ReasonerType.FAST_RETRIEVAL) { - SortedSet<Individual> posAsPos = new TreeSet<Individual>(); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - for(Individual example : positiveExamples) { - if(reasoningService.instanceCheck(concept, example)) - posAsPos.add(example); - else - posAsNeg.add(example); - } - for(Individual example : negativeExamples) { - if(reasoningService.instanceCheck(concept, example)) - negAsPos.add(example); - else - negAsNeg.add(example); - } - return new ScoreTwoValued(concept.getLength(),posAsPos, posAsNeg, negAsPos, negAsNeg); - } else - throw new Error("LP not completely implemented"); - } - } - - private Score computeScoreThreeValued(Concept concept) { - // Anfragen an Reasoner - if(Config.useRetrievalForClassification) { - if(Config.reasonerType == ReasonerType.FAST_RETRIEVAL) { - SortedSetTuple<Individual> tuple = reasoningService.doubleRetrieval(concept); - // this.defPosSet = tuple.getPosSet(); - // this.defNegSet = tuple.getNegSet(); - SortedSet<Individual> neutClassified = Helper.intersectionTuple(reasoningService.getIndividuals(),tuple); - return new ScoreThreeValued(concept.getLength(),tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); - } else if(Config.reasonerType == ReasonerType.KAON2) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> negClassified = reasoningService.retrieval(new Negation(concept)); - SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); - neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); - } else - throw new Error("score cannot be computed in this configuration"); - } else { - if(Config.reasonerType == ReasonerType.KAON2) { - if(Config.penalizeNeutralExamples) - throw new Error("It does not make sense to use single instance checks when" + - "neutral examples are penalized. Use Retrievals instead."); - - // TODO: umschreiben in instance checks - SortedSet<Individual> posClassified = new TreeSet<Individual>(); - SortedSet<Individual> negClassified = new TreeSet<Individual>(); - // Beispiele durchgehen - // TODO: Implementierung ist ineffizient, da man hier schon in Klassen wie - // posAsNeut, posAsNeg etc. einteilen k�nnte; so wird das extra in der Score-Klasse - // gemacht; bei wichtigen Benchmarks des 3-wertigen Lernproblems m�sste man das - // umstellen - // pos => pos - for(Individual example : positiveExamples) { - if(reasoningService.instanceCheck(concept, example)) - posClassified.add(example); - } - // neg => pos - for(Individual example: negativeExamples) { - if(reasoningService.instanceCheck(concept, example)) - posClassified.add(example); - } - // pos => neg - for(Individual example : positiveExamples) { - if(reasoningService.instanceCheck(new Negation(concept), example)) - negClassified.add(example); - } - // neg => neg - for(Individual example : negativeExamples) { - if(reasoningService.instanceCheck(new Negation(concept), example)) - negClassified.add(example); - } - - SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); - neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); - } else - throw new Error("score cannot be computed in this configuration"); - } - } - - private Score computeScoreThreeValued(Concept concept, Concept adc) { - if(!Config.useRetrievalForClassification && - Config.reasonerType != ReasonerType.FAST_RETRIEVAL) { - throw new Error("Computing score for concept with ADC" - + " is currently only supported by retrivals " - + " using the fast retrieval algorithm"); - } else { - // SortedSetTuple tuple = reasoner.doubleRetrieval(concept,adc); - // this.defPosSet = tuple.getPosSet(); - // this.defNegSet = tuple.getNegSet(); - // deriveStatistics(); - } - throw new Error("LP not completely implemented"); - } - - public SortedSet<Individual> getNegativeExamples() { - return negativeExamples; - } - - public SortedSet<Individual> getNeutralExamples() { - return neutralExamples; - } - - public SortedSet<Individual> getPositiveExamples() { - return positiveExamples; - } - - public ReasoningService getReasoningService() { - return reasoningService; - } -} Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 10:45:34 UTC (rev 166) @@ -44,6 +44,8 @@ import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.core.ComponentManager; +import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningProblem; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; @@ -61,6 +63,7 @@ import org.dllearner.kb.OntologyFileFormat; import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.modules.ModuleInvocator; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -97,7 +100,7 @@ private Reasoner reasoner; private ReasoningService rs; - private LearningProblem learningProblem; + private PosNegLP learningProblem; // es werden jeweils die Dateien mit dem zugehörigen Format abgelegt Map<URL, OntologyFileFormat> importedFiles; Map<File, OntologyFileFormat> exportedFiles; @@ -235,7 +238,8 @@ reasoner = createReasoner(kb, importedFiles); ReasoningService rs = new ReasoningService(reasoner); - learningProblem = new LearningProblem(rs, posExamples, negExamples); + // commented out during changes + // learningProblem = new LearningProblem(rs, posExamples, negExamples); // export function /* @@ -412,7 +416,7 @@ algorithmStartTime = System.nanoTime(); if (Config.algorithm == Algorithm.BRUTE_FORCE) { - LearningAlgorithm la = new BruteForceLearner(learningProblem); + LearningAlgorithmNew la = new BruteForceLearner(learningProblem); la.start(); } else if (Config.algorithm == Algorithm.RANDOM_GUESSER) { // new RandomGuesser(learningProblem, 10000, 10); @@ -444,7 +448,7 @@ // implemented)"); // } } - LearningAlgorithm la = new ROLearner(learningProblem); + LearningAlgorithmNew la = new ROLearner(learningProblem); la.start(); // new ROLearner(learningProblem, learningProblem2); } @@ -1293,95 +1297,9 @@ return abox; } - // irgendwelche Sachen testen - @SuppressWarnings("unused") - private void test(LearningProblem learningProblem) { - System.out.println("=== starting test method ==="); - // Concept concept = DLLearner.parseConcept("NOT EXISTS hasChild.NOT - // male"); - // System.out.println("testing: " + concept); - /* - * PsiDown pd = new PsiDown(learningProblem); concept = - * ConceptTransformation.transformToMulti(concept); - * - * Set<Concept> r = pd.refine(concept); System.out.println(r); - */ - /* - * Concept result = - * ConceptTransformation.transformToNegationNormalForm(concept); - * System.out.println(result); - * - */ - - /* - * Concept male = new - * AtomicConcept("http://www.csc.liv.ac.uk/~luigi/ontologies/basicFamily#Male"); - * AtomicRole hasChild = new - * AtomicRole("http://www.csc.liv.ac.uk/~luigi/ontologies/basicFamily#hasChild"); - * Concept exists = new Exists(hasChild, new Top()); MultiConjunction mc = - * new MultiConjunction(); mc.addChild(male); mc.addChild(exists); - * - * SortedSet<String> result = rs.retrieval(mc); for(String s : result) - * System.out.println(s); - * - * SortedSet<String> result2 = Helper.intersection(result, - * learningProblem.getPositiveExamples()); - * - * Score score = learningProblem.computeScore(mc); - * System.out.println("==="); - * System.out.println(score.getCoveredPositives()); - * System.out.println(score.getCoveredNegatives()); - * - * Concept top = new Top(); RhoDown rd = new RhoDown(learningProblem); - * Set<Concept> result3 = rd.refine(top, 3, null); for(Concept c : - * result3) System.out.println(c); - * - * System.out.println(rs.getMoreSpecialConcepts(top)); - * - * Concept container = new - * AtomicConcept("http://www.w3.org/2000/01/rdf-schema#Resource"); - * System.out.println(((DIGReasoner)reasoner).getMoreSpecialConceptsDIG(container)); - */ - - /* - * for(int i=0; i<10; i++) { Program p = - * GPUtilities.createGrowRandomProgram(learningProblem, 3); // - * System.out.println("concept: " + p.getTree()); // - * System.out.println("fitness: " + p.getFitness()); // - * System.out.println("length of concept: " + p.getTree().getLength()); // - * System.out.println(p.getScore()); - * - * System.out.println("##"); boolean ok = GPUtilities.checkProgram(p); // - * if(!ok) System.out.println(p.getTree()); } - * - * System.out.println("==="); // Concept male = new - * AtomicConcept("male"); Concept male = - * rs.getAtomicConceptsList().get(0); // Concept male = null; // - * for(Concept c : rs.getAtomicConcepts()) // male = c; - * GPUtilities.checkTree(male, true); System.out.println(male); - * System.out.println(male.getParent()); - */ - - Concept c = null; - try { - c = KBParser.parseConcept("EXISTS r.(TOP AND (TOP OR BOTTOM))"); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - ConceptTransformation.transformToMulti(c); - // Concept cMod = - // ConceptTransformation.transformToNegationNormalForm(c); - Concept cMod = ConceptTransformation.applyEquivalenceRules(c); - System.out.println(c); - System.out.println(cMod); - - System.exit(0); - } - // generiert sibling aus Forte-Daten @SuppressWarnings("unused") - private void test2(LearningProblem learningProblem) { + private void test2(PosNegLP learningProblem) { // Set<AtomicRole> roles = reasoner.getAtomicRoles(); // for(AtomicRole role : roles) { // System.out.println(rs.getRoleMembers(role)); Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-03 10:45:34 UTC (rev 166) @@ -1,12 +1,18 @@ package org.dllearner.algorithms; +import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.dllearner.Config; -import org.dllearner.LearningProblem; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.IntegerConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -27,7 +33,7 @@ * @author Jens Lehmann * */ -public class BruteForceLearner implements LearningAlgorithm { +public class BruteForceLearner extends LearningAlgorithmNew { LearningProblem learningProblem; @@ -48,10 +54,37 @@ public BruteForceLearner(LearningProblem learningProblem) { this.learningProblem = learningProblem; - - } + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); + problems.add(LearningProblem.class); + return problems; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new IntegerConfigOption("numberOfTrees", "number of randomly generated concepts/trees")); + options.add(new IntegerConfigOption("maxDepth", "maximum depth of generated concepts/trees")); + return options; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String name = entry.getOptionName(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + + } + public void start() { // FlatABox abox = FlatABox.getInstance(); int maxLength = Config.maxLength; Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-03 10:45:34 UTC (rev 166) @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.LinkedList; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.gp.Program; import org.dllearner.algorithms.gp.GPUtilities; import org.dllearner.core.ConfigEntry; @@ -30,29 +29,26 @@ import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; -import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; -import org.dllearner.learningproblems.DefinitionLP; -import org.dllearner.learningproblems.PosNegDefinitionLPStrict; -import org.dllearner.learningproblems.PosNegDefinitionLP; public class RandomGuesser extends LearningAlgorithmNew implements LearningAlgorithm { private Concept bestDefinition = null; private Score bestScore; private double bestFitness = Double.NEGATIVE_INFINITY; - private LearningProblemNew learningProblem; + private LearningProblem learningProblem; private int numberOfTrees; private int maxDepth; - public RandomGuesser(LearningProblemNew learningProblem) { + public RandomGuesser(LearningProblem learningProblem) { this.learningProblem = learningProblem; } - public static Collection<Class<? extends LearningProblemNew>> supportedLearningProblems() { - Collection<Class<? extends LearningProblemNew>> problems = new LinkedList<Class<? extends LearningProblemNew>>(); - problems.add(LearningProblemNew.class); + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); + problems.add(LearningProblem.class); return problems; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-03 10:45:34 UTC (rev 166) @@ -46,18 +46,16 @@ import java.util.Map.Entry; import org.dllearner.Config; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.algorithms.hybridgp.Psi; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.LearningAlgorithmNew; -import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Top; -import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.Helper; @@ -133,8 +131,8 @@ this.learningProblem = learningProblem; } - public static Collection<Class<? extends LearningProblemNew>> supportedLearningAlgorithms() { - Collection<Class<? extends LearningProblemNew>> problems = new LinkedList<Class<? extends LearningProblemNew>>(); + public static Collection<Class<? extends LearningProblem>> supportedLearningAlgorithms() { + Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); problems.add(PosNegLP.class); return problems; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-03 10:45:34 UTC (rev 166) @@ -9,7 +9,7 @@ import org.dllearner.Config; import org.dllearner.Main; -import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -57,7 +57,7 @@ private static Random rand = new Random(); - private static Score calculateFitness(LearningProblemNew learningProblem, Concept hypothesis) { + private static Score calculateFitness(LearningProblem learningProblem, Concept hypothesis) { return calculateFitness(learningProblem, hypothesis, null); } @@ -66,7 +66,7 @@ // (macht aber nicht so viel Sinn, da man das bei richtigen Reasoning-Algorithmen // ohnehin mit einer Erweiterung der Wissensbasis um die Inklusion Target SUBSETOF ReturnType // erschlagen kann) - private static Score calculateFitness(LearningProblemNew learningProblem, Concept hypothesis, Concept adc) { + private static Score calculateFitness(LearningProblem learningProblem, Concept hypothesis, Concept adc) { Concept extendedHypothesis; if (!Config.returnType.equals("")) { @@ -123,11 +123,11 @@ return score; } - public static Program createProgram(LearningProblemNew learningProblem, Concept mainTree) { + public static Program createProgram(LearningProblem learningProblem, Concept mainTree) { return new Program(calculateFitness(learningProblem, mainTree), mainTree); } - private static Program createProgram(LearningProblemNew learningProblem, Concept mainTree, Concept adc) { + private static Program createProgram(LearningProblem learningProblem, Concept mainTree, Concept adc) { return new Program(calculateFitness(learningProblem, mainTree,adc), mainTree, adc); } @@ -135,7 +135,7 @@ * Perform a point mutation on the given program. * @param p The program to be mutated. */ - public static Program mutation(LearningProblemNew learningProblem, Program p) { + public static Program mutation(LearningProblem learningProblem, Program p) { mutation++; if(Config.GP.adc) { // TODO: hier kann man noch mehr Feinabstimmung machen, d.h. @@ -159,7 +159,7 @@ } } - private static Concept mutation(LearningProblemNew learningProblem, Concept tree, boolean useADC) { + private static Concept mutation(LearningProblem learningProblem, Concept tree, boolean useADC) { // auch bei Mutation muss darauf geachtet werden, dass // Baum nicht modifiziert wird (sonst w�rde man automatisch auch // andere "selected individuals" modifizieren) @@ -228,7 +228,7 @@ * @param p2 Second parent. * @return A two-element array containing the offpsring. */ - public static Program[] crossover(LearningProblemNew learningProblem, Program p1, Program p2) { + public static Program[] crossover(LearningProblem learningProblem, Program p1, Program p2) { crossover++; if(Config.GP.adc) { Concept[] pt; @@ -304,7 +304,7 @@ // m�sste auch mit ADC funktionieren, da nur am Hauptbaum etwas // ver�ndert wird - public static Program hillClimbing(LearningProblemNew learningProblem, Program p) { + public static Program hillClimbing(LearningProblem learningProblem, Program p) { hillClimbing++; // checken, ob Bedingungen f�r hill-climbing erf�llt sind if(!learningProblem.getReasoningService().getReasonerType().equals(ReasonerType.FAST_RETRIEVAL) @@ -327,7 +327,7 @@ // Alternativen zu speichern und dann ein Element zuf�llig auszuw�hlen, // aber w�rde man das nicht machen, dann w�re das ein starker Bias // zu z.B. Disjunktion (weil die als erstes getestet wird) - private static Concept hillClimbing(LearningProblemNew learningProblem, Concept node, ScoreThreeValued score) { + private static Concept hillClimbing(LearningProblem learningProblem, Concept node, ScoreThreeValued score) { SortedSetTuple<Individual> tuple = new SortedSetTuple<Individual>(score.getPosClassified(),score.getNegClassified()); SortedSetTuple<String> stringTuple = Helper.getStringTuple(tuple); // FlatABox abox = FlatABox.getInstance(); @@ -442,7 +442,7 @@ } } - private static ScoreThreeValued getScore(int conceptLength, LearningProblemNew learningProblem, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { + private static ScoreThreeValued getScore(int conceptLength, LearningProblem learningProblem, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { // es muss hier die Helper-Methode verwendet werden, sonst werden // Individuals gel�scht !! SortedSet<Individual> neutClassified = Helper.intersection(learningProblem.getReasoningService().getIndividuals(),posClassified); @@ -479,7 +479,7 @@ return returnMap; } - private static Concept pickTerminalSymbol(LearningProblemNew learningProblem, boolean useADC) { + private static Concept pickTerminalSymbol(LearningProblem learningProblem, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int nr; int nrOfConcepts = learningProblem.getReasoningService().getAtomicConcepts().size(); @@ -609,7 +609,7 @@ * @param depth Depth of the tree. * @return The created program. */ - public static Program createFullRandomProgram(LearningProblemNew learningProblem, int depth) { + public static Program createFullRandomProgram(LearningProblem learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, true), @@ -619,7 +619,7 @@ return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, false)); } - private static Concept createFullRandomTree(LearningProblemNew learningProblem, int depth, boolean useADC) { + private static Concept createFullRandomTree(LearningProblem learningProblem, int depth, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int numberOfRoles = learningProblem.getReasoningService().getAtomicRoles().size(); // abox.roles.size(); @@ -670,7 +670,7 @@ * @param depth The maximum depth of the program tree. * @return The created program. */ - public static Program createGrowRandomProgram(LearningProblemNew learningProblem, int depth) { + public static Program createGrowRandomProgram(LearningProblem learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createGrowRandomTree(learningProblem,depth,true), @@ -680,7 +680,7 @@ return createProgram(learningProblem, createGrowRandomTree(learningProblem, depth,false)); } - private static Concept createGrowRandomTree(LearningProblemNew learningProblem, int depth, boolean useADC) { + private static Concept createGrowRandomTree(LearningProblem learningProblem, int depth, boolean useADC) { /* private static Concept pickAlphabetSymbol(boolean useADC) { FlatABox abox = FlatABox.getInstance(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-03 10:45:34 UTC (rev 166) @@ -5,12 +5,9 @@ import java.util.SortedMap; import java.util.TreeMap; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.gp.Program; -import org.dllearner.core.LearningProblemNew; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; -import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-10-03 10:45:34 UTC (rev 166) @@ -7,7 +7,6 @@ import java.util.Set; import java.util.TreeSet; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.All; @@ -21,7 +20,6 @@ import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Top; -import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-10-03 10:45:34 UTC (rev 166) @@ -7,7 +7,6 @@ import java.util.Set; import java.util.TreeSet; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.All; @@ -21,7 +20,6 @@ import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Top; -import org.dllearner.learningproblems.DefinitionLP; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-03 10:45:34 UTC (rev 166) @@ -1,6 +1,7 @@ package org.dllearner.algorithms.refinement; import java.text.DecimalFormat; +import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; @@ -10,19 +11,26 @@ import java.util.TreeSet; import org.dllearner.Config; -import org.dllearner.LearningProblem; import org.dllearner.algorithms.LearningAlgorithm; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.IntegerConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.MultiConjunction; import org.dllearner.core.dl.MultiDisjunction; import org.dllearner.core.dl.Top; +import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; -public class ROLearner implements LearningAlgorithm { +public class ROLearner extends LearningAlgorithmNew { private boolean stop = false; @@ -31,7 +39,7 @@ private ConceptComparator conceptComparator = new ConceptComparator(); DecimalFormat df = new DecimalFormat(); - private LearningProblem learningProblem; + private PosNegLP learningProblem; // private LearningProblem learningProblem2; // Menge von Kandidaten für Refinement @@ -103,7 +111,7 @@ // soll später einen Operator und eine Heuristik entgegennehmen // public ROLearner(LearningProblem learningProblem, LearningProblem learningProblem2) { - public ROLearner(LearningProblem learningProblem) { + public ROLearner(PosNegLP learningProblem) { this.learningProblem = learningProblem; // this.learningProblem2 = learningProblem2; operator = new RhoDown(learningProblem); @@ -203,7 +211,36 @@ // start(); } + + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); + problems.add(PosNegDefinitionLP.class); + return problems; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + return options; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + // TODO Auto-generated method stub + + } + // Kernalgorithmus @SuppressWarnings("unchecked") public void start() { @@ -826,4 +863,6 @@ stop = true; } + + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-10-03 10:45:34 UTC (rev 166) @@ -30,7 +30,6 @@ import java.util.TreeSet; import org.dllearner.Config; -import org.dllearner.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -46,6 +45,7 @@ import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Role; import org.dllearner.core.dl.Top; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; @@ -62,7 +62,7 @@ */ public class RhoDown implements RefinementOperator { - private LearningProblem learningProblem; + private PosNegLP learningProblem; private ReasoningService rs; // gibt die Gr��e an bis zu der die Refinements des Top-Konzepts @@ -91,7 +91,7 @@ // braucht man wirklich das learningProblem oder reicht der Reasoning-Service? // TODO: conceptComparator könnte auch noch Parameter sein - public RhoDown(LearningProblem learningProblem) { + public RhoDown(PosNegLP learningProblem) { this.learningProblem = learningProblem; rs = learningProblem.getReasoningService(); } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-03 10:45:34 UTC (rev 166) @@ -62,13 +62,13 @@ private static Set<Class<? extends Component>> components; private static Set<Class<? extends KnowledgeSource>> knowledgeSources; private static Set<Class<? extends ReasonerComponent>> reasonerComponents; - private static Set<Class<? extends LearningProblemNew>> learningProblems; + private static Set<Class<? extends LearningProblem>> learningProblems; private static Set<Class<? extends LearningAlgorithmNew>> learningAlgorithms; // list of all configuration options of all components private static Map<Class<? extends Component>, List<ConfigOption<?>>> componentOptions; private static Map<Class<? extends Component>, Map<String, ConfigOption<?>>> componentOptionsByName; - private static Map<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblemNew>>> algorithmProblemsMapping; + private static Map<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblem>>> algorithmProblemsMapping; private Comparator<Class<?>> classComparator = new Comparator<Class<?>>() { @@ -87,9 +87,9 @@ components = new TreeSet<Class<? extends Component>>(classComparator); knowledgeSources = new TreeSet<Class<? extends KnowledgeSource>>(classComparator); reasonerComponents = new TreeSet<Class<? extends ReasonerComponent>>(classComparator); - learningProblems = new TreeSet<Class<? extends LearningProblemNew>>(classComparator); + learningProblems = new TreeSet<Class<? extends LearningProblem>>(classComparator); learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithmNew>>(classComparator); - algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblemNew>>>( + algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblem>>>( classComparator); // create classes from strings @@ -103,12 +103,12 @@ knowledgeSources.add((Class<? extends KnowledgeSource>) component); else if (ReasonerComponent.class.isAssignableFrom(component)) reasonerComponents.add((Class<? extends ReasonerComponent>) component); - else if (LearningProblemNew.class.isAssignableFrom(component)) - learningProblems.add((Class<? extends LearningProblemNew>) component); + else if (LearningProblem.class.isAssignableFrom(component)) + learningProblems.add((Class<? extends LearningProblem>) component); else if (LearningAlgorithmNew.class.isAssignableFrom(component)) { Class<? extends LearningAlgorithmNew> learningAlgorithmClass = (Class<? extends LearningAlgorithmNew>) component; learningAlgorithms.add(learningAlgorithmClass); - Collection<Class<? extends LearningProblemNew>> problems = (Collection<Class<? extends LearningProblemNew>>) invokeStaticMethod( + Collection<Class<? extends LearningProblem>> problems = (Collection<Class<? extends LearningProblem>>) invokeStaticMethod( learningAlgorithmClass, "supportedLearningProblems"); algorithmProblemsMapping.put(learningAlgorithmClass, problems); } @@ -265,7 +265,7 @@ return new ReasoningService(reasonerInstance); } - public <T extends LearningProblemNew> T learningProblem(Class<T> lp, ReasoningService reasoner) { + public <T extends LearningProblem> T learningProblem(Class<T> lp, ReasoningService reasoner) { if (!learningProblems.contains(lp)) System.err.println("Warning: learning problem " + lp + " is not a registered learning problem component."); @@ -275,15 +275,15 @@ } // automagically calls the right constructor for the given learning problem - public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblemNew lp) { + public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblem lp) { if (!learningAlgorithms.contains(la)) System.err.println("Warning: learning algorithm " + la + " is not a registered learning algorithm component."); // find the right constructor: use the one that is registered and // has the class of the learning problem as a subclass - Class<? extends LearningProblemNew> constructorArgument = null; - for (Class<? extends LearningProblemNew> problemClass : algorithmProblemsMapping.get(la)) { + Class<? extends LearningProblem> constructorArgument = null; + for (Class<? extends LearningProblem> problemClass : algorithmProblemsMapping.get(la)) { if (problemClass.isAssignableFrom(lp.getClass())) constructorArgument = problemClass; } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-03 10:45:34 UTC (rev 166) @@ -57,7 +57,7 @@ rs.init(); // create a learning problem and set positive and negative examples - LearningProblemNew lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); Set<String> positiveExamples = new TreeSet<String>(); positiveExamples.add("http://example.com/father#stefan"); positiveExamples.add("http://example.com/father#markus"); Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-03 10:45:34 UTC (rev 166) @@ -59,8 +59,8 @@ /** * Returns all learning problems supported by this component. */ - public static Collection<Class<? extends LearningProblemNew>> supportedLearningProblems() { - return new LinkedList<Class<? extends LearningProblemNew>>(); + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + return new LinkedList<Class<? extends LearningProblem>>(); } } Copied: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java (from rev 165, trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2007-10-03 10:45:34 UTC (rev 166) @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import org.dllearner.core.dl.Concept; + +/** + * Base class for all learning problems. + * + * @author Jens Lehmann + * + */ +public abstract class LearningProblem extends Component { + + protected ReasoningService reasoningService; + + public LearningProblem(ReasoningService reasoningService) { + this.reasoningService = reasoningService; + } + + public abstract Score computeScore(Concept concept); + + // TODO: remove? reasoning service should probably not be accessed via + // learning problem + public ReasoningService getReasoningService() { + return reasoningService; + } + +} Deleted: trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-10-03 10:45:34 UTC (rev 166) @@ -1,47 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.core; - -import org.dllearner.core.dl.Concept; - -/** - * Base class for all learning problems (the "New" at the end of the name - * is temporary for the restructuring process). - * - * @author Jens Lehmann - * - */ -public abstract class LearningProblemNew extends Component { - - protected ReasoningService reasoningService; - - public LearningProblemNew(ReasoningService reasoningService) { - this.reasoningService = reasoningService; - } - - public abstract Score computeScore(Concept concept); - - // TODO: remove? reasoning service should probably not be accessed via - // learning problem - public ReasoningService getReasoningService() { - return reasoningService; - } - -} Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-03 10:45:34 UTC (rev 166) @@ -211,20 +211,4 @@ } } - @Override - public SortedSet<Individual> getNegativeExamples() { - return negativeExamples; - } - - @Override - public SortedSet<Individual> getPositiveExamples() { - return positiveExamples; - } - - // TODO: remove? reasoning service should probably not be accessed via - // learning problem - @Override - public ReasoningService getReasoningService() { - return reasoningService; - } } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-03 09:53:38 UTC (rev 165) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-03 10:45:34 UTC (rev 166) @@ -19,14 +19,22 @@ */ package org.dllearner.learningproblems; +import java.util.Collection; import java.util.SortedSet; +import java.util.TreeSet; +import org.dllearner.core.BooleanConfigOption; import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.Negation; +import org.dllearner.reasoning.ReasonerType; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.SortedSetTuple; /** * @author Jens Lehmann @@ -34,6 +42,9 @@ */ public class PosNegDefinitionLPStrict extends PosNegLP implements DefinitionLP { + private SortedSet<Individual> neutralExamples; + private boolean penaliseNeutralExamples = false; + public PosNegDefinitionLPStrict(ReasoningService reasoningService) { super(reasoningService); } @@ -45,22 +56,37 @@ return "three valued definition learning problem"; } - /* (non-Javadoc) - * @see org.dllearner.core.Component#init() + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = PosNegLP.createConfigOptions(); + options.add(new BooleanConfigOption("penaliseNeutralExamples", "if set to true neutral examples are penalised")); + return options; + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) */ @Override - public void init() { - // TODO Auto-generated method stub - + @SuppressWarnings( { "unchecked" }) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + super.applyConfigEntry(entry); + String name = entry.getOptionName(); + if(name.equals("penaliseNeutralExamples")) + penaliseNeutralExamples = (Boolean) entry.getValue(); } - + /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + * @see org.dllearner.core.Component#init() */ @Override - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - // TODO Auto-generated method stub - + public void init() { + super.init(); + // compute neutral examples, i.e. those which are neither positive + // nor negative (we have to take care to copy sets instead of + // modifying them) + neutralExamples = Helper.intersection(reasoningService.getIndividuals(),positiveExamples); + neutralExamples.retainAll(negativeExamples); } /* (non-Javadoc) @@ -68,8 +94,62 @@ */ @Override public Score computeScore(Concept concept) { - // TODO Auto-generated method stub - return null; + if(useRetrievalForClassification) { + if(reasoningService.getReasonerType() == ReasonerType.FAST_RETRIEVAL) { + SortedSetTuple<Individual> tuple = reasoningService.doubleRetrieval(concept); + // this.defPosSet = tuple.getPosSet(); + // this.defNegSet = tuple.getNegSet(); + SortedSet<Individual> neutClassified = Helper.intersectionTuple(reasoningService.getIndividuals(),tuple); + return new ScoreThreeValued(concept.getLength(),tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); + } else if(reasoningService.getReasonerType() == ReasonerType.KAON2) { + SortedSet<Individual> posClassified = reasoningService.retrieval(concept); + SortedSet<Individual> negClassified = reasoningService.retrieval(new Negation(concept)); + SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); + neutClassified.retainAll(negClassified); + return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + } else + throw new Error("score cannot be computed in this configuration"); + } else { + if(reasoningService.getReasonerType() == ReasonerType.KAON2) { + if(penaliseNeutralExamples) + throw new Error("It does not make sense to use single instance checks when" + + "neutral examples are penalized. Use Retrievals instead."); + + // TODO: umschreiben in instance checks + SortedSet<Individual> posClassified = new TreeSet<Individual>(); + SortedSet<Individual> negClassified = new TreeSet<Individual>(); + // Beispiele durchgehen + // TODO: Implementierung ist ineffizient, da man hier schon in Klassen wie + // posAsNeut, posAsNeg etc. einteilen k�nnte; so wird das extra in der Score-Klasse + // gemacht; bei wichtigen Benchmarks des 3-wertigen Lernproblems m�sste man das + // umstellen + // pos => pos + for(Individual example : positiveExamples) { + if(reasoningService.instanceCheck(concept, example)) + posClassified.add(example); + } + // neg => pos + for(Individual example: negativeExamples) { + if(reasoningService.instanceCheck(concept, example)) + posClassified.add(example); + } + // pos => neg + for(Individual example : positiveExamples) { + if(reasoningService.instanceCheck(new Negation(concept), example)) + negClassified.add(example); + } + // neg => neg + for(Individual example : negativeExamples) { + if(reasoningService.instanceCheck(new Negation(concept), example)) + negClassified.add(example); + } + + SortedSet<Individual> neutClassified = Helper.intersection(reasoningService.getIndividuals(),posClassified); + neutClassified.retainAll(negClassified); + return new ScoreThreeValued(concept.getLength(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + } else + throw new Error("score cannot be computed in this configuration"); + } } /* (non-Javadoc) @@ -77,38 +157,10 @@ */ @Override public int coveredNegativeExamplesOrTooWeak(Concept concept) { - // TODO Auto-generated method stub - return 0; + throw new UnsupportedOperationException("Method not implemented for three valued definition learning problem."); } - /* (non-Javadoc) - * @see org.dllearner.learningproblems.DefinitionLP#getNegativeExamples() - */ - @Override - public SortedSet<Individual> getNegativeExamples() { - // TODO Auto-generated method stub - return null; - } - - /* (n... [truncated message content] |
From: <jen...@us...> - 2007-10-03 11:13:09
|
Revision: 165 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=165&view=rev Author: jenslehmann Date: 2007-10-03 02:53:38 -0700 (Wed, 03 Oct 2007) Log Message: ----------- - added learning problem structure - partially implemented learning problems Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/LearningProblem.java trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/learningproblems/InclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-03 09:53:38 UTC (rev 165) @@ -12,7 +12,7 @@ import org.dllearner.algorithms.gp.GP.SelectionType; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; -import org.dllearner.learningproblems.DefinitionLP.UseMultiInstanceChecks; +import org.dllearner.learningproblems.PosNegLP.UseMultiInstanceChecks; import org.dllearner.learningproblems.ScoreThreeValued.ScoreMethod; import org.dllearner.reasoning.ReasonerType; Modified: trunk/src/dl-learner/org/dllearner/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/LearningProblem.java 2007-10-03 09:53:38 UTC (rev 165) @@ -12,7 +12,7 @@ import org.dllearner.core.dl.Negation; import org.dllearner.learningproblems.ScoreThreeValued; import org.dllearner.learningproblems.ScoreTwoValued; -import org.dllearner.learningproblems.DefinitionLP.UseMultiInstanceChecks; +import org.dllearner.learningproblems.PosNegLP.UseMultiInstanceChecks; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.Helper; import org.dllearner.utilities.SortedSetTuple; Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 09:53:38 UTC (rev 165) @@ -60,7 +60,7 @@ import org.dllearner.core.dl.RoleAssertion; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.learningproblems.DefinitionLP; -import org.dllearner.learningproblems.DefinitionLPTwoValued; +import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.modules.ModuleInvocator; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -821,7 +821,7 @@ // erzeugt Statistiken für MLDM-Paper zur Verarbeitung mit GnuPlot // Vorsicht: Laufzeit von mehreren Stunden @SuppressWarnings("unused") - private void createStatisticsMLDMPaper(DefinitionLP learningProblem, String baseDir) { + private void createStatisticsMLDMPaper(PosNegDefinitionLP learningProblem, String baseDir) { // Algorithmus 1: hybrid GP (100% refinement) // Algorithmus 2: 50% refinement, 40% crossover, 1% mutation // Algorithmus 3: 80% crossover, 2% mutation @@ -888,7 +888,7 @@ reasoner.prepareSubsumptionHierarchy(); rs = new ReasoningService(reasoner); // learningProblem = new LearningProblem(rs, posExamples, negExamples); - learningProblem = cm.learningProblem(DefinitionLPTwoValued.class, rs); + learningProblem = cm.learningProblem(PosNegDefinitionLP.class, rs); cm.applyConfigEntry(learningProblem, "positiveExamples", posExamples); cm.applyConfigEntry(learningProblem, "negativeExamples", negExamples); Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-03 09:53:38 UTC (rev 165) @@ -34,25 +34,25 @@ import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.learningproblems.DefinitionLP; -import org.dllearner.learningproblems.DefinitionLPThreeValued; -import org.dllearner.learningproblems.DefinitionLPTwoValued; +import org.dllearner.learningproblems.PosNegDefinitionLPStrict; +import org.dllearner.learningproblems.PosNegDefinitionLP; public class RandomGuesser extends LearningAlgorithmNew implements LearningAlgorithm { private Concept bestDefinition = null; private Score bestScore; private double bestFitness = Double.NEGATIVE_INFINITY; - private DefinitionLP learningProblem; + private LearningProblemNew learningProblem; private int numberOfTrees; private int maxDepth; - public RandomGuesser(DefinitionLP learningProblem) { + public RandomGuesser(LearningProblemNew learningProblem) { this.learningProblem = learningProblem; } public static Collection<Class<? extends LearningProblemNew>> supportedLearningProblems() { Collection<Class<? extends LearningProblemNew>> problems = new LinkedList<Class<? extends LearningProblemNew>>(); - problems.add(DefinitionLP.class); + problems.add(LearningProblemNew.class); return problems; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -58,6 +58,7 @@ import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.Helper; /** @@ -116,7 +117,7 @@ private Score bestScore; private Concept bestConcept; - private DefinitionLP learningProblem; + private PosNegLP learningProblem; // private GeneticRefinementOperator psi; private Psi psi; @@ -128,13 +129,13 @@ * 1.0 and a probability of mutation of 0.01. * */ - public GP(DefinitionLP learningProblem) { + public GP(PosNegLP learningProblem) { this.learningProblem = learningProblem; } public static Collection<Class<? extends LearningProblemNew>> supportedLearningAlgorithms() { Collection<Class<? extends LearningProblemNew>> problems = new LinkedList<Class<? extends LearningProblemNew>>(); - problems.add(DefinitionLP.class); + problems.add(PosNegLP.class); return problems; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-03 09:53:38 UTC (rev 165) @@ -25,8 +25,8 @@ import org.dllearner.core.dl.MultiDisjunction; import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.Top; -import org.dllearner.learningproblems.DefinitionLP; -import org.dllearner.learningproblems.DefinitionLPThreeValued; +import org.dllearner.learningproblems.PosNegDefinitionLPStrict; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.ScoreThreeValued; import org.dllearner.reasoning.FastRetrieval; import org.dllearner.reasoning.ReasonerType; @@ -57,7 +57,7 @@ private static Random rand = new Random(); - private static Score calculateFitness(DefinitionLP learningProblem, Concept hypothesis) { + private static Score calculateFitness(LearningProblemNew learningProblem, Concept hypothesis) { return calculateFitness(learningProblem, hypothesis, null); } @@ -66,7 +66,7 @@ // (macht aber nicht so viel Sinn, da man das bei richtigen Reasoning-Algorithmen // ohnehin mit einer Erweiterung der Wissensbasis um die Inklusion Target SUBSETOF ReturnType // erschlagen kann) - private static Score calculateFitness(DefinitionLP learningProblem, Concept hypothesis, Concept adc) { + private static Score calculateFitness(LearningProblemNew learningProblem, Concept hypothesis, Concept adc) { Concept extendedHypothesis; if (!Config.returnType.equals("")) { @@ -89,7 +89,9 @@ Score score; if(Config.GP.adc) - score = learningProblem.computeScore(extendedHypothesis, adc); + // TODO: ADC-Support + // score = learningProblem.computeScore(extendedHypothesis, adc); + throw new RuntimeException("ADC not supported"); else score = learningProblem.computeScore(extendedHypothesis); @@ -121,11 +123,11 @@ return score; } - public static Program createProgram(DefinitionLP learningProblem, Concept mainTree) { + public static Program createProgram(LearningProblemNew learningProblem, Concept mainTree) { return new Program(calculateFitness(learningProblem, mainTree), mainTree); } - private static Program createProgram(DefinitionLP learningProblem, Concept mainTree, Concept adc) { + private static Program createProgram(LearningProblemNew learningProblem, Concept mainTree, Concept adc) { return new Program(calculateFitness(learningProblem, mainTree,adc), mainTree, adc); } @@ -133,7 +135,7 @@ * Perform a point mutation on the given program. * @param p The program to be mutated. */ - public static Program mutation(DefinitionLP learningProblem, Program p) { + public static Program mutation(LearningProblemNew learningProblem, Program p) { mutation++; if(Config.GP.adc) { // TODO: hier kann man noch mehr Feinabstimmung machen, d.h. @@ -157,7 +159,7 @@ } } - private static Concept mutation(DefinitionLP learningProblem, Concept tree, boolean useADC) { + private static Concept mutation(LearningProblemNew learningProblem, Concept tree, boolean useADC) { // auch bei Mutation muss darauf geachtet werden, dass // Baum nicht modifiziert wird (sonst w�rde man automatisch auch // andere "selected individuals" modifizieren) @@ -226,7 +228,7 @@ * @param p2 Second parent. * @return A two-element array containing the offpsring. */ - public static Program[] crossover(DefinitionLP learningProblem, Program p1, Program p2) { + public static Program[] crossover(LearningProblemNew learningProblem, Program p1, Program p2) { crossover++; if(Config.GP.adc) { Concept[] pt; @@ -302,7 +304,7 @@ // m�sste auch mit ADC funktionieren, da nur am Hauptbaum etwas // ver�ndert wird - public static Program hillClimbing(DefinitionLP learningProblem, Program p) { + public static Program hillClimbing(LearningProblemNew learningProblem, Program p) { hillClimbing++; // checken, ob Bedingungen f�r hill-climbing erf�llt sind if(!learningProblem.getReasoningService().getReasonerType().equals(ReasonerType.FAST_RETRIEVAL) @@ -325,7 +327,7 @@ // Alternativen zu speichern und dann ein Element zuf�llig auszuw�hlen, // aber w�rde man das nicht machen, dann w�re das ein starker Bias // zu z.B. Disjunktion (weil die als erstes getestet wird) - private static Concept hillClimbing(DefinitionLP learningProblem, Concept node, ScoreThreeValued score) { + private static Concept hillClimbing(LearningProblemNew learningProblem, Concept node, ScoreThreeValued score) { SortedSetTuple<Individual> tuple = new SortedSetTuple<Individual>(score.getPosClassified(),score.getNegClassified()); SortedSetTuple<String> stringTuple = Helper.getStringTuple(tuple); // FlatABox abox = FlatABox.getInstance(); @@ -440,15 +442,15 @@ } } - private static ScoreThreeValued getScore(int conceptLength, DefinitionLP learningProblem, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { + private static ScoreThreeValued getScore(int conceptLength, LearningProblemNew learningProblem, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { // es muss hier die Helper-Methode verwendet werden, sonst werden // Individuals gel�scht !! SortedSet<Individual> neutClassified = Helper.intersection(learningProblem.getReasoningService().getIndividuals(),posClassified); // learningProblem.getReasoner().getIndividuals(); // neutClassified.retainAll(posClassified); neutClassified.retainAll(negClassified); - - return new ScoreThreeValued(conceptLength, posClassified, neutClassified, negClassified, learningProblem.getPositiveExamples(),((DefinitionLPThreeValued)learningProblem).getNeutralExamples(),learningProblem.getNegativeExamples()); + PosNegDefinitionLPStrict lp = (PosNegDefinitionLPStrict)learningProblem; + return new ScoreThreeValued(conceptLength, posClassified, neutClassified, negClassified, lp.getPositiveExamples(),lp.getNeutralExamples(),lp.getNegativeExamples()); } // aktualisiert die besten Knoten @@ -477,7 +479,7 @@ return returnMap; } - private static Concept pickTerminalSymbol(DefinitionLP learningProblem, boolean useADC) { + private static Concept pickTerminalSymbol(LearningProblemNew learningProblem, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int nr; int nrOfConcepts = learningProblem.getReasoningService().getAtomicConcepts().size(); @@ -607,7 +609,7 @@ * @param depth Depth of the tree. * @return The created program. */ - public static Program createFullRandomProgram(DefinitionLP learningProblem, int depth) { + public static Program createFullRandomProgram(LearningProblemNew learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, true), @@ -617,7 +619,7 @@ return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, false)); } - private static Concept createFullRandomTree(DefinitionLP learningProblem, int depth, boolean useADC) { + private static Concept createFullRandomTree(LearningProblemNew learningProblem, int depth, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int numberOfRoles = learningProblem.getReasoningService().getAtomicRoles().size(); // abox.roles.size(); @@ -668,7 +670,7 @@ * @param depth The maximum depth of the program tree. * @return The created program. */ - public static Program createGrowRandomProgram(DefinitionLP learningProblem, int depth) { + public static Program createGrowRandomProgram(LearningProblemNew learningProblem, int depth) { if(Config.GP.adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createGrowRandomTree(learningProblem,depth,true), @@ -678,7 +680,7 @@ return createProgram(learningProblem, createGrowRandomTree(learningProblem, depth,false)); } - private static Concept createGrowRandomTree(DefinitionLP learningProblem, int depth, boolean useADC) { + private static Concept createGrowRandomTree(LearningProblemNew learningProblem, int depth, boolean useADC) { /* private static Concept pickAlphabetSymbol(boolean useADC) { FlatABox abox = FlatABox.getInstance(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2007-10-03 09:53:38 UTC (rev 165) @@ -11,6 +11,7 @@ import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; @@ -18,7 +19,7 @@ PsiUp pu; PsiDown pd; - DefinitionLP learningProblem; + PosNegLP learningProblem; int nrOfPositiveExamples; int nrOfNegativeExamples; Random random; @@ -48,7 +49,7 @@ private long someTimeStart = 0; public long someTime = 0; - public Psi(DefinitionLP learningProblem) { //, PsiUp pu, PsiDown pd) { + public Psi(PosNegLP learningProblem) { //, PsiUp pu, PsiDown pd) { // this.pu = pu; // this.pd = pd; this.learningProblem = learningProblem; Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2007-10-03 09:53:38 UTC (rev 165) @@ -22,6 +22,7 @@ import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; /** @@ -40,12 +41,12 @@ ConceptComparator conceptComparator = new ConceptComparator(); - DefinitionLP learningProblem; + PosNegLP learningProblem; ReasoningService reasoningService; private TreeSet<Concept> topSet; - public PsiDown(DefinitionLP learningProblem) { + public PsiDown(PosNegLP learningProblem) { this.learningProblem = learningProblem; reasoningService = learningProblem.getReasoningService(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2007-10-03 09:53:38 UTC (rev 165) @@ -22,18 +22,19 @@ import org.dllearner.core.dl.Quantification; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.DefinitionLP; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.ConceptComparator; public class PsiUp implements RefinementOperator { ConceptComparator conceptComparator = new ConceptComparator(); - DefinitionLP learningProblem; + PosNegLP learningProblem; ReasoningService reasoningService; private TreeSet<Concept> bottomSet; - public PsiUp(DefinitionLP learningProblem) { + public PsiUp(PosNegLP learningProblem) { this.learningProblem = learningProblem; reasoningService = learningProblem.getReasoningService(); Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-03 09:53:38 UTC (rev 165) @@ -25,7 +25,7 @@ import org.dllearner.algorithms.RandomGuesser; import org.dllearner.kb.OWLFile; -import org.dllearner.learningproblems.DefinitionLPTwoValued; +import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.reasoning.DIGReasonerNew; /** @@ -57,7 +57,7 @@ rs.init(); // create a learning problem and set positive and negative examples - LearningProblemNew lp = cm.learningProblem(DefinitionLPTwoValued.class, rs); + LearningProblemNew lp = cm.learningProblem(PosNegDefinitionLP.class, rs); Set<String> positiveExamples = new TreeSet<String>(); positiveExamples.add("http://example.com/father#stefan"); positiveExamples.add("http://example.com/father#markus"); Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblemNew.java 2007-10-03 09:53:38 UTC (rev 165) @@ -19,8 +19,10 @@ */ package org.dllearner.core; +import org.dllearner.core.dl.Concept; + /** - * Marker interface for all learning problems (the "New" at the end of the name + * Base class for all learning problems (the "New" at the end of the name * is temporary for the restructuring process). * * @author Jens Lehmann @@ -34,4 +36,12 @@ this.reasoningService = reasoningService; } + public abstract Score computeScore(Concept concept); + + // TODO: remove? reasoning service should probably not be accessed via + // learning problem + public ReasoningService getReasoningService() { + return reasoningService; + } + } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -19,75 +19,12 @@ */ package org.dllearner.learningproblems; -import java.util.SortedSet; - -import org.dllearner.core.LearningProblemNew; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; - /** - * The definition learning problem. + * Marker interface for definition learning problems. * * @author Jens Lehmann * */ -public abstract class DefinitionLP extends LearningProblemNew { - - protected boolean useRetrievalForClassification = false; - protected UseMultiInstanceChecks useDIGMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; - - /** - * If instance checks are used for testing concepts (e.g. no retrieval), then - * there are several options to do this. The enumeration lists the supported - * options. These options are only important if the reasoning mechanism - * supports sending several reasoning requests at once as it is the case for - * DIG reasoners. - * - * @author Jens Lehmann - * - */ - public enum UseMultiInstanceChecks { - /** - * Perform a separate instance check for each example. - */ - NEVER, - /** - * Perform one instance check for all positive and one instance check - * for all negative examples. - */ - TWOCHECKS, - /** - * Perform all instance checks at once. - */ - ONECHECK - }; - - public DefinitionLP(ReasoningService reasoningService) { - super(reasoningService); - } - - public abstract int coveredNegativeExamplesOrTooWeak(Concept concept); - - public abstract Score computeScore(Concept concept); - - /** - * @todo Method not implemented yet. - * @param concept - * @param adc - * @return - */ - public Score computeScore(Concept concept, Concept adc) { - throw new UnsupportedOperationException(); - } - - public abstract SortedSet<Individual> getNegativeExamples(); - - public abstract SortedSet<Individual> getPositiveExamples(); - - // TODO: remove? reasoning service should probably not be accessed via - // learning problem - public abstract ReasoningService getReasoningService(); - +public interface DefinitionLP { + } Deleted: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java 2007-10-03 09:53:38 UTC (rev 165) @@ -1,114 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.learningproblems; - -import java.util.SortedSet; - -import org.dllearner.core.ConfigEntry; -import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; - -/** - * @author Jens Lehmann - * - */ -public class DefinitionLPThreeValued extends DefinitionLP { - - public DefinitionLPThreeValued(ReasoningService reasoningService) { - super(reasoningService); - } - - /* (non-Javadoc) - * @see org.dllearner.core.Component#getName() - */ - public static String getName() { - return "two valued definition learning problem"; - } - - /* (non-Javadoc) - * @see org.dllearner.core.Component#init() - */ - @Override - public void init() { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.dllearner.learningproblems.DefinitionLP#computeScore(org.dllearner.core.dl.Concept) - */ - @Override - public Score computeScore(Concept concept) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.dllearner.learningproblems.DefinitionLP#coveredNegativeExamplesOrTooWeak(org.dllearner.core.dl.Concept) - */ - @Override - public int coveredNegativeExamplesOrTooWeak(Concept concept) { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.dllearner.learningproblems.DefinitionLP#getNegativeExamples() - */ - @Override - public SortedSet<Individual> getNegativeExamples() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.dllearner.learningproblems.DefinitionLP#getPositiveExamples() - */ - @Override - public SortedSet<Individual> getPositiveExamples() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.dllearner.learningproblems.DefinitionLP#getReasoningService() - */ - @Override - public ReasoningService getReasoningService() { - // TODO Auto-generated method stub - return null; - } - - public SortedSet<Individual> getNeutralExamples() { - throw new UnsupportedOperationException(); - } -} Deleted: trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-10-03 07:46:54 UTC (rev 164) +++ trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java 2007-10-03 09:53:38 UTC (rev 165) @@ -1,274 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.learningproblems; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.BooleanConfigOption; -import org.dllearner.core.CommonConfigMappings; -import org.dllearner.core.ConfigEntry; -import org.dllearner.core.ConfigOption; -import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.StringSetConfigOption; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; -import org.dllearner.utilities.Helper; - -/** - * The aim of this learning problem is to learn a concept definition such that - * the positive examples and the negative examples do not follow. It is - * 2-valued, because we only distinguish between covered and non-covered - * examples. (A 3-valued problem distinguishes between covered examples, - * examples covered by the negation of the concept, and all other examples.) The - * 2-valued learning problem is often more useful for Description Logics due to - * (the Open World Assumption and) the fact that negative knowledge, e.g. that a - * person does not have a child, is or cannot be expressed. - * - * @author Jens Lehmann - * - */ -public class DefinitionLPTwoValued extends DefinitionLP { - - private SortedSet<Individual> positiveExamples; - private SortedSet<Individual> negativeExamples; - private SortedSet<Individual> posNegExamples; - - public DefinitionLPTwoValued(ReasoningService reasoningService) { - super(reasoningService); - } - - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringSetConfigOption("positiveExamples", - "positive examples")); - options.add(new StringSetConfigOption("negativeExamples", - "negative examples")); - options.add(new BooleanConfigOption("useRetrievalForClassficiation", - "Specifies whether to use retrieval or instance checks for testing a concept.")); - return options; - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings( { "unchecked" }) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); - if (name.equals("positiveExamples")) - positiveExamples = CommonConfigMappings - .getIndividualSet((Set<String>) entry.getValue()); - else if (name.equals("negativeExamples")) - negativeExamples = CommonConfigMappings - .getIndividualSet((Set<String>) entry.getValue()); - else if (name.equals("useRetrievalForClassification")) - useRetrievalForClassification = (Boolean) entry.getValue(); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Component#getName() - */ - public static String getName() { - return "two valued definition learning problem"; - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Component#init() - */ - @Override - public void init() { - posNegExamples = Helper.union(positiveExamples, negativeExamples); - } - - /** - * This method computes (using the reasoner) whether a concept is too weak. - * If it is not weak, it returns the number of covered negative example. It - * can use retrieval or instance checks for classification. - * - * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks - * @todo Performance could be slightly improved by counting the number of - * covers instead of using sets and counting their size. - * @param concept - * The concept to test. - * @return -1 if concept is too weak and the number of covered negative - * examples otherwise. - */ - @Override - public int coveredNegativeExamplesOrTooWeak(Concept concept) { - - if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - - // the set is constructed piecewise to avoid expensive set - // operations - // on a large number of individuals - for (Individual posExample : positiveExamples) { - if (!posClassified.contains(posExample)) - posAsNeg.add(posExample); - } - - // too weak - if (posAsNeg.size() > 0) - return -1; - // number of covered negatives - else - return negAsPos.size(); - } else { - if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { - // two checks - if (useDIGMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { - Set<Individual> s = reasoningService.instanceCheck(concept, positiveExamples); - // if the concept is too weak, then do not query negative - // examples - if (s.size() != positiveExamples.size()) - return -1; - else { - s = reasoningService.instanceCheck(concept, negativeExamples); - return s.size(); - } - // one check - } else { - Set<Individual> s = reasoningService.instanceCheck(concept, posNegExamples); - // test whether all positive examples are covered - if (s.containsAll(positiveExamples)) - return s.size() - positiveExamples.size(); - else - return -1; - } - } else { - // SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - - for (Individual example : positiveExamples) { - if (!reasoningService.instanceCheck(concept, example)) - return -1; - // posAsNeg.add(example); - } - for (Individual example : negativeExamples) { - if (reasoningService.instanceCheck(concept, example)) - negAsPos.add(example); - } - - return negAsPos.size(); - } - } - } - - /** - * Computes score of a given concept using the reasoner. Either retrieval or - * instance check are used. For the latter, this method treats - * <code>UseMultiInstanceChecks.TWO_CHECKS</code> as if it were - * <code>UseMultiInstanceChecks.ONE_CHECKS</code> (it does not make much sense - * to implement TWO_CHECKS in this function, because we have to test all - * examples to create a score object anyway). - * - * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks - * @param concept - * The concept to test. - * @return Corresponding Score object. - */ - @Override - public Score computeScore(Concept concept) { - if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoningService.retrieval(concept); - SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - - // piecewise set construction - for (Individual posExample : positiveExamples) { - if (!posClassified.contains(posExample)) - posAsNeg.add(posExample); - } - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - for (Individual negExample : negativeExamples) { - if (!posClassified.contains(negExample)) - negAsNeg.add(negExample); - } - return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, negAsNeg); - // instance checks for classification - } else { - SortedSet<Individual> posAsPos = new TreeSet<Individual>(); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - - if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { - SortedSet<Individual> posClassified = reasoningService.instanceCheck(concept, - posNegExamples); - SortedSet<Individual> negClassified = Helper.difference(posNegExamples, - posClassified); - posAsPos = Helper.intersection(positiveExamples, posClassified); - posAsNeg = Helper.intersection(positiveExamples, negClassified); - negAsPos = Helper.intersection(negativeExamples, posClassified); - negAsNeg = Helper.intersection(negativeExamples, negClassified); - return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, - negAsNeg); - } else { - - for (Individual example : positiveExamples) { - if (reasoningService.instanceCheck(concept, example)) - posAsPos.add(example); - else - posAsNeg.add(example); - } - for (Individual example : negativeExamples) { - if (reasoningService.instanceCheck(concept, example)) - negAsPos.add(example); - else - negAsNeg.add(example); - } - return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, - negAsNeg); - } - } - } - - @Override - public SortedSet<Individual> getNegativeExamples() { - return negativeExamples; - } - - @Override - public SortedSet<Individual> getPositiveExamples() { - return positiveExamples; - } - - // TODO: remove? reasoning service should probably not be accessed via - // learning problem - @Override - public ReasoningService getReasoningService() { - return reasoningService; - } -} Added: trunk/src/dl-learner/org/dllearner/learningproblems/InclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/InclusionLP.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/InclusionLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +/** + * Marker interface for inclusion learning problems. + * + * @author Jens Lehmann + * + */ +public interface InclusionLP { + +} Copied: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java (from rev 162, trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPTwoValued.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,230 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.BooleanConfigOption; +import org.dllearner.core.CommonConfigMappings; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; +import org.dllearner.core.StringSetConfigOption; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.utilities.Helper; + +/** + * The aim of this learning problem is to learn a concept definition such that + * the positive examples and the negative examples do not follow. It is + * 2-valued, because we only distinguish between covered and non-covered + * examples. (A 3-valued problem distinguishes between covered examples, + * examples covered by the negation of the concept, and all other examples.) The + * 2-valued learning problem is often more useful for Description Logics due to + * (the Open World Assumption and) the fact that negative knowledge, e.g. that a + * person does not have a child, is or cannot be expressed. + * + * @author Jens Lehmann + * + */ +public class PosNegDefinitionLP extends PosNegLP implements DefinitionLP { + + public PosNegDefinitionLP(ReasoningService reasoningService) { + super(reasoningService); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#getName() + */ + public static String getName() { + return "two valued definition learning problem"; + } + + /** + * This method computes (using the reasoner) whether a concept is too weak. + * If it is not weak, it returns the number of covered negative example. It + * can use retrieval or instance checks for classification. + * + * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks + * @todo Performance could be slightly improved by counting the number of + * covers instead of using sets and counting their size. + * @param concept + * The concept to test. + * @return -1 if concept is too weak and the number of covered negative + * examples otherwise. + */ + @Override + public int coveredNegativeExamplesOrTooWeak(Concept concept) { + + if (useRetrievalForClassification) { + SortedSet<Individual> posClassified = reasoningService.retrieval(concept); + SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); + + // the set is constructed piecewise to avoid expensive set + // operations + // on a large number of individuals + for (Individual posExample : positiveExamples) { + if (!posClassified.contains(posExample)) + posAsNeg.add(posExample); + } + + // too weak + if (posAsNeg.size() > 0) + return -1; + // number of covered negatives + else + return negAsPos.size(); + } else { + if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + // two checks + if (useDIGMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { + Set<Individual> s = reasoningService.instanceCheck(concept, positiveExamples); + // if the concept is too weak, then do not query negative + // examples + if (s.size() != positiveExamples.size()) + return -1; + else { + s = reasoningService.instanceCheck(concept, negativeExamples); + return s.size(); + } + // one check + } else { + Set<Individual> s = reasoningService.instanceCheck(concept, allExamples); + // test whether all positive examples are covered + if (s.containsAll(positiveExamples)) + return s.size() - positiveExamples.size(); + else + return -1; + } + } else { + // SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); + SortedSet<Individual> negAsPos = new TreeSet<Individual>(); + + for (Individual example : positiveExamples) { + if (!reasoningService.instanceCheck(concept, example)) + return -1; + // posAsNeg.add(example); + } + for (Individual example : negativeExamples) { + if (reasoningService.instanceCheck(concept, example)) + negAsPos.add(example); + } + + return negAsPos.size(); + } + } + } + + /** + * Computes score of a given concept using the reasoner. Either retrieval or + * instance check are used. For the latter, this method treats + * <code>UseMultiInstanceChecks.TWO_CHECKS</code> as if it were + * <code>UseMultiInstanceChecks.ONE_CHECKS</code> (it does not make much sense + * to implement TWO_CHECKS in this function, because we have to test all + * examples to create a score object anyway). + * + * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks + * @param concept + * The concept to test. + * @return Corresponding Score object. + */ + @Override + public Score computeScore(Concept concept) { + if (useRetrievalForClassification) { + SortedSet<Individual> posClassified = reasoningService.retrieval(concept); + SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); + SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); + + // piecewise set construction + for (Individual posExample : positiveExamples) { + if (!posClassified.contains(posExample)) + posAsNeg.add(posExample); + } + SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); + for (Individual negExample : negativeExamples) { + if (!posClassified.contains(negExample)) + negAsNeg.add(negExample); + } + return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, negAsNeg); + // instance checks for classification + } else { + SortedSet<Individual> posAsPos = new TreeSet<Individual>(); + SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); + SortedSet<Individual> negAsPos = new TreeSet<Individual>(); + SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); + + if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + SortedSet<Individual> posClassified = reasoningService.instanceCheck(concept, + allExamples); + SortedSet<Individual> negClassified = Helper.difference(allExamples, + posClassified); + posAsPos = Helper.intersection(positiveExamples, posClassified); + posAsNeg = Helper.intersection(positiveExamples, negClassified); + negAsPos = Helper.intersection(negativeExamples, posClassified); + negAsNeg = Helper.intersection(negativeExamples, negClassified); + return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, + negAsNeg); + } else { + + for (Individual example : positiveExamples) { + if (reasoningService.instanceCheck(concept, example)) + posAsPos.add(example); + else + posAsNeg.add(example); + } + for (Individual example : negativeExamples) { + if (reasoningService.instanceCheck(concept, example)) + negAsPos.add(example); + else + negAsNeg.add(example); + } + return new ScoreTwoValued(concept.getLength(), posAsPos, posAsNeg, negAsPos, + negAsNeg); + } + } + } + + @Override + public SortedSet<Individual> getNegativeExamples() { + return negativeExamples; + } + + @Override + public SortedSet<Individual> getPositiveExamples() { + return positiveExamples; + } + + // TODO: remove? reasoning service should probably not be accessed via + // learning problem + @Override + public ReasoningService getReasoningService() { + return reasoningService; + } +} Copied: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java (from rev 162, trunk/src/dl-learner/org/dllearner/learningproblems/DefinitionLPThreeValued.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,114 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +import java.util.SortedSet; + +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; + +/** + * @author Jens Lehmann + * + */ +public class PosNegDefinitionLPStrict extends PosNegLP implements DefinitionLP { + + public PosNegDefinitionLPStrict(ReasoningService reasoningService) { + super(reasoningService); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#getName() + */ + public static String getName() { + return "three valued definition learning problem"; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#computeScore(org.dllearner.core.dl.Concept) + */ + @Override + public Score computeScore(Concept concept) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#coveredNegativeExamplesOrTooWeak(org.dllearner.core.dl.Concept) + */ + @Override + public int coveredNegativeExamplesOrTooWeak(Concept concept) { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#getNegativeExamples() + */ + @Override + public SortedSet<Individual> getNegativeExamples() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#getPositiveExamples() + */ + @Override + public SortedSet<Individual> getPositiveExamples() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.DefinitionLP#getReasoningService() + */ + @Override + public ReasoningService getReasoningService() { + // TODO Auto-generated method stub + return null; + } + + public SortedSet<Individual> getNeutralExamples() { + throw new UnsupportedOperationException(); + } +} Added: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,119 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.Set; +import java.util.SortedSet; + +import org.dllearner.core.BooleanConfigOption; +import org.dllearner.core.CommonConfigMappings; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; +import org.dllearner.core.StringSetConfigOption; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; + +/** + * @author Jens Lehmann + * + */ +public class PosNegInclusionLP extends PosNegLP implements InclusionLP { + + private SortedSet<Individual> positiveExamples; + private SortedSet<Individual> negativeExamples; + private SortedSet<Individual> posNegExamples; + + public PosNegInclusionLP(ReasoningService reasoningService) { + super(reasoningService); + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringSetConfigOption("positiveExamples", + "positive examples")); + options.add(new StringSetConfigOption("negativeExamples", + "negative examples")); + options.add(new BooleanConfigOption("useRetrievalForClassficiation", + "Specifies whether to use retrieval or instance checks for testing a concept.")); + return options; + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + @SuppressWarnings( { "unchecked" }) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String name = entry.getOptionName(); + if (name.equals("positiveExamples")) + positiveExamples = CommonConfigMappings + .getIndividualSet((Set<String>) entry.getValue()); + else if (name.equals("negativeExamples")) + negativeExamples = CommonConfigMappings + .getIndividualSet((Set<String>) entry.getValue()); + else if (name.equals("useRetrievalForClassification")) + useRetrievalForClassification = (Boolean) entry.getValue(); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#getName() + */ + public static String getName() { + return "two valued definition learning problem"; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.learningproblems.PosNegLP#coveredNegativeExamplesOrTooWeak(org.dllearner.core.dl.Concept) + */ + @Override + public int coveredNegativeExamplesOrTooWeak(Concept concept) { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.dllearner.core.LearningProblemNew#computeScore(org.dllearner.core.dl.Concept) + */ + @Override + public Score computeScore(Concept concept) { + // TODO Auto-generated method stub + return null; + } + +} Added: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2007-10-03 09:53:38 UTC (rev 165) @@ -0,0 +1,132 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.learningproblems; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.Set; +import java.util.SortedSet; + +import org.dllearner.core.BooleanConfigOption; +import org.dllearner.core.CommonConfigMappings; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.LearningProblemNew; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.StringSetConfigOption; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.utilities.Helper; + +/** + * @author Jens Lehmann + * + */ +public abstract class PosNegLP extends LearningProblemNew { + + protected SortedSet<Individual> positiveExamples; + protected SortedSet<Individual> negativeExamples; + protected SortedSet<Individual> allExamples; + + protected boolean useRetrievalForClassification = false; + protected UseMultiInstanceChecks useDIGMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; + + /** + * If instance checks are used for testing concepts (e.g. no retrieval), then + * there are several options to do this. The enumeration lists the supported + * options. These options are only important if the reasoning mechanism + * supports sending several reasoning requests at once as it is the case for + * DIG reasoners. + * + * @author Jens Lehmann + * + */ + public enum UseMultiInstanceChecks { + /** + * Perform a separate instance check for each example. + */ + NEVER, + /** + * Perform one instance check for all positive and one instance check + * for all negative examples. + */ + TWOCHECKS, + /** + * Perform all instance checks at once. + */ + ONECHECK + }; + + public PosNegLP(ReasoningService reasoningService) { + super(reasoningService); + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringSetConfigOption("positiveExamples", + "positive examples")); + options.add(new StringSetConfigOption("negativeExamples", + "negative examples")); + options.add(new BooleanConfigOption("useRetrievalForClassficiation", + "Specifies whether to use retrieval or instance checks for testing a concept.")); + return options; + } + + /* + * (non-Javadoc) + * + * @see org.dlle... [truncated message content] |
From: <jen...@us...> - 2007-10-03 14:54:52
|
Revision: 167 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=167&view=rev Author: jenslehmann Date: 2007-10-03 07:54:46 -0700 (Wed, 03 Oct 2007) Log Message: ----------- command line interface started Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/Main.java trunk/src/dl-learner/org/dllearner/cli/QuickStart.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java trunk/src/dl-learner/org/dllearner/modules/ModuleInvocator.java trunk/src/dl-learner/org/dllearner/modules/PreprocessingModule.java trunk/src/dl-learner/org/dllearner/modules/TestModule.java trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java trunk/src/dl-learner/org/dllearner/parser/ConfParser.java trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java trunk/src/dl-learner/org/dllearner/parser/conf.jj trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/ConfigurationOption.java Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-03 14:54:46 UTC (rev 167) @@ -15,6 +15,7 @@ import org.dllearner.Config.Algorithm; import org.dllearner.algorithms.gp.GP.AlgorithmType; import org.dllearner.algorithms.gp.GP.SelectionType; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.learningproblems.ScoreThreeValued.ScoreMethod; @@ -44,7 +45,7 @@ */ public class ConfigurationManager { - private Collection<ConfigurationOption> options; + private Collection<ConfFileOption> options; // verfuegbare Optionen // Problemfall: double-Optionen, die auch int-Optionen sein können; @@ -56,10 +57,10 @@ private List<String> setOptions; public ConfigurationManager() { - this(new LinkedList<ConfigurationOption>()); + this(new LinkedList<ConfFileOption>()); } - public ConfigurationManager(Collection<ConfigurationOption> confOptions) { + public ConfigurationManager(Collection<ConfFileOption> confOptions) { // options = new HashSet<ConfigurationOption>(); options = confOptions; strOptions = new HashMap<String, String[]>(); @@ -73,7 +74,7 @@ } public void applyOptions() { - for(ConfigurationOption option : options) { + for(ConfFileOption option : options) { // System.out.println(option); applyConfigurationOption(option); } @@ -101,7 +102,7 @@ // TODO: bei Fehlerbehandlungen müsste man jetzt noch berücksichtigen, dass // Mengen als 4. Optionstyp (neben int, double, string) dazugekommen sind - public void applyConfigurationOption(ConfigurationOption option) { + public void applyConfigurationOption(ConfFileOption option) { String optionString; if(option.containsSubOption()) optionString = option.getOption() + "." + option.getSubOption(); Deleted: trunk/src/dl-learner/org/dllearner/ConfigurationOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationOption.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/ConfigurationOption.java 2007-10-03 14:54:46 UTC (rev 167) @@ -1,129 +0,0 @@ -package org.dllearner; - -import java.util.Set; - -/** - * Repraesentiert eine Konfigurationsoption. Es werden verschiedene Optionen angeboten. - * - * @author jl - * - */ -public class ConfigurationOption { - - private boolean containsSubOption = true; - private boolean isIntegerOption = false; - private boolean isNumeric = false; - private boolean isSetOption = false; - private String option; - private String subOption; - private String strValue; - private int intValue; - private double doubleValue; - private Set<String> setValues; - - public ConfigurationOption(String option, String value) { - this(option, null, value); - containsSubOption = false; - } - - public ConfigurationOption(String option, String subOption, String value) { - this.option = option; - this.subOption = subOption; - strValue = value; - } - - public ConfigurationOption(String option, int value) { - this(option, null, value); - containsSubOption = false; - } - - public ConfigurationOption(String option, String subOption, int value) { - this.option = option; - this.subOption = subOption; - intValue = value; - isIntegerOption = true; - isNumeric = true; - } - - public ConfigurationOption(String option, double value) { - this(option, null, value); - containsSubOption = false; - } - - public ConfigurationOption(String option, String subOption, double value) { - this.option = option; - this.subOption = subOption; - doubleValue = value; - // isIntegerOption = false; - isNumeric = true; - } - - public ConfigurationOption(String option, Set<String> values) { - this(option, null, values); - containsSubOption = false; - } - - public ConfigurationOption(String option, String subOption, Set<String> values) { - this.option = option; - this.subOption = subOption; - isSetOption = true; - setValues = values; - } - - public boolean containsSubOption() { - return containsSubOption; - } - - public int getIntValue() { - return intValue; - } - - public boolean isIntegerOption() { - return isIntegerOption; - } - - public String getOption() { - return option; - } - - public String getStrValue() { - return strValue; - } - - public String getSubOption() { - return subOption; - } - - public double getDoubleValue() { - return doubleValue; - } - - public boolean isNumeric() { - return isNumeric; - } - - public boolean isSetOption() { - return isSetOption; - } - - @Override - public String toString() { - String completeOption = "Configuration Option: "; - if(containsSubOption) - completeOption += option + "." + subOption; - else - completeOption += option; - if(isNumeric) - if(isIntegerOption) - return completeOption + "=" + intValue; - else - return completeOption + "=" + doubleValue; - else - return completeOption + "=" + strValue; - } - - public Set<String> getSetValues() { - return setValues; - } - -} Modified: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-03 14:54:46 UTC (rev 167) @@ -43,6 +43,7 @@ import org.dllearner.algorithms.LearningAlgorithm; import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.ComponentManager; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblem; @@ -117,7 +118,7 @@ // neuer Hauptkonstruktor public Main(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, List<List<String>> functionCalls, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { this.kb = kb; Added: trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java 2007-10-03 14:54:46 UTC (rev 167) @@ -0,0 +1,157 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +package org.dllearner.cli; + +import java.util.Set; + +/** + * Represents one configuration option in a conf file, e.g. + * refinement.horizontalExpansionFactor = 0.6. + * + * @author Jens Lehmann + * + */ +public class ConfFileOption { + + private boolean containsSubOption = true; + private boolean isIntegerOption = false; + private boolean isNumeric = false; + private boolean isSetOption = false; + private String option; + private String subOption; + private String strValue; + private int intValue; + private double doubleValue; + private Set<String> setValues; + + public ConfFileOption(String option, String value) { + this(option, null, value); + containsSubOption = false; + } + + public ConfFileOption(String option, String subOption, String value) { + this.option = option; + this.subOption = subOption; + strValue = value; + } + + public ConfFileOption(String option, int value) { + this(option, null, value); + containsSubOption = false; + } + + public ConfFileOption(String option, String subOption, int value) { + this.option = option; + this.subOption = subOption; + intValue = value; + isIntegerOption = true; + isNumeric = true; + } + + public ConfFileOption(String option, double value) { + this(option, null, value); + containsSubOption = false; + } + + public ConfFileOption(String option, String subOption, double value) { + this.option = option; + this.subOption = subOption; + doubleValue = value; + // isIntegerOption = false; + isNumeric = true; + } + + public ConfFileOption(String option, Set<String> values) { + this(option, null, values); + containsSubOption = false; + } + + public ConfFileOption(String option, String subOption, Set<String> values) { + this.option = option; + this.subOption = subOption; + isSetOption = true; + setValues = values; + } + + public boolean containsSubOption() { + return containsSubOption; + } + + public int getIntValue() { + return intValue; + } + + public boolean isIntegerOption() { + return isIntegerOption; + } + + public String getOption() { + return option; + } + + public String getStrValue() { + return strValue; + } + + public String getSubOption() { + return subOption; + } + + public double getDoubleValue() { + return doubleValue; + } + + public boolean isNumeric() { + return isNumeric; + } + + public boolean isSetOption() { + return isSetOption; + } + + @Override + public String toString() { + String completeOption = "Configuration Option: "; + if(containsSubOption) + completeOption += option + "." + subOption; + else + completeOption += option; + if(isNumeric) + if(isIntegerOption) + return completeOption + "=" + intValue; + else + return completeOption + "=" + doubleValue; + else + return completeOption + "=" + strValue; + } + + public Set<String> getSetValues() { + return setValues; + } + + public String getFullName() { + if(containsSubOption) + return option + "." + subOption; + else + return option; + } + +} Modified: trunk/src/dl-learner/org/dllearner/cli/QuickStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2007-10-03 14:54:46 UTC (rev 167) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.cli; import java.io.BufferedReader; Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-03 14:54:46 UTC (rev 167) @@ -20,7 +20,25 @@ package org.dllearner.cli; import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.kb.KBFile; +import org.dllearner.kb.OWLFile; +import org.dllearner.kb.OntologyFileFormat; +import org.dllearner.kb.SparqlEndpoint; +import org.dllearner.parser.ConfParser; + /** * Startup file for Command Line Interface. * @@ -34,10 +52,96 @@ */ public static void main(String[] args) { File file = new File(args[args.length-1]); + String baseDir = file.getParentFile().getPath(); + // create component manager instance + ComponentManager cm = ComponentManager.getInstance(); + // parse conf file + ConfParser parser = ConfParser.parseFile(file); +// try { + + // step 1: detect knowledge sources + Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); + Map<URL, Class<? extends KnowledgeSource>> importedFiles = getImportedFiles(parser, baseDir); + for(Map.Entry<URL, Class<? extends KnowledgeSource>> entry : importedFiles.entrySet()) { + KnowledgeSource ks = cm.knowledgeSource(entry.getValue()); + // ConfigOption<?> urlOption = cm.getConfigOption(entry.getValue(), "url"); + // cm.applyConfigEntry(ks, new ConfigEntry<String>(urlOption, entry.getValue())); + cm.applyConfigEntry(ks, "url", entry.getKey().toString()); + + // TODO: SPARQL-specific settings + + // ks.applyConfigEntry(new ConfigEntry) + + } + // use parsed values to configure components + +// } catch (InvalidConfigOptionValueException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } } + private static Map<URL, Class<? extends KnowledgeSource>> getImportedFiles(ConfParser parser, String baseDir) { + List<List<String>> imports = parser.getFunctionCalls().get("import"); + Map<URL, Class<? extends KnowledgeSource>> importedFiles = new HashMap<URL, Class<? extends KnowledgeSource>>(); + + for(List<String> arguments : imports) { + // step 1: detect URL + URL url = null; + try { + String fileString = arguments.get(0); + if(fileString.startsWith("http:")) { + url = new URL(fileString); + } else { + File f = new File(baseDir, arguments.get(0)); + url = f.toURI().toURL(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + // step 2: detect format + Class<? extends KnowledgeSource> ksClass; + if (arguments.size() == 1) { + String filename = url.getPath(); + String ending = filename.substring(filename.lastIndexOf(".")); + + if(ending.equals("rdf") || ending.equals("owl")) + ksClass = OWLFile.class; + else if(ending.equals("nt")) + ksClass = OWLFile.class; + else if(ending.equals("kb")) + ksClass = KBFile.class; + else { + System.err.println("Warning: no format fiven for " + arguments.get(0) + " and could not detect it. Chosing RDF/XML."); + ksClass = OWLFile.class; + } + + importedFiles.put(url, ksClass); + } else { + String formatString = arguments.get(1); + + if (formatString.equals("RDF/XML")) + ksClass = OWLFile.class; + else if(formatString.equals("KB")) + ksClass = KBFile.class; + else if(formatString.equals("SPARQL")) + ksClass = SparqlEndpoint.class; + else if(formatString.equals("NT")) + ksClass = OWLFile.class; + else { + throw new RuntimeException("Unsupported knowledge source format " + formatString + ". Exiting."); + } + + importedFiles.put(url, ksClass); + } + } + + return importedFiles; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-03 14:54:46 UTC (rev 167) @@ -398,5 +398,9 @@ return null; } + + public ConfigOption<?> getConfigOption(Class<? extends Component> component, String name) { + return componentOptionsByName.get(component).get(name); + } } Modified: trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/kb/OntologyFileFormat.java 2007-10-03 14:54:46 UTC (rev 167) @@ -2,10 +2,19 @@ public enum OntologyFileFormat { - // RDF-Triples in XML file + /** + * RDF-Triples in XML file + */ RDF_XML, - // N-Triple format (subformat of N3) - N_TRIPLES + /** + * N-Triple format (subformat of N3) + */ + N_TRIPLES, + /** + * internal KB format + */ + KB, + } Modified: trunk/src/dl-learner/org/dllearner/modules/ModuleInvocator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/ModuleInvocator.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/ModuleInvocator.java 2007-10-03 14:54:46 UTC (rev 167) @@ -6,7 +6,7 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -24,7 +24,7 @@ @SuppressWarnings({"unchecked"}) public void invokePreprocessingModule(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, List<List<String>> functionCalls, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { try { // Config.preprocessingModule = "org.dllearner.algorithms.gp.GP"; Modified: trunk/src/dl-learner/org/dllearner/modules/PreprocessingModule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/PreprocessingModule.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/PreprocessingModule.java 2007-10-03 14:54:46 UTC (rev 167) @@ -4,7 +4,7 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -13,7 +13,7 @@ public void preprocess(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, List<List<String>> functionCalls, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode); public String getModuleName(); Modified: trunk/src/dl-learner/org/dllearner/modules/TestModule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/TestModule.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/TestModule.java 2007-10-03 14:54:46 UTC (rev 167) @@ -4,8 +4,8 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; import org.dllearner.Main; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -15,7 +15,7 @@ public void preprocess(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, List<List<String>> functionCalls, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { Main.getConfMgr().addStringOption("bla", new String[] {"test"}); Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-10-03 14:54:46 UTC (rev 167) @@ -29,7 +29,7 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -70,7 +70,7 @@ public void preprocess(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-10-03 14:54:46 UTC (rev 167) @@ -28,8 +28,8 @@ import java.util.Set; import java.util.SortedSet; -import org.dllearner.ConfigurationOption; import org.dllearner.Main; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; @@ -69,7 +69,7 @@ public void preprocess(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfigurationOption> confOptions, + List<ConfFileOption> confOptions, List<List<String>> functionCalls, String baseDir, boolean useQueryMode) { Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParser.java 2007-10-03 14:54:46 UTC (rev 167) @@ -1,6 +1,7 @@ /* Generated By:JavaCC: Do not edit this line. ConfParser.java */ package org.dllearner.parser; +import java.util.HashMap; import java.util.List; import java.util.LinkedList; import java.util.Map; @@ -20,36 +21,40 @@ import org.dllearner.Info; import org.dllearner.core.dl.*; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.*; import org.dllearner.utilities.*; public @SuppressWarnings("all") class ConfParser implements ConfParserConstants { + // examples private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); - // Konfigurationsoptionen - private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + // conf file options + private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); + private Map<String,ConfFileOption> confOptionsByName = new HashMap<String,ConfFileOption>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe // werden in einer Liste gespeichert - private List<List<String>> functionCalls = new LinkedList<List<String>>(); + // private List<List<String>> functionCalls = new LinkedList<List<String>>(); // => irgendwie Funktionsname + Argumente speichern // => d.h. man bräuchte für jede Funktion so eine Liste oder das erste Element // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante - // speichert, ob der Parser-Konstruktor aufgerufen wurde: momemtan handelt es - // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal - // aufgerufen werden; weitere Parsevorgänge erfolgen dann mit ReInit - // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser - // private static boolean constructorCalled = false; + private Map<String,List<List<String>>> functionCalls = new HashMap<String,List<List<String>>>(); - // Wissensbasis - // private KB kb = new KB(); - // public static final String internalNamespace = "http://localhost/foo#"; + private void addFunctionCall(String name, List<String> arguments) { + if(functionCalls.containsKey(name)) + functionCalls.get(name).add(arguments); + else { + List<List<String>> calls = new LinkedList<List<String>>(); + calls.add(arguments); + functionCalls.put(name,calls); + } + } public SortedSet<Individual> getPositiveExamples() { return positiveExamples; @@ -59,11 +64,15 @@ return negativeExamples; } - public List<ConfigurationOption> getConfOptions() { + public List<ConfFileOption> getConfOptions() { return confOptions; } - public List<List<String>> getFunctionCalls() { + public Map<String,ConfFileOption> getConfOptionsByName() { + return confOptionsByName; + } + + public Map<String,List<List<String>>> getFunctionCalls() { return functionCalls; } @@ -89,7 +98,7 @@ } */ - public static ConfParser parseFile(String filename) { + public static ConfParser parseFile(File filename) { ConfParser learner = null; try { learner = new ConfParser(new FileInputStream(filename)); @@ -174,7 +183,7 @@ RBoxAxiom rBoxAxiom; Equality equality; Inclusion inclusion; - ConfigurationOption confOption; + ConfFileOption confOption; label_1: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -189,7 +198,7 @@ } if (jj_2_1(2147483647)) { confOption = ConfOption(); - confOptions.add(confOption); + confOptions.add(confOption); confOptionsByName.put(confOption.getFullName(), confOption); } else if (jj_2_2(2147483647)) { FunctionCall(); } else if (jj_2_3(2147483647)) { @@ -204,12 +213,12 @@ jj_consume_token(0); } - final public ConfigurationOption ConfOption() throws ParseException { + final public ConfFileOption ConfOption() throws ParseException { boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false; String option="", subOption="", value="", tmp=""; int number = 0; double numberDouble = 0; - ConfigurationOption confOption; + ConfFileOption confOption; Set<String> values = new HashSet<String>(); option = Id(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -297,25 +306,25 @@ if(containsSubOption) { if(isNumeric) if(isDouble) - confOption = new ConfigurationOption(option,subOption,numberDouble); + confOption = new ConfFileOption(option,subOption,numberDouble); else - confOption = new ConfigurationOption(option,subOption,number); + confOption = new ConfFileOption(option,subOption,number); else if(isSet) - confOption = new ConfigurationOption(option,subOption,values); + confOption = new ConfFileOption(option,subOption,values); else - confOption = new ConfigurationOption(option,subOption,value); + confOption = new ConfFileOption(option,subOption,value); } else { if(isNumeric) if(isDouble) - confOption = new ConfigurationOption(option,numberDouble); + confOption = new ConfFileOption(option,numberDouble); else - confOption = new ConfigurationOption(option,number); + confOption = new ConfFileOption(option,number); else if(isSet) - confOption = new ConfigurationOption(option,values); + confOption = new ConfFileOption(option,values); else - confOption = new ConfigurationOption(option,value); + confOption = new ConfFileOption(option,value); } {if (true) return confOption;} // confOptions.add(confOption); @@ -329,7 +338,7 @@ s1 = Id(); jj_consume_token(29); s2 = String(); - list.add(s1); list.add(s2); + list.add(s2); label_3: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -346,7 +355,7 @@ } jj_consume_token(30); jj_consume_token(CONF_END); - functionCalls.add(list); + addFunctionCall(s1,list); } final public void PosExample() throws ParseException { @@ -455,6 +464,96 @@ finally { jj_save(5, xla); } } + final private boolean jj_3R_8() { + if (jj_3R_17()) return true; + return false; + } + + final private boolean jj_3R_10() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3R_19() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_17() { + if (jj_scan_token(DOUBLE)) return true; + return false; + } + + final private boolean jj_3R_14() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_7() { + if (jj_3R_16()) return true; + return false; + } + + final private boolean jj_3R_4() { + if (jj_scan_token(ID)) return true; + return false; + } + + final private boolean jj_3R_6() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3R_22() { + if (jj_3R_4()) return true; + return false; + } + + final private boolean jj_3R_13() { + if (jj_scan_token(28)) return true; + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3_6() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + final private boolean jj_3_5() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_14()) { + jj_scanpos = xsp; + if (jj_3R_15()) return true; + } + if (jj_scan_token(28)) return true; + return false; + } + + final private boolean jj_3R_12() { + if (jj_scan_token(STRING)) return true; + return false; + } + + final private boolean jj_3R_21() { + if (jj_3R_12()) return true; + return false; + } + + final private boolean jj_3R_18() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_21()) { + jj_scanpos = xsp; + if (jj_3R_22()) return true; + } + if (jj_scan_token(28)) return true; + return false; + } + final private boolean jj_3R_9() { if (jj_3R_12()) return true; return false; @@ -548,96 +647,6 @@ return false; } - final private boolean jj_3R_8() { - if (jj_3R_17()) return true; - return false; - } - - final private boolean jj_3R_10() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; - return false; - } - - final private boolean jj_3R_19() { - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3R_17() { - if (jj_scan_token(DOUBLE)) return true; - return false; - } - - final private boolean jj_3R_14() { - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3R_7() { - if (jj_3R_16()) return true; - return false; - } - - final private boolean jj_3R_4() { - if (jj_scan_token(ID)) return true; - return false; - } - - final private boolean jj_3R_6() { - if (jj_3R_4()) return true; - return false; - } - - final private boolean jj_3R_22() { - if (jj_3R_4()) return true; - return false; - } - - final private boolean jj_3R_13() { - if (jj_scan_token(28)) return true; - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3_6() { - if (jj_scan_token(26)) return true; - if (jj_scan_token(27)) return true; - return false; - } - - final private boolean jj_3_5() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_14()) { - jj_scanpos = xsp; - if (jj_3R_15()) return true; - } - if (jj_scan_token(28)) return true; - return false; - } - - final private boolean jj_3R_12() { - if (jj_scan_token(STRING)) return true; - return false; - } - - final private boolean jj_3R_21() { - if (jj_3R_12()) return true; - return false; - } - - final private boolean jj_3R_18() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_21()) { - jj_scanpos = xsp; - if (jj_3R_22()) return true; - } - if (jj_scan_token(28)) return true; - return false; - } - public ConfParserTokenManager token_source; SimpleCharStream jj_input_stream; public Token token, jj_nt; Modified: trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java 2007-10-03 14:54:46 UTC (rev 167) @@ -1,5 +1,6 @@ /* Generated By:JavaCC: Do not edit this line. ConfParserTokenManager.java */ package org.dllearner.parser; +import java.util.HashMap; import java.util.List; import java.util.LinkedList; import java.util.Map; @@ -16,7 +17,7 @@ import org.dllearner.Main; import org.dllearner.Info; import org.dllearner.core.dl.*; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.*; import org.dllearner.utilities.*; public @SuppressWarnings("all") class ConfParserTokenManager implements ConfParserConstants Modified: trunk/src/dl-learner/org/dllearner/parser/conf.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-03 14:54:46 UTC (rev 167) @@ -30,6 +30,7 @@ PARSER_BEGIN(ConfParser) package org.dllearner.parser; +import java.util.HashMap; import java.util.List; import java.util.LinkedList; import java.util.Map; @@ -49,36 +50,40 @@ import org.dllearner.Info; import org.dllearner.core.dl.*; -import org.dllearner.ConfigurationOption; +import org.dllearner.cli.*; import org.dllearner.utilities.*; public class ConfParser { + // examples private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); - // Konfigurationsoptionen - private List<ConfigurationOption> confOptions = new LinkedList<ConfigurationOption>(); + // conf file options + private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); + private Map<String,ConfFileOption> confOptionsByName = new HashMap<String,ConfFileOption>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) // private static Map<String,Set<String>> functionCallsAlt = new TreeMap<String,Set<String>>(); // jeder Funktionsaufruf hat eine Liste von n Argumenten; alle Funktionsaufrufe // werden in einer Liste gespeichert - private List<List<String>> functionCalls = new LinkedList<List<String>>(); + // private List<List<String>> functionCalls = new LinkedList<List<String>>(); // => irgendwie Funktionsname + Argumente speichern // => d.h. man bräuchte für jede Funktion so eine Liste oder das erste Element // der Liste ist der Funktionsname <= ist noch die praktikabelste Variante - // speichert, ob der Parser-Konstruktor aufgerufen wurde: momemtan handelt es - // sich um einen statischen Parser, d.h. der Konstruktor darf nur einmal - // aufgerufen werden; weitere Parsevorgänge erfolgen dann mit ReInit - // TODO: bei einem Webservice braucht man wahrscheinlich einen dynamischen Parser - // private static boolean constructorCalled = false; + private Map<String,List<List<String>>> functionCalls = new HashMap<String,List<List<String>>>(); - // Wissensbasis - // private KB kb = new KB(); - // public static final String internalNamespace = "http://localhost/foo#"; + private void addFunctionCall(String name, List<String> arguments) { + if(functionCalls.containsKey(name)) + functionCalls.get(name).add(arguments); + else { + List<List<String>> calls = new LinkedList<List<String>>(); + calls.add(arguments); + functionCalls.put(name,calls); + } + } public SortedSet<Individual> getPositiveExamples() { return positiveExamples; @@ -88,11 +93,15 @@ return negativeExamples; } - public List<ConfigurationOption> getConfOptions() { + public List<ConfFileOption> getConfOptions() { return confOptions; } - public List<List<String>> getFunctionCalls() { + public Map<String,ConfFileOption> getConfOptionsByName() { + return confOptionsByName; + } + + public Map<String,List<List<String>>> getFunctionCalls() { return functionCalls; } @@ -118,7 +127,7 @@ } */ - public static ConfParser parseFile(String filename) { + public static ConfParser parseFile(File filename) { ConfParser learner = null; try { learner = new ConfParser(new FileInputStream(filename)); @@ -238,14 +247,14 @@ RBoxAxiom rBoxAxiom; Equality equality; Inclusion inclusion; - ConfigurationOption confOption; + ConfFileOption confOption; } { ( // bei Konfigurationsoption geht der Parser bis zum Semikolon durch, da das das einzige // sichere Unterscheidungsmerkmal ist LOOKAHEAD(Id() [ "." Id() ] "=" ( Id() | Integer() | Double() | String() | "{" "}" | "{" ( ( String() | Id() ) "," )* (String() | Id()) "}" ) <CONF_END>) confOption=ConfOption() - { confOptions.add(confOption); } + { confOptions.add(confOption); confOptionsByName.put(confOption.getFullName(), confOption); } | LOOKAHEAD(Id() "(" String() ("," String())* ")" <CONF_END>) FunctionCall() // positive bzw. negative Beispiele sind an "+" bzw. "-" erkennbar | LOOKAHEAD(<POS_EX>) PosExample() @@ -254,13 +263,13 @@ <EOF> } -ConfigurationOption ConfOption() : +ConfFileOption ConfOption() : { boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false; String option="", subOption="", value="", tmp=""; int number = 0; double numberDouble = 0; - ConfigurationOption confOption; + ConfFileOption confOption; Set<String> values = new HashSet<String>(); } { @@ -278,25 +287,25 @@ if(containsSubOption) { if(isNumeric) if(isDouble) - confOption = new ConfigurationOption(option,subOption,numberDouble); + confOption = new ConfFileOption(option,subOption,numberDouble); else - confOption = new ConfigurationOption(option,subOption,number); + confOption = new ConfFileOption(option,subOption,number); else if(isSet) - confOption = new ConfigurationOption(option,subOption,values); + confOption = new ConfFileOption(option,subOption,values); else - confOption = new ConfigurationOption(option,subOption,value); + confOption = new ConfFileOption(option,subOption,value); } else { if(isNumeric) if(isDouble) - confOption = new ConfigurationOption(option,numberDouble); + confOption = new ConfFileOption(option,numberDouble); else - confOption = new ConfigurationOption(option,number); + confOption = new ConfFileOption(option,number); else if(isSet) - confOption = new ConfigurationOption(option,values); + confOption = new ConfFileOption(option,values); else - confOption = new ConfigurationOption(option,value); + confOption = new ConfFileOption(option,value); } return confOption; // confOptions.add(confOption); @@ -309,9 +318,9 @@ List<String> list = new LinkedList<String>(); } { - s1=Id() "(" s2=String() { list.add(s1); list.add(s2); } + s1=Id() "(" s2=String() { list.add(s2); } ("," s=String() { list.add(s); } )* ")" <CONF_END> - { functionCalls.add(list); } + { addFunctionCall(s1,list); } } void PosExample() : { Individual i; } Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2007-10-03 14:54:46 UTC (rev 167) @@ -15,9 +15,9 @@ import org.dllearner.Config; import org.dllearner.ConfigurationManager; -import org.dllearner.ConfigurationOption; import org.dllearner.Main; import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.cli.ConfFileOption; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; @@ -63,13 +63,13 @@ public void setStatus(String status) {this.status = status;} ConfigurationManager confMgr; - public void addOption(ConfigurationOption c){confMgr.applyConfigurationOption(c);} + public void addOption(ConfFileOption c){confMgr.applyConfigurationOption(c);} ROLearner ROL; public ClientState() { - TreeSet<ConfigurationOption> s=new TreeSet<ConfigurationOption>(); + TreeSet<ConfFileOption> s=new TreeSet<ConfFileOption>(); //s.add(new ConfigurationOption("refinement","quiet","true")); /*s.add(new ConfigurationOption()); s.add(new ConfigurationOption()); @@ -79,7 +79,7 @@ s.add(new ConfigurationOption());*/ confMgr = new ConfigurationManager(s); - addOption(new ConfigurationOption("refinement","quiet","true")); + addOption(new ConfFileOption("refinement","quiet","true")); //confMgr.applyOptions(); } @@ -460,7 +460,7 @@ public void learnMonitored(){ - addOption(new ConfigurationOption("refinement","ignoredConcepts",ignoredConcept)); + addOption(new ConfFileOption("refinement","ignoredConcepts",ignoredConcept)); this.lm=new LearnMonitor(this); this.lm.start(); //this.lm.learn(this); Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-03 10:45:34 UTC (rev 166) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-10-03 14:54:46 UTC (rev 167) @@ -156,7 +156,7 @@ for(int exampleNr=startExampleNr; exampleNr < examples.length; exampleNr++) { // parse current conf file - ConfParser learner = ConfParser.parseFile(confFiles[exampleNr].toString()); + ConfParser learner = ConfParser.parseFile(confFiles[exampleNr]); // read which files were imported (internal KB is ignored) and initialise reasoner Map<URL, OntologyFileFormat> imports = getImports(learner.getFunctionCalls(), confFiles[exampleNr]); @@ -302,15 +302,17 @@ } - private static Map<URL, OntologyFileFormat> getImports(List<List<String>> functionCalls, File confFile) { + private static Map<URL, OntologyFileFormat> getImports(Map<String,List<List<String>>> functionCalls, File confFile) { Map<URL, OntologyFileFormat> importedFiles = new HashMap<URL, OntologyFileFormat>(); OntologyFileFormat format = null; URL url = null; - for (List<String> call : functionCalls) { + List<List<String>> imports = functionCalls.get("import"); + + for (List<String> call : imports) { - if(call.get(0).equals("import")) { + //if(call.get(0).equals("import")) { try { String fileString = call.get(1); @@ -336,7 +338,7 @@ format = OntologyFileFormat.N_TRIPLES; importedFiles.put(url, format); } - } + // } } return importedFiles; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-04 15:07:43
|
Revision: 168 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=168&view=rev Author: jenslehmann Date: 2007-10-04 08:07:40 -0700 (Thu, 04 Oct 2007) Log Message: ----------- continued to implement command line interface (with numerous related changes) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java trunk/src/dl-learner/org/dllearner/parser/conf.jj Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-04 15:07:40 UTC (rev 168) @@ -22,6 +22,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.RoleComparator; /** @@ -188,15 +189,15 @@ // alle Strings erlaubt) String[] possibleValuesArray = strOptions.get(optionString); List<String> possibleValues = Arrays.asList(possibleValuesArray); - if (!possibleValues.contains(option.getStrValue()) && possibleValues.size() != 0) { + if (!possibleValues.contains(option.getStringValue()) && possibleValues.size() != 0) { System.out.println("Error: The configuration option \"" + optionString - + "\" must not have value \"" + option.getStrValue() + + "\" must not have value \"" + option.getStringValue() + "\". The value must be one of " + possibleValues + "."); System.exit(0); } // alles OK, Option kann angewandt werden - applyStringOptions(optionString,option.getStrValue()); + applyStringOptions(optionString,option.getStringValue()); // Option existiert nicht => Fehlerbehandlung } else { @@ -421,17 +422,17 @@ private void applyStringOptions(String option, String value) { if (option.equals("penalizeNeutralExamples")) - Config.penalizeNeutralExamples = strToBool(value); + Config.penalizeNeutralExamples = Datastructures.strToBool(value); else if (option.equals("showCorrectClassifications")) - Config.showCorrectClassifications = strToBool(value); + Config.showCorrectClassifications = Datastructures.strToBool(value); else if (option.equals("statMode")) - Config.statisticMode = strToBool(value); + Config.statisticMode = Datastructures.strToBool(value); else if (option.equals("una")) - Config.una = strToBool(value); + Config.una = Datastructures.strToBool(value); else if (option.equals("owa")) - Config.owa = strToBool(value); + Config.owa = Datastructures.strToBool(value); else if (option.equals("gp.useFixedNumberOfGenerations")) - Config.GP.useFixedNumberOfGenerations = strToBool(value); + Config.GP.useFixedNumberOfGenerations = Datastructures.strToBool(value); else if (option.equals("scoreMethod")) { if (value.equals("full")) Config.scoreMethod = ScoreMethod.FULL; @@ -459,17 +460,17 @@ } else if(option.equals("hidePrefix")) { Config.hidePrefixes.add(value); } else if (option.equals("showIndividuals")) { - Config.showIndividuals = strToBool(value); + Config.showIndividuals = Datastructures.strToBool(value); } else if (option.equals("showConcepts")) { - Config.showConcepts = strToBool(value); + Config.showConcepts = Datastructures.strToBool(value); } else if (option.equals("showRoles")) { - Config.showRoles = strToBool(value); + Config.showRoles = Datastructures.strToBool(value); } else if (option.equals("showInternalKB")) { - Config.showInternalKB = strToBool(value); + Config.showInternalKB = Datastructures.strToBool(value); } else if (option.equals("showSubsumptionHierarchy")) { - Config.showSubsumptionHierarchy = strToBool(value); + Config.showSubsumptionHierarchy = Datastructures.strToBool(value); } else if (option.equals("writeDIGProtocol")) { - Config.writeDIGProtocol = strToBool(value); + Config.writeDIGProtocol = Datastructures.strToBool(value); } else if (option.equals("digProtocolFile")) { Config.digProtocolFile = new File(value); // } else if (option.equals("preprocessingModule")) { @@ -487,34 +488,34 @@ else Config.GP.algorithmType = AlgorithmType.GENERATIONAL; } else if (option.equals("gp.adc")) { - Config.GP.adc = strToBool(value); + Config.GP.adc = Datastructures.strToBool(value); } else if (option.equals("refinement.heuristic")) { if(value.equals("lexicographic")) Config.Refinement.heuristic = Config.Refinement.Heuristic.LEXICOGRAPHIC; else Config.Refinement.heuristic = Config.Refinement.Heuristic.FLEXIBLE; } else if (option.equals("refinement.quiet")) - Config.Refinement.quiet = strToBool(value); + Config.Refinement.quiet = Datastructures.strToBool(value); else if (option.equals("refinement.writeSearchTree")) - Config.Refinement.writeSearchTree = strToBool(value); + Config.Refinement.writeSearchTree = Datastructures.strToBool(value); else if (option.equals("refinement.searchTreeFile")) { Config.Refinement.searchTreeFile = new File(value); } else if (option.equals("refinement.applyAllFilter")) - Config.Refinement.applyAllFilter = strToBool(value); + Config.Refinement.applyAllFilter = Datastructures.strToBool(value); else if (option.equals("refinement.applyExistsFilter")) - Config.Refinement.applyExistsFilter = strToBool(value); + Config.Refinement.applyExistsFilter = Datastructures.strToBool(value); else if (option.equals("refinement.useTooWeakList")) - Config.Refinement.useTooWeakList = strToBool(value); + Config.Refinement.useTooWeakList = Datastructures.strToBool(value); else if (option.equals("refinement.useOverlyGeneralList")) - Config.Refinement.useOverlyGeneralList = strToBool(value); + Config.Refinement.useOverlyGeneralList = Datastructures.strToBool(value); else if (option.equals("refinement.useShortConceptConstruction")) - Config.Refinement.useShortConceptConstruction = strToBool(value); + Config.Refinement.useShortConceptConstruction = Datastructures.strToBool(value); else if (option.equals("refinement.useAllConstructor")) - Config.Refinement.useAllConstructor = strToBool(value); + Config.Refinement.useAllConstructor = Datastructures.strToBool(value); else if (option.equals("refinement.useExistsConstructor")) - Config.Refinement.useExistsConstructor = strToBool(value); + Config.Refinement.useExistsConstructor = Datastructures.strToBool(value); else if (option.equals("refinement.useNegation")) - Config.Refinement.useNegation = strToBool(value); + Config.Refinement.useNegation = Datastructures.strToBool(value); else if (option.equals("reasoner")) { if(value.equals("dig")) Config.reasonerType = ReasonerType.DIG; @@ -531,7 +532,7 @@ System.exit(0); } } else if (option.equals("useRetrievalForClassification")) - Config.useRetrievalForClassification = strToBool(value); + Config.useRetrievalForClassification = Datastructures.strToBool(value); // else if (option.equals("refinement.useDIGMultiInstanceChecks")) { // if(value.equals("never")) // Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.NEVER; @@ -567,15 +568,6 @@ } } - private static boolean strToBool(String str) { - if (str.equals("true")) - return true; - else if (str.equals("false")) - return false; - else - throw new Error("Cannot convert to boolean."); - } - public void addDoubleOption(String option, Double[] range) { doubleOptions.put(option, range); } Modified: trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/cli/ConfFileOption.java 2007-10-04 15:07:40 UTC (rev 168) @@ -33,11 +33,12 @@ private boolean containsSubOption = true; private boolean isIntegerOption = false; - private boolean isNumeric = false; + private boolean isDoubleOption = false; + private boolean isStringOption = false; private boolean isSetOption = false; private String option; private String subOption; - private String strValue; + private String stringValue; private int intValue; private double doubleValue; private Set<String> setValues; @@ -50,7 +51,8 @@ public ConfFileOption(String option, String subOption, String value) { this.option = option; this.subOption = subOption; - strValue = value; + stringValue = value; + isStringOption = true; } public ConfFileOption(String option, int value) { @@ -63,7 +65,6 @@ this.subOption = subOption; intValue = value; isIntegerOption = true; - isNumeric = true; } public ConfFileOption(String option, double value) { @@ -75,8 +76,7 @@ this.option = option; this.subOption = subOption; doubleValue = value; - // isIntegerOption = false; - isNumeric = true; + isDoubleOption = false; } public ConfFileOption(String option, Set<String> values) { @@ -98,17 +98,13 @@ public int getIntValue() { return intValue; } - - public boolean isIntegerOption() { - return isIntegerOption; - } - + public String getOption() { return option; } - public String getStrValue() { - return strValue; + public String getStringValue() { + return stringValue; } public String getSubOption() { @@ -119,8 +115,46 @@ return doubleValue; } + public Object getValue() { + if(isIntegerOption) + return intValue; + else if(isDoubleOption) + return doubleValue; + else if(isStringOption) + return stringValue; + else + return setValues; + } + + /** + * + * @return The class of the value of the conf file option; + */ + public Class<?> getType() { + if(isIntegerOption) + return Integer.class; + else if(isDoubleOption) + return Double.class; + else if(isStringOption) + return String.class; + else + return Set.class; + } + + public boolean isIntegerOption() { + return isIntegerOption; + } + + public boolean isDoubleOption() { + return isDoubleOption; + } + public boolean isNumeric() { - return isNumeric; + return (isIntegerOption || isDoubleOption); + } + + public boolean isStringOption() { + return isStringOption; } public boolean isSetOption() { @@ -134,13 +168,13 @@ completeOption += option + "." + subOption; else completeOption += option; - if(isNumeric) + if(isNumeric()) if(isIntegerOption) return completeOption + "=" + intValue; else return completeOption + "=" + doubleValue; else - return completeOption + "=" + strValue; + return completeOption + "=" + stringValue; } public Set<String> getSetValues() { Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-04 15:07:40 UTC (rev 168) @@ -28,22 +28,35 @@ import java.util.Map; import java.util.Set; +import org.dllearner.algorithms.gp.GP; +import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.core.BooleanConfigOption; +import org.dllearner.core.Component; import org.dllearner.core.ComponentManager; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; +import org.dllearner.core.DoubleConfigOption; +import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.StringConfigOption; +import org.dllearner.core.StringSetConfigOption; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; -import org.dllearner.kb.OntologyFileFormat; import org.dllearner.kb.SparqlEndpoint; +import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.parser.ConfParser; +import org.dllearner.reasoning.DIGReasonerNew; +import org.dllearner.utilities.Datastructures; /** * Startup file for Command Line Interface. * * @author Jens Lehmann - * + * */ public class Start { @@ -51,50 +64,169 @@ * @param args */ public static void main(String[] args) { - File file = new File(args[args.length-1]); + File file = new File(args[args.length - 1]); String baseDir = file.getParentFile().getPath(); - + // create component manager instance ComponentManager cm = ComponentManager.getInstance(); - + + // create a mapping between components and prefixes in the conf file + Map<Class<? extends Component>, String> componentPrefixMapping = createComponentPrefixMapping(); + // parse conf file ConfParser parser = ConfParser.parseFile(file); - -// try { - + + // try { + // step 1: detect knowledge sources Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); Map<URL, Class<? extends KnowledgeSource>> importedFiles = getImportedFiles(parser, baseDir); - for(Map.Entry<URL, Class<? extends KnowledgeSource>> entry : importedFiles.entrySet()) { + for (Map.Entry<URL, Class<? extends KnowledgeSource>> entry : importedFiles.entrySet()) { KnowledgeSource ks = cm.knowledgeSource(entry.getValue()); - // ConfigOption<?> urlOption = cm.getConfigOption(entry.getValue(), "url"); - // cm.applyConfigEntry(ks, new ConfigEntry<String>(urlOption, entry.getValue())); + // ConfigOption<?> urlOption = cm.getConfigOption(entry.getValue(), + // "url"); + // cm.applyConfigEntry(ks, new ConfigEntry<String>(urlOption, + // entry.getValue())); cm.applyConfigEntry(ks, "url", entry.getKey().toString()); // TODO: SPARQL-specific settings - + // ks.applyConfigEntry(new ConfigEntry) - + } - + + // step 2: detect used reasoner + ConfFileOption reasonerOption = parser.getConfOptionsByName("reasoner"); + ReasoningService rs = null; + // default value + if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) + rs = cm.reasoningService(DIGReasonerNew.class, sources); + else { + handleError("Unknown value " + reasonerOption.getStringValue() + + "for option \"reasoner\"."); + } + + // step 3: detect learning problem (no options yet) + LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + + // step 4: detect learning algorithm + ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); + LearningAlgorithmNew la = null; + Class<? extends LearningAlgorithmNew> laClass = null; + if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) + laClass = ROLearner.class; + + la = cm.learningAlgorithm(ROLearner.class, lp); + + configureComponent(cm, la, parser.getConfOptionsByPrefix(componentPrefixMapping + .get(la))); + + // start algorithm + la.start(); + // use parsed values to configure components - -// } catch (InvalidConfigOptionValueException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } + + // several classes of options: function calls, conf options for a + // component, + // CLI specific options, general conf options for all components + + // } catch (InvalidConfigOptionValueException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } } - private static Map<URL, Class<? extends KnowledgeSource>> getImportedFiles(ConfParser parser, String baseDir) { + // creates a mapping from components to option prefix strings + private static Map<Class<? extends Component>, String> createComponentPrefixMapping() { + Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); + componentPrefixMapping.put(ROLearner.class, "refinement"); + componentPrefixMapping.put(GP.class, "gp"); + componentPrefixMapping.put(DIGReasonerNew.class, "digReasoner"); + componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); + return componentPrefixMapping; + } + + private static void configureComponent(ComponentManager cm, + Component component, List<ConfFileOption> options) { + for (ConfFileOption option : options) + applyConfFileOption(cm, component, option); + } + + private static void applyConfFileOption(ComponentManager cm, + Component component, ConfFileOption option) { + // the name of the option is suboption-part (the first part refers + // to its component) + String optionName = option.getSubOption(); + + ConfigOption<?> configOption = cm.getConfigOption(component.getClass(), optionName); + // check whether such an option exists + if (configOption != null) { + + // catch all invalid config options + try { + + // perform compatibility checks + if (configOption instanceof StringConfigOption && option.isStringOption()) { + + ConfigEntry<String> entry = new ConfigEntry<String>( + (StringConfigOption) configOption, option.getStringValue()); + cm.applyConfigEntry(component, entry); + + } else if(configOption instanceof IntegerConfigOption && option.isIntegerOption()) { + + ConfigEntry<Integer> entry = new ConfigEntry<Integer>( + (IntegerConfigOption) configOption, option.getIntValue()); + cm.applyConfigEntry(component, entry); + + } else if(configOption instanceof DoubleConfigOption && (option.isIntegerOption() || option.isDoubleOption())) { + + double value; + if(option.isIntegerOption()) + value = option.getIntValue(); + else + value = option.getDoubleValue(); + + ConfigEntry<Double> entry = new ConfigEntry<Double>( + (DoubleConfigOption) configOption, value); + cm.applyConfigEntry(component, entry); + + } else if(configOption instanceof BooleanConfigOption && option.isStringOption()) { + + ConfigEntry<Boolean> entry = new ConfigEntry<Boolean>( + (BooleanConfigOption) configOption, Datastructures.strToBool(option.getStringValue())); + cm.applyConfigEntry(component, entry); + + } else if(configOption instanceof StringSetConfigOption && option.isSetOption()) { + + ConfigEntry<Set<String>> entry = new ConfigEntry<Set<String>>( + (StringSetConfigOption) configOption, option.getSetValues()); + cm.applyConfigEntry(component, entry); + + } else { + handleError("The type of conf file entry " + option + " is not correct."); + } + + } catch (InvalidConfigOptionValueException e) { + // e.printStackTrace(); + System.exit(0); + } + + } else + handleError("Unknow option " + option + "."); + } + + // detects all imported files and their format + private static Map<URL, Class<? extends KnowledgeSource>> getImportedFiles(ConfParser parser, + String baseDir) { List<List<String>> imports = parser.getFunctionCalls().get("import"); Map<URL, Class<? extends KnowledgeSource>> importedFiles = new HashMap<URL, Class<? extends KnowledgeSource>>(); - - for(List<String> arguments : imports) { + + for (List<String> arguments : imports) { // step 1: detect URL URL url = null; - try { + try { String fileString = arguments.get(0); - if(fileString.startsWith("http:")) { + if (fileString.startsWith("http:")) { url = new URL(fileString); } else { File f = new File(baseDir, arguments.get(0)); @@ -103,45 +235,52 @@ } catch (MalformedURLException e) { e.printStackTrace(); } - + // step 2: detect format Class<? extends KnowledgeSource> ksClass; if (arguments.size() == 1) { String filename = url.getPath(); String ending = filename.substring(filename.lastIndexOf(".")); - - if(ending.equals("rdf") || ending.equals("owl")) + + if (ending.equals("rdf") || ending.equals("owl")) ksClass = OWLFile.class; - else if(ending.equals("nt")) + else if (ending.equals("nt")) ksClass = OWLFile.class; - else if(ending.equals("kb")) + else if (ending.equals("kb")) ksClass = KBFile.class; else { - System.err.println("Warning: no format fiven for " + arguments.get(0) + " and could not detect it. Chosing RDF/XML."); + System.err.println("Warning: no format fiven for " + arguments.get(0) + + " and could not detect it. Chosing RDF/XML."); ksClass = OWLFile.class; } - + importedFiles.put(url, ksClass); } else { String formatString = arguments.get(1); - + if (formatString.equals("RDF/XML")) ksClass = OWLFile.class; - else if(formatString.equals("KB")) + else if (formatString.equals("KB")) ksClass = KBFile.class; - else if(formatString.equals("SPARQL")) + else if (formatString.equals("SPARQL")) ksClass = SparqlEndpoint.class; - else if(formatString.equals("NT")) + else if (formatString.equals("NT")) ksClass = OWLFile.class; else { - throw new RuntimeException("Unsupported knowledge source format " + formatString + ". Exiting."); + throw new RuntimeException("Unsupported knowledge source format " + + formatString + ". Exiting."); } - + importedFiles.put(url, ksClass); } } - + return importedFiles; } - + + private static void handleError(String message) { + System.err.println(message); + System.exit(0); + } + } Added: trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/DoubleConfigOption.java 2007-10-04 15:07:40 UTC (rev 168) @@ -0,0 +1,85 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * Represents a configuration option with values of type value. Similar + * to the integer option a minimum and a maximum value can specified. + * + * @author Jens Lehmann + * + */ +public class DoubleConfigOption extends ConfigOption<Double> { + + private double lowerLimit = Double.MIN_VALUE; + private double upperLimit = Double.MAX_VALUE; + + public DoubleConfigOption(String name, String description) { + super(name, description); + } + + /* (non-Javadoc) + * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) + */ + @Override + public boolean isValidValue(Double value) { + if(value >= lowerLimit && value <= upperLimit) + return true; + else + return false; + } + + /** + * @return the The lowest possible value for this configuration option. + */ + public double getLowerLimit() { + return lowerLimit; + } + + /** + * @param lowerLimit The lowest possible value for this configuration option. + */ + public void setLowerLimit(double lowerLimit) { + this.lowerLimit = lowerLimit; + } + + /** + * @return the The highest possible value for this configuration option. + */ + public double getUpperLimit() { + return upperLimit; + } + + /** + * @param upperLimit The highest possible value for this configuration option. + */ + public void setUpperLimit(double upperLimit) { + this.upperLimit = upperLimit; + } + + /* (non-Javadoc) + * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) + */ + @Override + public boolean checkType(Object object) { + return (object instanceof Double); + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/core/IntegerConfigOption.java 2007-10-04 15:07:40 UTC (rev 168) @@ -38,23 +38,6 @@ /* (non-Javadoc) * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ - /* - public boolean isValidValue(Object value) { - if(!(value instanceof Integer)) - return false; - - int intValue = (Integer) value; - - if(intValue >= lowerLimit && intValue <= upperLimit) - return true; - else - return false; - } - */ - - /* (non-Javadoc) - * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) - */ @Override public boolean isValidValue(Integer value) { if(value >= lowerLimit && value <= upperLimit) @@ -99,10 +82,4 @@ return (object instanceof Integer); } - - - - - - } Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-10-04 15:07:40 UTC (rev 168) @@ -84,7 +84,7 @@ for (int i = 0; i < confOptions.size(); i++) { if(confOptions.get(i).getOption().equals("hidePrefix")){ - prefix=confOptions.get(i).getStrValue(); + prefix=confOptions.get(i).getStringValue(); } System.out.println(confOptions.get(i).getOption()); if(confOptions.get(i).getOption().equals("gp")) Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-10-04 15:07:40 UTC (rev 168) @@ -34,6 +34,7 @@ import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.KB; import org.dllearner.modules.PreprocessingModule; +import org.dllearner.utilities.Datastructures; /** @@ -97,7 +98,7 @@ for (int i = 0; i < confOptions.size(); i++) { if(confOptions.get(i).getOption().equals("hidePrefix")){ - prefix=confOptions.get(i).getStrValue(); + prefix=confOptions.get(i).getStringValue(); } //sparqlModule options if(confOptions.get(i).getOption().equals("sparqlModule")){ @@ -136,7 +137,7 @@ this.fw=new FileWriter(new File(baseDir+File.separator+filename),true); System.out.println("SparqlModul: Collecting Ontology"); OntologyCollector oc=new OntologyCollector(subjectList, numberOfRecursions, - filterMode, Util.setToArray(predList),Util.setToArray( objList),Util.setToArray(classList)); + filterMode, Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList)); String ont=oc.collectOntology(); fw.write(ont); Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java 2007-10-04 15:07:40 UTC (rev 168) @@ -21,12 +21,10 @@ import java.util.HashSet; import java.util.Iterator; -import java.util.Set; /** * mainly converts datatypes * - * TODO: move to org.dllearner.utilities * * @author Sebastian Hellmann * @@ -35,25 +33,6 @@ /** - * easy conversion - * - * @param s - * @return - */ - public static String[] setToArray(Set<String> s){ - if(s==null)return null; - String[] ret=new String[s.size()]; - int i=0; - for (Iterator<String> iter = s.iterator(); iter.hasNext();) { - ret[i] = iter.next(); - i++; - - } - return ret; - - } - - /** * Warning use only for visualization * @param s * @return String without certain namespaces Modified: trunk/src/dl-learner/org/dllearner/parser/conf.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-03 14:54:46 UTC (rev 167) +++ trunk/src/dl-learner/org/dllearner/parser/conf.jj 2007-10-04 15:07:40 UTC (rev 168) @@ -62,6 +62,7 @@ // conf file options private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); private Map<String,ConfFileOption> confOptionsByName = new HashMap<String,ConfFileOption>(); + private Map<String,List<ConfFileOption>> confOptionsByPrefix = new HashMap<String,List<ConfFileOption>>(); // Funktionsaufrufe (die gleiche Funktion darf mehrmals mit unterschiedlichen // Argumenten aufgerufen werden) @@ -85,6 +86,19 @@ } } + private void addConfOption(ConfFileOption confOption) { + confOptions.add(confOption); + confOptionsByName.put(confOption.getFullName(), confOption); + String prefix = confOption.getOption(); + if(confOptionsByPrefix.containsKey(prefix)) + confOptionsByPrefix.get(prefix).add(confOption); + else { + LinkedList<ConfFileOption> optionList = new LinkedList<ConfFileOption>(); + optionList.add(confOption); + confOptionsByPrefix.put(prefix,optionList); + } + } + public SortedSet<Individual> getPositiveExamples() { return positiveExamples; } @@ -100,7 +114,19 @@ public Map<String,ConfFileOption> getConfOptionsByName() { return confOptionsByName; } + + public ConfFileOption getConfOptionsByName(String name) { + return confOptionsByName.get(name); + } + public Map<String,List<ConfFileOption>> getConfOptionsByPrefix() { + return confOptionsByPrefix; + } + + public List<ConfFileOption> getConfOptionsByPrefix(String prefix) { + return confOptionsByPrefix.get(prefix); + } + public Map<String,List<List<String>>> getFunctionCalls() { return functionCalls; } @@ -254,7 +280,7 @@ // sichere Unterscheidungsmerkmal ist LOOKAHEAD(Id() [ "." Id() ] "=" ( Id() | Integer() | Double() | String() | "{" "}" | "{" ( ( String() | Id() ) "," )* (String() | Id()) "}" ) <CONF_END>) confOption=ConfOption() - { confOptions.add(confOption); confOptionsByName.put(confOption.getFullName(), confOption); } + { addConfOption(confOption); } | LOOKAHEAD(Id() "(" String() ("," String())* ")" <CONF_END>) FunctionCall() // positive bzw. negative Beispiele sind an "+" bzw. "-" erkennbar | LOOKAHEAD(<POS_EX>) PosExample() Added: trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java 2007-10-04 15:07:40 UTC (rev 168) @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.utilities; + +import java.util.Iterator; +import java.util.Set; + +/** + * @author Jens Lehmann + * @author Sebastian Hellmann + * + */ +public class Datastructures { + + public static boolean strToBool(String str) { + if (str.equals("true")) + return true; + else if (str.equals("false")) + return false; + else + throw new Error("Cannot convert to boolean."); + } + + /** + * easy conversion + * + * @param s + * @return + */ + public static String[] setToArray(Set<String> s){ + if(s==null)return null; + String[] ret=new String[s.size()]; + int i=0; + for (Iterator<String> iter = s.iterator(); iter.hasNext();) { + ret[i] = iter.next(); + i++; + + } + return ret; + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-07 18:00:23
|
Revision: 174 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=174&view=rev Author: jenslehmann Date: 2007-10-07 11:00:21 -0700 (Sun, 07 Oct 2007) Log Message: ----------- transition from old command line interface completed Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/modules/TestModule.java trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java trunk/src/dl-learner/org/dllearner/parser/ConfParser.java trunk/src/dl-learner/org/dllearner/parser/ConfParserTokenManager.java trunk/src/dl-learner/org/dllearner/parser/conf.jj trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java trunk/src/dl-learner/org/dllearner/utilities/Helper.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/Main.java Deleted: trunk/src/dl-learner/org/dllearner/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Main.java 2007-10-07 16:35:12 UTC (rev 173) +++ trunk/src/dl-learner/org/dllearner/Main.java 2007-10-07 18:00:21 UTC (rev 174) @@ -1,1379 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -package org.dllearner; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.text.DecimalFormat; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.Config.Algorithm; -import org.dllearner.algorithms.BruteForceLearner; -import org.dllearner.algorithms.LearningAlgorithm; -import org.dllearner.algorithms.gp.GP; -import org.dllearner.algorithms.refinement.ROLearner; -import org.dllearner.cli.ConfFileOption; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.LearningAlgorithmNew; -import org.dllearner.core.LearningProblem; -import org.dllearner.core.Reasoner; -import org.dllearner.core.ReasoningMethodUnsupportedException; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.Score; -import org.dllearner.core.dl.AssertionalAxiom; -import org.dllearner.core.dl.AtomicConcept; -import org.dllearner.core.dl.AtomicRole; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.ConceptAssertion; -import org.dllearner.core.dl.FlatABox; -import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.KB; -import org.dllearner.core.dl.Negation; -import org.dllearner.core.dl.RoleAssertion; -import org.dllearner.kb.OntologyFileFormat; -import org.dllearner.learningproblems.DefinitionLP; -import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.modules.ModuleInvocator; -import org.dllearner.parser.KBParser; -import org.dllearner.parser.ParseException; -import org.dllearner.parser.TokenMgrError; -import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.reasoning.FastRetrievalReasoner; -import org.dllearner.reasoning.KAON2Reasoner; -import org.dllearner.reasoning.ReasonerType; -import org.dllearner.utilities.ConceptComparator; -import org.dllearner.utilities.ConceptTransformation; -import org.dllearner.utilities.Files; -import org.dllearner.utilities.Helper; -import org.dllearner.utilities.RoleComparator; -import org.dllearner.utilities.Stat; - -/** - * Stellt die Verbindung zwischen Parser und den anderen Programmteilen her. - * Startet den Algorithmus. - * - * TODO: Die Hauptmethode sollte noch in kleinere Einheiten zerlegt werden zur - * besseren Lesbarkeit. - * - * TODO: einige Errors können durch RuntimeException ersetzt werden (kein throws - * und Exception-Handling notwendig) - * - * @author Jens Lehmann - * - */ -public class Main { - - private static FlatABox abox; - - private static ConfigurationManager confMgr; - - private Reasoner reasoner; - private ReasoningService rs; - private PosNegLP learningProblem; - // es werden jeweils die Dateien mit dem zugehörigen Format abgelegt - Map<URL, OntologyFileFormat> importedFiles; - Map<File, OntologyFileFormat> exportedFiles; - KB kb; - SortedSet<Individual> posExamples; - SortedSet<Individual> negExamples; - List<File> loadedJars; - List<String> preprocessingModules; - - private static long algorithmStartTime = 0; - - private String baseDir; - - // neuer Hauptkonstruktor - public Main(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, - Map<AtomicConcept, SortedSet<Individual>> negativeExamples, - List<ConfFileOption> confOptions, List<List<String>> functionCalls, - String baseDir, boolean useQueryMode) { - - this.kb = kb; - this.baseDir = baseDir; - - // Konfigurationsmanager erstellen - confMgr = new ConfigurationManager(confOptions); - if (!confMgr.checkConsistency()) { - throw new Error( - "inconsistent/unsupported combination of configuration options"); - } - - // Funktionsaufrufe in Klassenvariablen laden - parseFunctionCalls(functionCalls); - - - - // verwandte Individuen entfernen - /* - * removeIndividualSubtree(kb, new - * Individual("http://localhost/foo#nonnie")); - * removeIndividualSubtree(kb, new - * Individual("http://localhost/foo#beatrice")); - * removeIndividualSubtree(kb, new - * Individual("http://localhost/foo#ann")); - */ - - // momentan keine Unterst�tzung f�r das gleichzeitige Lernen mehrerer - // Konzepte - // TODO: irgendwann lernen mehrerer Konzepte eventuell unterst�tzen - // (momentan keine hohe Priorit�t) - if (positiveExamples.size() > 1 || negativeExamples.size() > 1) { - throw new Error("Currently only one target concept is supported."); - } - - // Jar-Dateien laden - List<URL> urls = new LinkedList<URL>(); - // for (List<String> call : functionCalls) { - // if (call.get(0).equals("loadJarFile")) { - for(File f : loadedJars) { - // base dir wird hier nicht verwendet, da die Module eher - // relativ zum DL-Learner als zu den Beispielen liegen - // File f = new File(baseDir,call.get(1)); - // File f = new File(call.get(1)); - System.out.println("Loading jar file \"" + f.getAbsolutePath() + "\"."); - try { - urls.add(new URL("file", "localhost", f.getAbsolutePath())); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - // } - //} - } - - URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[] {})); - - // confMgr.applyOptions(); - - // Preprocessing-Modul aufrufen, falls notwendig - for (String module : preprocessingModules) { - //if (!Config.preprocessingModule.equals("")) { - System.out.println("Invoking preprocessing module main class " + module + "."); - ModuleInvocator mi = new ModuleInvocator(loader, module); - mi.invokePreprocessingModule(kb, positiveExamples, negativeExamples, confOptions, functionCalls, baseDir, useQueryMode); - //} - } - - // Funktionsaufrufe nochmal in Klassenvariablen laden, falls sie sich - // geändert haben - parseFunctionCalls(functionCalls); - - // Konfigurationsoptionen anwenden (könnten auch von einem Modul - // gesetzt werden) - confMgr.applyOptions(); - - // Beispiele werden in eine Menge gebracht - posExamples = new TreeSet<Individual>(); - negExamples = new TreeSet<Individual>(); - - for (AtomicConcept target : positiveExamples.keySet()) - posExamples = positiveExamples.get(target); - - for (AtomicConcept target : negativeExamples.keySet()) - negExamples = negativeExamples.get(target); - - // File-Objekte an function calls binden - /* - * boolean importKB = functionCalls.containsKey("import"); importedFiles = - * new LinkedList<File>(); if (importKB) { Set<String> - * importedFilesStr = functionCalls.get("import"); for (String - * importFileStr : importedFilesStr) { importedFiles.add(new - * File(baseDir, importFileStr)); } } - */ - /* - importedFiles = new HashMap<File, OntologyFileFormat>(); - for (List<String> call : functionCalls) { - if (call.get(0).equals("import")) { - File f = new File(baseDir, call.get(1)); - if (call.size() == 2) - // falls nichts angegeben, dann wird RDF/XML gewählt - importedFiles.put(f, OntologyFileFormat.RDF_XML); - else { - String formatString = call.get(2); - OntologyFileFormat format; - if (formatString.equals("RDF/XML")) - format = OntologyFileFormat.RDF_XML; - else - format = OntologyFileFormat.N_TRIPLES; - importedFiles.put(f, format); - } - } - } - */ - - // DIG-Reasoner testen - // new DIGReasonerTest(kb); - // System.exit(0); - - reasoner = createReasoner(kb, importedFiles); - ReasoningService rs = new ReasoningService(reasoner); - // commented out during changes - // learningProblem = new LearningProblem(rs, posExamples, negExamples); - - // export function - /* - * if (functionCalls.containsKey("export")) { for (String export : - * functionCalls.get("export")) { rs.saveOntology(export, baseDir); } } - */ - /* - for (List<String> call : functionCalls) { - if (call.get(0).equals("export")) { - File f = new File(baseDir, call.get(1)); - if (call.size() == 2) - // falls nichts angegeben, dann wird RDF/XML gewählt - rs.saveOntology(f, OntologyFileFormat.RDF_XML); - else { - String formatString = call.get(2); - OntologyFileFormat format; - if (formatString.equals("RDF/XML")) - format = OntologyFileFormat.RDF_XML; - else - format = OntologyFileFormat.N_TRIPLES; - rs.saveOntology(f, format); - } - } - } - */ - for(File f : exportedFiles.keySet()) { - rs.saveOntology(f, exportedFiles.get(f)); - } - - // Satisfiability Check - if (Config.reasonerType != ReasonerType.FAST_RETRIEVAL) { - System.out.print("Satisfiability Check ... "); - long satStartTime = System.nanoTime(); - boolean satisfiable = rs.isSatisfiable(); - long satDuration = System.nanoTime() - satStartTime; - - String result = satisfiable ? "OK" : "not satisfiable!"; - System.out.println(result + " (" - + Helper.prettyPrintNanoSeconds(satDuration, true, false) + ")"); - if (!satisfiable) - System.exit(0); - } - - autoDetectConceptsAndRoles(rs); - - // Subsumptionhierarchie vorbereiten - System.out.print("Preparing Subsumption Hierarchy ... "); - long subHierTimeStart = System.nanoTime(); - reasoner.prepareSubsumptionHierarchy(); - long subHierTime = System.nanoTime() - subHierTimeStart; - System.out.println("OK (" - + Helper.prettyPrintNanoSeconds(subHierTime, true, false) + ")"); - - // prepare role hierarchy - System.out.print("Preparing Role Hierarchy ... "); - long roleHierTimeStart = System.nanoTime(); - try { - reasoner.prepareRoleHierarchy(); - // System.out.println(); - // System.out.println(reasoner.getRoleHierarchy()); - } catch (ReasoningMethodUnsupportedException e1) { - System.out.println("Tried to construct the role hierarchy, but the reasoner " - + "does not support it. Currently only DIG reasoners support this feature."); - } - long roleHierTime = System.nanoTime() - roleHierTimeStart; - System.out.println("OK (" - + Helper.prettyPrintNanoSeconds(roleHierTime, true, false) + ")"); - - // Beispiele anzeigen - boolean oneLineExampleInfo = true; - int maxExampleStringLength = posExamples.toString().length(); - maxExampleStringLength = Math.max(maxExampleStringLength, negExamples.toString() - .length()); - if (maxExampleStringLength > 100) - oneLineExampleInfo = false; - - if (oneLineExampleInfo) { - System.out.println("positive examples[" + posExamples.size() + "]: " - + posExamples); - System.out.println("negative examples[" + negExamples.size() + "]: " - + negExamples); - } else { - System.out.println("positive examples[" + posExamples.size() + "]: "); - for (Individual ex : posExamples) - System.out.println(" " + ex); - System.out.println("negative examples[" + negExamples.size() + "]: "); - for (Individual ex : negExamples) - System.out.println(" " + ex); - } - - // Individuals - if (Config.showIndividuals) { - int stringLength = reasoner.getIndividuals().toString().length(); - if (stringLength > Config.maxLineLength) { - System.out.println("individuals[" + reasoner.getIndividuals().size() - + "]: "); - for (Individual ind : reasoner.getIndividuals()) - System.out.println(" " + ind); - } else - System.out.println("individuals[" + reasoner.getIndividuals().size() - + "]: " + reasoner.getIndividuals()); - } - - // Konzepte - if (Config.showConcepts) { - int stringLength = reasoner.getAtomicConcepts().toString().length(); - if (stringLength > Config.maxLineLength) { - System.out.println("concepts[" + reasoner.getAtomicConcepts().size() - + "]: "); - for (AtomicConcept ac : reasoner.getAtomicConcepts()) - System.out.println(" " + ac); - } else - System.out.println("concepts[" + reasoner.getAtomicConcepts().size() - + "]: " + reasoner.getAtomicConcepts()); - } - - // Rollen - if (Config.showRoles) { - int stringLength = reasoner.getAtomicRoles().toString().length(); - if (stringLength > Config.maxLineLength) { - System.out.println("roles[" + reasoner.getAtomicRoles().size() + "]: "); - for (AtomicRole r : reasoner.getAtomicRoles()) - System.out.println(" " + r); - } else - System.out.println("roles[" + reasoner.getAtomicRoles().size() + "]: " - + reasoner.getAtomicRoles()); - } - - // Anzeige der Subsumptionhierarchie - if (Config.showSubsumptionHierarchy) { - System.out.println("Subsumption Hierarchy:"); - try { - System.out.println(reasoner.getSubsumptionHierarchy()); - } catch (ReasoningMethodUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - // Anzeige der Wissensbasis - if (Config.showInternalKB) { - System.out.println(kb); - } - - - // Vergleichsreasoner erstellen zum Testen - // Reasoner reasoner2 = null; - // try { - // URL dig2URL = new URL("http://localhost:8081"); - // reasoner2 = new DIGReasoner(kb, dig2URL); - // reasoner2 = new KAON2Reasoner(kb, importedFiles); - // } catch (MalformedURLException e) { - // TODO Auto-generated catch block - // e.printStackTrace(); - // } - // ReasoningService rs2 = new ReasoningService(reasoner2); - // LearningProblem learningProblem2 = new LearningProblem(rs2, - // posExamples, negExamples); - - // test(learningProblem); - // test2(learningProblem); - - // createStatisticsMLDMPaper(learningProblem, baseDir); - // System.exit(0); - - if (useQueryMode) { - processQueryMode(reasoner); - } else { - if (Config.statisticMode) - ; // createStatistics(learningProblem, baseDir); - else { - - rs.resetStatistics(); - algorithmStartTime = System.nanoTime(); - - if (Config.algorithm == Algorithm.BRUTE_FORCE) { - LearningAlgorithmNew la = new BruteForceLearner(learningProblem, null); - la.start(); - } else if (Config.algorithm == Algorithm.RANDOM_GUESSER) { - // new RandomGuesser(learningProblem, 10000, 10); - } else if (Config.algorithm == Algorithm.GP - || Config.algorithm == Algorithm.HYBRID_GP) { - //LearningAlgorithm la = new GP(learningProblem); - //la.start(); - } else { - if (Config.Refinement.improveSubsumptionHierarchy) { - // if(Config.reasonerType == ReasonerType.DIG) { - System.out - .println("Subsumption Hierarchy is improved for Refinement Operator Based Algorithm"); - - - try { - reasoner.getSubsumptionHierarchy() - .improveSubsumptionHierarchy(); - // System.out.println(reasoner.getSubsumptionHierarchy()); - } catch (ReasoningMethodUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - // ((DIGReasoner)reasoner).improveSubsumptionHierarchy(); - // ((DIGReasoner)reasoner).printSubsumptionHierarchies(); - // } else { - // System.out.println("Subsumption Hierarchy not - // improved (support for selected reasoner not - // implemented)"); - // } - } - LearningAlgorithmNew la = new ROLearner(learningProblem, null); - la.start(); - // new ROLearner(learningProblem, learningProblem2); - } - - long algorithmDuration = System.nanoTime() - algorithmStartTime; - - if (rs.getNrOfRetrievals() > 0) { - System.out.println("number of retrievals: " + rs.getNrOfRetrievals()); - System.out.println("retrieval reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getRetrievalReasoningTimeNs()) + " ( " - + Helper.prettyPrintNanoSeconds(rs.getTimePerRetrievalNs()) - + " per retrieval)"); - } - if (rs.getNrOfInstanceChecks() > 0) { - System.out.println("number of instance checks: " - + rs.getNrOfInstanceChecks() + " (" - + rs.getNrOfMultiInstanceChecks() + " multiple)"); - System.out.println("instance check reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getInstanceCheckReasoningTimeNs()) - + " ( " - + Helper.prettyPrintNanoSeconds(rs - .getTimePerInstanceCheckNs()) - + " per instance check)"); - } - if (rs.getNrOfSubsumptionHierarchyQueries() > 0) { - System.out.println("subsumption hierarchy queries: " - + rs.getNrOfSubsumptionHierarchyQueries()); - /* - * System.out.println("subsumption hierarchy reasoning time: " + - * Helper.prettyPrintNanoSeconds(rs - * .getSubsumptionHierarchyTimeNs()) + " ( " + - * Helper.prettyPrintNanoSeconds(rs - * .getTimePerSubsumptionHierarchyQueryNs()) + " per - * subsumption hierachy query)"); - */ - } - if (rs.getNrOfSubsumptionChecks() > 0) { - System.out.println("(complex) subsumption checks: " - + rs.getNrOfSubsumptionChecks() + " (" - + rs.getNrOfMultiSubsumptionChecks() + " multiple)"); - System.out.println("subsumption reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getSubsumptionReasoningTimeNs()) - + " ( " - + Helper.prettyPrintNanoSeconds(rs - .getTimePerSubsumptionCheckNs()) - + " per subsumption check)"); - } - DecimalFormat df = new DecimalFormat(); - double reasoningPercentage = 100 * rs.getOverallReasoningTimeNs() - / (double) algorithmDuration; - System.out - .println("overall reasoning time: " - + Helper.prettyPrintNanoSeconds(rs - .getOverallReasoningTimeNs()) + " (" - + df.format(reasoningPercentage) - + "% of overall runtime)"); - System.out.println("overall algorithm runtime: " - + Helper.prettyPrintNanoSeconds(algorithmDuration)); - } - } - - // Aufräumarbeiten (TODO: das fehlt für KAON2 noch) - if (reasoner instanceof DIGReasoner) - ((DIGReasoner) reasoner).releaseKB(); - } - - // parst Funktionsaufrufe in Klassenvariablen - private void parseFunctionCalls(List<List<String>> functionCalls) { - // Funktionsaufrufe parsen - importedFiles = new HashMap<URL, OntologyFileFormat>(); - exportedFiles = new HashMap<File, OntologyFileFormat>(); - loadedJars = new LinkedList<File>(); - preprocessingModules = new LinkedList<String>(); - for (List<String> call : functionCalls) { - if(call.get(0).equals("import")) { - // alte Methode mit file statt URI - // File f = new File(baseDir, call.get(1)); - - URL url = null; - try { - String fileString = call.get(1); - if(fileString.startsWith("http:")) { - url = new URL(fileString); - } else { - File f = new File(baseDir, call.get(1)); - url = f.toURI().toURL(); - } - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - if (call.size() == 2) - // falls nichts angegeben, dann wird RDF/XML gewählt - importedFiles.put(url, OntologyFileFormat.RDF_XML); - else { - String formatString = call.get(2); - OntologyFileFormat format; - if (formatString.equals("RDF/XML")) - format = OntologyFileFormat.RDF_XML; - else - format = OntologyFileFormat.N_TRIPLES; - importedFiles.put(url, format); - } - } else if(call.get(0).equals("export")) { - File f = new File(baseDir, call.get(1)); - if (call.size() == 2) - // falls nichts angegeben, dann wird RDF/XML gewählt - exportedFiles.put(f, OntologyFileFormat.RDF_XML); - else { - String formatString = call.get(2); - OntologyFileFormat format; - if (formatString.equals("RDF/XML")) - format = OntologyFileFormat.RDF_XML; - else - format = OntologyFileFormat.N_TRIPLES; - exportedFiles.put(f, format); - } - } else if(call.get(0).equals("loadJarFile")) { - loadedJars.add(new File(call.get(1))); - } else if(call.get(0).equals("runPreprocessingModule")) { - preprocessingModules.add(call.get(1)); - } else { - System.out.println("Unknown function \"" + call.get(0) + "\". Exiting."); - System.exit(0); - } - } - } - - // Reasoning-Service erstellen - // TODO: überlegen, ob man die Methode nicht ev. auslagert, da sich Klassenvariablen - // mit Parametern überlappen - public static Reasoner createReasoner(KB kb, Map<URL, OntologyFileFormat> importedFiles) { - Reasoner reasoner = null; - if (Config.reasonerType == ReasonerType.KAON2) { - reasoner = new KAON2Reasoner(kb, importedFiles); - System.out.println("Reasoner: KAON2 (over Java API)"); - } else if (Config.reasonerType == ReasonerType.DIG) { - reasoner = new DIGReasoner(kb, Config.digReasonerURL, importedFiles); - System.out.println("Reasoner: " + ((DIGReasoner) reasoner).getIdentifier() - + " - connected via DIG 1.1 at " + Config.digReasonerURL); - } else if (Config.reasonerType == ReasonerType.FAST_RETRIEVAL) { - // erst KAON2-Reasoner erstellen um FlatABox zu erzeugen - if (Config.startUpReasoningType == ReasonerType.KAON2) { - Reasoner startUpReasoner = new KAON2Reasoner(kb, importedFiles); - // FlatABox abox; - try { - abox = createFlatABox(startUpReasoner); - } catch (ReasoningMethodUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - throw new Error( - "StartUpReasoner does not support all necessary reasoning methods."); - } - reasoner = new FastRetrievalReasoner(abox); - } else - throw new Error("Unsupported startup reasoner."); - } else { - throw new Error("Unsupported Reasoner"); - } - - // Reasoner.initializeReasoner(ReasonerType.KAON2,kb,importedFiles); - // ReasoningService reasoner = new ReasoningService(Config.reasonerType, - // Config.startUpReasoningType, kb, importedFiles); - // ReasoningService - // return new ReasoningService(reasoner); - return reasoner; - } - - /** - * Computes the set of allowed concepts based on configuration settings (also - * ignores anonymous and standard RDF, RDFS, OWL concept produces by Jena). - * - */ - public static void autoDetectConceptsAndRoles(ReasoningService rs) { - // einige Sachen, die momentan nur vom Refinement-Algorithmus - // unterstützt werden (später ev. auch von anderen Algorithmen) - //if (Config.algorithm == Algorithm.REFINEMENT) { - - // berechnen der verwendbaren Konzepte - if (Config.Refinement.allowedConceptsAutoDetect) { - // TODO: Code aus DIG-Reasoner-Klasse einfügen - - Set<AtomicConcept> allowedConceptsTmp = new TreeSet<AtomicConcept>( - new ConceptComparator()); - allowedConceptsTmp.addAll(rs.getAtomicConcepts()); - Iterator<AtomicConcept> it = allowedConceptsTmp.iterator(); - while (it.hasNext()) { - String conceptName = it.next().getName(); - // System.out.println(conceptName); - // seltsame anon-Konzepte, die von Jena erzeugt werden - // löschen - if (conceptName.startsWith("anon")) { - System.out - .println(" Ignoring concept " - + conceptName - + " (probably an anonymous concept produced by Jena when reading in OWL file)."); - it.remove(); - } else if (conceptName - .startsWith("http://www.w3.org/1999/02/22-rdf-syntax-ns#")) { - System.out - .println(" Ignoring concept " - + conceptName - + " (RDF construct produced by Jena when reading in OWL file)."); - it.remove(); - } else if (conceptName - .startsWith("http://www.w3.org/2000/01/rdf-schema#")) { - System.out - .println(" Ignoring concept " - + conceptName - + " (RDF Schema construct produced by Jena when reading in OWL file)."); - it.remove(); - } else if (conceptName.startsWith("http://www.w3.org/2002/07/owl#")) { - System.out - .println(" Ignoring concept " - + conceptName - + " (OWL construct produced by Jena when reading in OWL file)."); - it.remove(); - } - } - - // hier werden jetzt noch die zu ignorierenden Konzepte entfernt - if(Config.Refinement.ignoredConcepts != null) { - - - for(AtomicConcept ac : Config.Refinement.ignoredConcepts) { - boolean success = allowedConceptsTmp.remove(ac); - if(!success) { - System.out.println("Ignored concept " + ac + " does not exist in knowledge base."); - System.exit(0); - } - - } - } - - - Config.Refinement.allowedConcepts = allowedConceptsTmp; - } else { - // prüfen, ob nur verfügbare Konzepte vom Nutzer gewählt worden - Set<AtomicConcept> allowed = new HashSet<AtomicConcept>(); - allowed.addAll(Config.Refinement.allowedConcepts); - allowed.removeAll(rs.getAtomicConcepts()); - if (allowed.size() > 0) { - System.out - .println("Some of the concepts you told the learner to use in the definition, " - + "do not exist in the background knowledge: " - + allowed); - System.out.println("Please correct this problem and restart."); - System.exit(0); - } - } - - if (Config.Refinement.allowedRolesAutoDetect) { - Set<AtomicRole> allowedRolesTmp = rs.getAtomicRoles(); - - // hier werden jetzt noch die zu ignorierenden Rollen entfernt - if(Config.Refinement.ignoredRoles != null) { - - - for(AtomicRole ar : Config.Refinement.ignoredRoles) { - boolean success = allowedRolesTmp.remove(ar); - if(!success) { - System.out.println("Ignored role " + ar + " does not exist in knowledge base."); - System.exit(0); - } - - } - } - - Config.Refinement.allowedRoles = allowedRolesTmp; - - } else { - Set<AtomicRole> allowedR = new HashSet<AtomicRole>(); - allowedR.addAll(Config.Refinement.allowedRoles); - - Set<AtomicRole> existingR = new TreeSet<AtomicRole>(new RoleComparator()); - existingR.addAll(rs.getAtomicRoles()); - - // allowedR.removeAll(rs.getAtomicRoles()); - allowedR.removeAll(existingR); - - if (allowedR.size() > 0) { - System.out - .println("Some of the roles you told the learner to use in the definition, " - + "do not exist in the background knowledge: " - + allowedR); - System.out.println("Please correct this problem and restart."); - System.out.println(rs.getAtomicRoles()); - System.out.println(Config.Refinement.allowedRoles); - System.exit(0); - } - - } - } - - // Statistikerzeugung wird ausgelagert, damit im "normalen" Programm - // nichts ge�ndert werden muss -// private void createStatistics(LearningProblemNew learningProblem, String baseDir) { -// -// int runs = 20; -// LearningAlgorithm alg; -// -// Stat stat1 = new Stat(); -// Stat stat2 = new Stat(); -// Stat stat3 = new Stat(); -// // Stat stat4 = new Stat(); -// File exportFile1 = new File(baseDir, "../../stats/guesser.data"); -// File exportFile2 = new File(baseDir, "../../stats/gp1.data"); -// File exportFile3 = new File(baseDir, "../../stats/gp2.data"); -// // File exportFile4 = new File(baseDir, "../../stats/gp3.data"); -// StringBuilder exportString1 = new StringBuilder(); -// StringBuilder exportString2 = new StringBuilder(); -// StringBuilder exportString3 = new StringBuilder(); -// // StringBuilder exportString4 = new StringBuilder(); -// -// for (int i = 1000; i <= 30000; i += 2000) { -// stat1 = new Stat(); -// stat2 = new Stat(); -// stat3 = new Stat(); -// // stat4 = new Stat(); -// for (int run = 0; run < runs; run++) { -// System.out.println("============="); -// System.out.println("i " + i + " run " + run); -// System.out.println("============="); -// alg = new RandomGuesser(learningProblem, i, 6); -// stat1.addNumber(alg.getSolutionScore().getScore() - 0.1 -// * alg.getBestSolution().getLength()); -// -// Config.GP.numberOfIndividuals = i / 10; -// Config.GP.mutationProbability = 0.03f; -// Config.GP.crossoverProbability = 0.9f; -// Config.GP.hillClimbingProbability = 0.0f; -// alg = new GP(learningProblem); -// stat2.addNumber(alg.getSolutionScore().getScore() - 0.1 -// * alg.getBestSolution().getLength()); -// -// // wie GP 1, aber mit Hill Climbing -// Config.GP.crossoverProbability = 0.8f; -// Config.GP.hillClimbingProbability = 0.15f; -// alg = new GP(learningProblem); -// stat3.addNumber(alg.getSolutionScore().getScore() - 0.1 -// * alg.getBestSolution().getLength()); -// // stat.addNumber(((GP)alg).fittestIndividualGeneration); -// -// // wie GP 1, aber mit festem return type -// /* -// * Config.GP.crossoverProbability = 0.85f; -// * Config.GP.hillClimbingProbability = 0.0f; Config.returnType = -// * "male"; alg = new GP(); -// * stat4.addNumber(alg.getSolutionScore().getScore()-0.1*alg.getBestSolution().getConceptLength()); -// * Config.returnType = ""; -// */ -// -// } -// exportString1.append(i + " " + stat1.getMean() + " " -// + stat1.getStandardDeviation() + "\n"); -// exportString2.append(i + " " + stat2.getMean() + " " -// + stat2.getStandardDeviation() + "\n"); -// exportString3.append(i + " " + stat3.getMean() + " " -// + stat3.getStandardDeviation() + "\n"); -// // exportString4.append(i + " " + stat4.getMean() + " " + -// // stat4.getStandardDeviation() + "\n"); -// } -// -// createFile(exportFile1, exportString1.toString()); -// createFile(exportFile2, exportString2.toString()); -// createFile(exportFile3, exportString3.toString()); -// // createFile(exportFile4, exportString4.toString()); -// } - - // erzeugt Statistiken für MLDM-Paper zur Verarbeitung mit GnuPlot - // Vorsicht: Laufzeit von mehreren Stunden - @SuppressWarnings("unused") - private void createStatisticsMLDMPaper(PosNegDefinitionLP learningProblem, String baseDir) { - // Algorithmus 1: hybrid GP (100% refinement) - // Algorithmus 2: 50% refinement, 40% crossover, 1% mutation - // Algorithmus 3: 80% crossover, 2% mutation - - // Diagramm 1: Prozentzahl richtig klassifiziert - // Diagramm 2: Konzeptlänge - // Diagramm 3: Laufzeit - - int runs = 9; - GP gp; - int nrOfExamples = learningProblem.getPositiveExamples().size() - + learningProblem.getNegativeExamples().size(); - - Stat[][] statAr = new Stat[4][3]; - File[][] fileAr = new File[4][3]; - StringBuilder[][] exportString = new StringBuilder[4][3]; - // initialise export strings - for (int j = 0; j < 4; j++) { - for (int k = 0; k < 3; k++) { - exportString[j][k] = new StringBuilder(); - } - } - - fileAr[0][0] = new File(baseDir, "gnuplot/hybrid100classification.data"); - fileAr[0][1] = new File(baseDir, "gnuplot/hybrid100length.data"); - fileAr[0][2] = new File(baseDir, "gnuplot/hybrid100runtime.data"); - fileAr[1][0] = new File(baseDir, "gnuplot/hybrid50classification.data"); - fileAr[1][1] = new File(baseDir, "gnuplot/hybrid50length.data"); - fileAr[1][2] = new File(baseDir, "gnuplot/hybrid50runtime.data"); - fileAr[2][0] = new File(baseDir, "gnuplot/gpclassification.data"); - fileAr[2][1] = new File(baseDir, "gnuplot/gplength.data"); - fileAr[2][2] = new File(baseDir, "gnuplot/gpruntime.data"); - - // Extra-Test - fileAr[3][0] = new File(baseDir, "gnuplot/extraclassification.data"); - fileAr[3][1] = new File(baseDir, "gnuplot/extralength.data"); - fileAr[3][2] = new File(baseDir, "gnuplot/extraruntime.data"); - - ComponentManager cm = ComponentManager.getInstance(); - - long overallTimeStart = System.nanoTime(); - - // allgemeine Einstellungen - // Config.GP.elitism = true; - - for (int i = 700; i <= 700; i += 100) { - // initialise statistics array - for (int j = 0; j < 4; j++) { - for (int k = 0; k < 3; k++) { - statAr[j][k] = new Stat(); - } - } - - for (int run = 0; run < runs; run++) { - System.out.println("============="); - System.out.println("i " + i + " run " + run); - System.out.println("============="); - - // nur ein Test durchlaufen - for (int j = 0; j < 3; j++) { - - // Reasoner neu erstellen um Speicherprobleme zu vermeiden - reasoner = new DIGReasoner(kb, Config.digReasonerURL, importedFiles); - reasoner.prepareSubsumptionHierarchy(); - rs = new ReasoningService(reasoner); - // learningProblem = new LearningProblem(rs, posExamples, negExamples); - learningProblem = cm.learningProblem(PosNegDefinitionLP.class, rs); - cm.applyConfigEntry(learningProblem, "positiveExamples", posExamples); - cm.applyConfigEntry(learningProblem, "negativeExamples", negExamples); - - if (j == 0) { - Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0.85; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.05; - Config.GP.hillClimbingProbability = 0; - } else if (j == 1) { - Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0.4; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.4; - Config.GP.hillClimbingProbability = 0; - } else if (j == 2) { - Config.algorithm = Algorithm.GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.8; - Config.GP.hillClimbingProbability = 0; - } else if (j == 3) { - Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0.7; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.1; - Config.GP.hillClimbingProbability = 0; - } - - algorithmStartTime = System.nanoTime(); - gp = new GP(learningProblem); - long algorithmTime = System.nanoTime() - algorithmStartTime; - long algorithmTimeSeconds = algorithmTime / 1000000000; - - // Release, damit Pellet (hoffentlich) Speicher wieder - // freigibt - ((DIGReasoner) reasoner).releaseKB(); - - int conceptLength = gp.getBestSolution().getLength(); - Score bestScore = gp.getSolutionScore(); - int misClassifications = bestScore.getCoveredNegatives().size() - + bestScore.getNotCoveredPositives().size(); - double classificationRatePercent = 100 * ((nrOfExamples - misClassifications) / (double) nrOfExamples); - - statAr[j][0].addNumber(classificationRatePercent); - statAr[j][1].addNumber(conceptLength); - statAr[j][2].addNumber(algorithmTimeSeconds); - - } - } - - for (int j = 0; j < 3; j++) { - for (int k = 0; k < 3; k++) { - exportString[j][k].append(i + " " + statAr[j][k].getMean() + " " - + statAr[j][k].getStandardDeviation() + "\n"); - } - } - - // Daten werden nach jeder Populationserhöhung geschrieben, nicht - // nur - // am Ende => man kann den Test also auch zwischendurch abbrechen - for (int j = 0; j < 3; j++) { - for (int k = 0; k < 3; k++) { - Files.createFile(fileAr[j][k], exportString[j][k].toString()); - } - } - } - - long overallTime = System.nanoTime() - overallTimeStart; - System.out.println("\noverall time: " - + Helper.prettyPrintNanoSeconds(overallTime)); - } - - // TODO: query mode umschreiben - private void processQueryMode(Reasoner reasoner) { - - System.out - .println("Entering query mode. Enter a concept for performing retrieval or q to quit."); - String queryStr = ""; - do { - - System.out.print("enter query: "); // String einlesen - BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); - - // Eingabestring einlesen - try { - queryStr = input.readLine(); - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - if (!queryStr.equals("q")) { - - // Konzept parsen - Concept concept = null; - boolean parsedCorrectly = true; - - try { - concept = KBParser.parseConcept(queryStr); - } catch (ParseException e1) { - e1.printStackTrace(); - System.err - .println("The concept you entered could not be parsed. Please try again."); - parsedCorrectly = false; - } catch (TokenMgrError e) { - e.printStackTrace(); - System.err - .println("An error occured during parsing. Please enter a syntactically valid concept."); - parsedCorrectly = false; - } - - if (parsedCorrectly) { - // berechne im Konzept vorkommende atomare Rollen und - // Konzepte - SortedSet<AtomicConcept> occurringConcepts = new TreeSet<AtomicConcept>( - new ConceptComparator()); - occurringConcepts.addAll(Helper.getAtomicConcepts(concept)); - SortedSet<AtomicRole> occurringRoles = new TreeSet<AtomicRole>( - new RoleComparator()); - occurringRoles.addAll(Helper.getAtomicRoles(concept)); - - // ziehe davon die existierenden ab => die resultierenden - // Mengen - // sollten leer sein, ansonsten Fehler (der DIG-Reasoner - // fängt das - // leider nicht selbst ab) - // => momentan etwas umständlich gelöst, da es in Java bei - // removeAll darauf - // ankommt, dass die Argumentmenge den Comparator - // implementiert hat, was hier - // (noch) nicht der Fall ist - for (AtomicConcept ac : rs.getAtomicConcepts()) - occurringConcepts.remove(ac); - for (AtomicRole ar : rs.getAtomicRoles()) - occurringRoles.remove(ar); - - boolean nonExistingConstructs = false; - if (occurringConcepts.size() != 0 || occurringRoles.size() != 0) { - System.out - .println("You used non-existing atomic concepts or roles. Please correct your query."); - if (occurringConcepts.size() > 0) - System.out.println("non-existing concepts: " - + occurringConcepts); - if (occurringRoles.size() > 0) - System.out.println("non-existing roles: " + occurringRoles); - nonExistingConstructs = true; - } - - if (!nonExistingConstructs) { - // Retrieval stellen - Set<Individual> result = null; - try { - result = reasoner.retrieval(concept); - } catch (ReasoningMethodUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - System.out.println(result); - - Score score = learningProblem.computeScore(concept); - System.out.println(score); - - // feststellen, was zur Lösung noch fehlt - // Set<String> notCoveredPositives - } - } - } - - } while (!queryStr.equals("q")); - - /* - * String queryStr = ""; - * - * do { - * - * System.out.print("enter query: "); // String einlesen BufferedReader - * input = new BufferedReader(new InputStreamReader(System.in)); - * - * try { queryStr = input.readLine(); // queryStr.trim(); } catch - * (IOException e) { e.printStackTrace(); } - * - * if (!queryStr.equals("q")) { - * - * Predicate queryPredicate = null; boolean parseError = false; boolean - * showRole = false; ASTConcept conceptNode = null; // testen, ob es - * einem Rollennamen entspricht if (roles.containsKey(queryStr)) { - * queryPredicate = roles.get(queryStr); showRole = true; } else { // zu - * einer Konzeptbeschreibung vervollst�ndigen queryStr = "query = " + - * queryStr + "."; // String parsen SimpleNode queryNode = null; try { - * queryNode = DLLearner.parseString(queryStr); conceptNode = - * (ASTConcept) queryNode.jjtGetChild(0).jjtGetChild(1); queryPredicate = - * parseConcept(conceptNode); } catch (ParseException e) { - * System.out.println(e); // e.printStackTrace(); System.out - * .println("Exception encountered. Please enter a valid concept - * description or a role name."); parseError = true; } catch - * (TokenMgrError e2) { System.out.println(e2); System.out - * .println("Error encountered. Please enter a valid concept description - * or a role name."); parseError = true; } } - * - * if (!parseError) { // Kind ermitteln (Kind 0 ist "query", Kind 1 // - * "=", Kind // 2 Konzept) // Node conceptNode = // - * queryNode.jjtGetChild(0).jjtGetChild(1); // if (conceptNode - * instanceof ASTConcept) { // Description d = parseConcept((ASTConcept) // // - * conceptNode); // Query stellen List<String> results = new // - * LinkedList<String>(); Map<String, List<String>> resultMap = new - * HashMap<String, List<String>>(); try { query = - * reasoner.createQuery(queryPredicate); Object[] tupleBuffer = null; - * - * query.open(); while (!query.afterLast()) { tupleBuffer = - * query.tupleBuffer(); // .toString(); if (tupleBuffer.length == 1) - * results.add(tupleBuffer[0].toString()); else { String ind1 = - * tupleBuffer[0].toString(); String ind2 = tupleBuffer[1].toString(); - * List<String> l; if (!resultMap.containsKey(ind1)) l = new LinkedList<String>(); - * else l = resultMap.get(ind1); - * - * l.add(ind2); resultMap.put(ind1, l); } query.next(); } // Query an - * eigenen Algorithmus stellen if(!showRole) { org.dllearner.dl.Concept - * conceptOwn = parseConceptOwn(conceptNode); // Score score = - * conceptOwn.computeScore(); Score score = new Score(conceptOwn); - * System.out.println(score); System.out.println("positive (own - * algorithm): " + score.getDefPosSet()); System.out.println("negative - * (own algorithm): " + score.getDefNegSet()); } - * - * if (tupleBuffer == null || tupleBuffer.length <= 1) { - * System.out.println("KAON2: " + results); } else - * System.out.println(resultMap); query.close(); query.dispose(); } - * catch (KAON2Exception e) { e.printStackTrace(); } catch - * (InterruptedException e) { e.printStackTrace(); } // } else { // - * System.out.println("Please enter a concept."); // } } // String - * einlesen, String parsen => SimpleNode, falls // einzigstes Kind // - * kein Konzept ist, dann Abbruch; falls doch dann parsen // und // // - * zur�ckerhaltene // Description an Reasoner geben } } while - * (!queryStr.equals("q")); - */ - - /* - * String queryStr = ""; Query query; - * - * do { - * - * System.out.print("enter query: "); // String einlesen BufferedReader - * input = new BufferedReader(new InputStreamReader(System.in)); - * - * try { queryStr = input.readLine(); // queryStr.trim(); } catch - * (IOException e) { e.printStackTrace(); } - * - * if (!queryStr.equals("q")) { - * - * Predicate queryPredicate = null; boolean parseError = false; boolean - * showRole = false; ASTConcept conceptNode = null; // testen, ob es - * einem Rollennamen entspricht if (roles.containsKey(queryStr)) { - * queryPredicate = roles.get(queryStr); showRole = true; } else { // zu - * einer Konzeptbeschreibung vervollst�ndigen queryStr = "query = " + - * queryStr + "."; // String parsen SimpleNode queryNode = null; try { - * queryNode = DLLearner.parseString(queryStr); conceptNode = - * (ASTConcept) queryNode.jjtGetChild(0).jjtGetChild(1); queryPredicate = - * parseConcept(conceptNode); } catch (ParseException e) { - * System.out.println(e); // e.printStackTrace(); System.out - * .println("Exception encountered. Please enter a valid concept - * description or a role name."); parseError = true; } catch - * (TokenMgrError e2) { System.out.println(e2); System.out - * .println("Error encountered. Please enter a valid concept description - * or a role name."); parseError = true; } } - * - * if (!parseError) { // Kind ermitteln (Kind 0 ist "query", Kind 1 "=", - * Kind // 2 Konzept) // Node conceptNode = // - * queryNode.jjtGetChild(0).jjtGetChild(1); // if (conceptNode - * instanceof ASTConcept) { // Description d = parseConcept((ASTConcept) // - * conceptNode); // Query stellen List<String> results = new LinkedList<String>(); - * Map<String, List<String>> resultMap = new HashMap<String, List<String>>(); - * try { query = reasoner.createQuery(queryPredicate); Object[] - * tupleBuffer = null; - * - * query.open(); while (!query.afterLast()) { tupleBuffer = - * query.tupleBuffer(); // .toString(); if (tupleBuffer.length == 1) - * results.add(tupleBuffer[0].toString()); else { String ind1 = - * tupleBuffer[0].toString(); String ind2 = tupleBuffer[1].toString(); - * List<String> l; if (!resultMap.containsKey(ind1)) l = new LinkedList<String>(); - * else l = resultMap.get(ind1); - * - * l.add(ind2); resultMap.put(ind1, l); } query.next(); } // Query an - * eigenen Algorithmus stellen if(!showRole) { org.dllearner.dl.Concept - * conceptOwn = parseConceptOwn(conceptNode); // Score score = - * conceptOwn.computeScore(); Score score = new Score(conceptOwn); - * System.out.println(score); System.out.println("positive (own - * algorithm): " + score.getDefPosSet()); System.out.println("negative - * (own algorithm): " + score.getDefNegSet()); } - * - * if (tupleBuffer == null || tupleBuffer.length <= 1) { - * System.out.println("KAON2: " + results); } else - * System.out.println(resultMap); query.close(); query.dispose(); } - * catch (KAON2Exception e) { e.printStackTrace(); } catch - * (InterruptedException e) { e.printStackTrace(); } // } else { // - * System.out.println("Please enter a concept."); // } } // String - * einlesen, String parsen => SimpleNode, falls // einzigstes Kind // - * kein Konzept ist, dann Abbruch; falls doch dann parsen // und // - * zur�ckerhaltene // Description an Reasoner geben } } while - * (!queryStr.equals("q")); - */ - } - - // Funktion wird nicht mehr ben�tigt - /* - * private File searchImports(Node rootNode, String baseDir) { // es wird - * zuerst nach einer import-Anweisung gesucht // boolean importKB = false; - * File importedFile = null; for (int i = 0; i < - * rootNode.jjtGetNumChildren(); i++) { if (rootNode.jjtGetChild(i) - * instanceof ASTFunctionCall) { Node functionCall = (ASTFunctionCall) - * rootNode.jjtGetChild(i); String function = ((ASTId) - * functionCall.jjtGetChild(0)).getId(); if (function.equals("import")) { - * String importFile = ""; importFile = ((ASTString) - * functionCall.jjtGetChild(1)).getId(); // Anf�hrungszeichen im String - * wegschneiden importFile = importFile.substring(1, importFile.length() - - * 1); importedFile = new File(baseDir, importFile); // importKB = true; } } } - * return importedFile; } - */ - - // VERALTET - /* - * private void handleReturnType(Ontology ontology) { // es wird eine Regel: - * "zielkonzept SUBCLASS r�ckgabetyp" zur Ontologie // hinzugef�gt // TODO: - * es muss noch gepr�ft werden was bei Inkosistenz mit pos. bzw. // - * negativen Beispiel passiert // Problem: diese Implementierungsvariante - * bringt leider nichts, da der // einfache DL-Algorithmus daraus keinen - * Nutzen zieht (au�erdem kann ein // Nutzer falls er m�chte einfach so eine - * Regel in die Konf.datei // schreiben) FlatABox abox = - * FlatABox.getInstance(); String subClass = abox.getTargetConcept() + " - * SUBCLASS " + Config.returnType; Description d2 = null; try { d2 = - * parseConcept((ASTConcept) - * DLLearner.parseString(subClass).jjtGetChild(1)); } catch (ParseException - * e) { System.err.println("Cannot parse return type."); - * e.printStackTrace(); System.exit(0); } Description d1 = - * getConcept(abox.getTargetConcept()); - * - * List<OntologyChangeEvent> changes = new ArrayList<OntologyChangeEvent>(); - * changes.add(new OntologyChangeEvent(KAON2Manager.factory().subClassOf(d1, - * d2), OntologyChangeEvent.ChangeType.ADD)); - * - * try { ontology.applyChanges(changes); } catch (KAON2Exception e) { - * System.err.println("Error in handling return type " + Config.returnType + - * "."); e.printStackTrace(); System.exit(0); } } - */ - - /* - * private static OWLClass getConcept(String name) { if - * (!concepts.containsKey(name)) { concepts.put(name, - * KAON2Manager.factory().owlClass(name)); } return concepts.get(name); } - * - * private static ObjectProperty getRole(String name) { if - * (!roles.containsKey(name)) { roles.put(name, - * KAON2Manager.factory().objectProperty(name)); } return roles.get(name); } - * - * public static Individual getIndividual(String name) { if - * (!individuals.containsKey(name)) { individuals.put(name, - * KAON2Manager.factory().individual(name)); } return individuals.get(name); } - */ - - // die Methode muss private bleiben - private static FlatABox createFlatABox(Reasoner reasoner) - throws ReasoningMethodUnsupportedException { - long dematStartTime = System.currentTimeMillis(); - - FlatABox aBox = new FlatABox(); // FlatABox.getInstance(); - for (AtomicConcept atomicConcept : reasoner.getAtomicConcepts()) { - aBox.atomicConceptsPos.put(atomicConcept.getName(), Helper - .getStringSet(reasoner.retrieval(atomicConcept))); - Negation negatedAtomicConcept = new Negation(atomicConcept); - aBox.atomicConceptsNeg.put(atomicConcept.getName(), Helper - .getStringSet(reasoner.retrieval(negatedAtomicConcept))); - aBox.concepts.add(atomicConcept.getName()); - } - - for (AtomicRole atomicRole : reasoner.getAtomicRoles()) { - aBox.rolesPos.put(atomicRole.getName(), Helper.getStringMap(reasoner - .getRoleMembers(atomicRole))); - aBox.roles.add(atomicRole.getName()); - } - - aBox.domain = Helper.getStringSet(reasoner.getIndividuals()); - aBox.top = aBox.domain; - // ab hier keine �nderungen mehr an FlatABox - aBox.prepare(); - - // System.out.println(aBox); - - long dematDuration = System.currentTimeMillis() - dematStartTime; - System.out.println("OK (" + dematDuration + " ms)"); - return aBox; - } - - // gibt M�glickeit flat Abox zu bekommen, falls eine erzeugt wurde - // (wird momentan nur f�r hill climbing ben�tigt und es ist sauberer diese - // hier - // zu erzeugen und bekommen als die ReasoningService-Klasse zu hacken) - public static FlatABox getFlatAbox() { - return abox; - } - - // generiert sibling aus Forte-Daten - @SuppressWarnings("unused") - private void test2(PosNegLP learningProblem) { - // Set<AtomicRole> roles = reasoner.getAtomicRoles(); - // for(AtomicRole role : roles) { - // System.out.println(rs.getRoleMembers(role)); - // } - /* - * AtomicRole sibling = new AtomicRole("sibling"); Map<String,SortedSet<String>> - * members = rs.getRoleMembers(sibling); for(String name : - * members.keySet()) { SortedSet<String> fillers = members.get(name); - * for(String filler : fillers) { - * System.out.println("sibling("+name+","+filler+")."); } } - */ - Concept c = null; - try { - c = KBParser.parseConcept("EXISTS uncle.TOP"); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Set<Individual> uncles = rs.retrieval(c); - Set<Individual> inds = rs.getIndividuals(); - for (Individual ind : uncles) - System.out.println("+isUncle(" + ind + ")."); - inds.removeAll(uncles); - for (Individual ind : inds) - System.out.println("-isUncle(" + ind + ")."); - - System.exit(0); - } - - public static long getAlgorithmStartTime() { - return algorithmStartTime; - } - - // die Methode soll alle Konzeptzusicherungen und Rollenzusicherungen von - // Individuen entfernen, die mit diesem Individuum verbunden sind - @SuppressWarnings("unused") - private void removeIndividualSubtree(KB kb, Individual individual) { - System.out.println(); - // erster Schritt: alle verbundenen Individuen finden - Set<Individual> connectedIndividuals = kb.findRelatedIndividuals(individual); - System.out.println("connected individuals: " + connectedIndividuals); - // Individual selbst auch entfernen - connectedIndividuals.add(individual); - - // zweiter Schritt: entfernen von Rollen- und Konzeptzusicherungen - Set<AssertionalAxiom> abox = kb.getAbox(); - Iterator<AssertionalAxiom> it = abox.iterator(); - while (it.hasNext()) { - AssertionalAxiom a = it.next(); - if (a instanceof RoleAssertion) { - RoleAssertion ra = (RoleAssertion) a; - if (connectedIndividuals.contains(ra.getIndividual1()) - || connectedIndividuals.contains(ra.getIndividual2())) { - System.out.println("remove " + ra); - it.remove(); - } - } else if (a instanceof ConceptAssertion) { - if (connectedIndividuals.contains(((ConceptAssertion) a).getIndividual())) { - System.out.println("remove " + a); - it.remove(); - } - } else - throw new RuntimeException(); - } - - Set<Individual> inds = kb.findAllIndividuals(); - System.out.println("remaining individuals: " + inds); - System.out.println(); - } - - public static ConfigurationManager getConfMgr() { - return confMgr; - } - -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-07 16:35:12 UTC (rev 173) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-07 18:00:21 UTC (rev 174) @@ -8,8 +8,8 @@ import java.util.TreeMap; import org.dllearner.Config; -import org.dllearner.Main; import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.Score; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -340,7 +340,14 @@ Score tmpScore; SortedSetTuple<String> tmp, tmp2; // FlatABox abox = ((FastRetrievalReasoner)learningProblem.getReasoner().getFastRetrieval().getAbox(); - FlatABox abox = Main.getFlatAbox(); + // FlatABox abox = Main.getFlatAbox(); + FlatABox abox = null; + try { + abox = Helper.createFlatABox(learningProblem.getReasoningService()); + } catch (ReasoningMethodUnsupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } // TODO: testen, ob aktuelles Konzept zu speziell bzw. allgemein ist; // dann kann man das effizienter implementieren Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-07 16:35:12 UTC (rev 173) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-07 18:00:21 UTC (rev 174) @@ -11,7 +11,6 @@ import java.util.TreeSet; import org.dllearner.Config; -import org.dllearner.Main; import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; @@ -243,7 +242,7 @@ @Override public void init() { // TODO: this needs to be changed - Main.autoDetectConceptsAndRoles(rs); + Helper.autoDetectConceptsAndRoles(rs); // prepare subsumption and role hierarchies, because they are needed // during the run of the algorithm rs.prepareSubsumptionHierarchy(); Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-07 16:35:12 UTC (rev 173) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-07 18:00:21 UTC (rev 174) @@ -19,15 +19,20 @@ */ package org.dllearner.cli; +import java.io.BufferedReader; import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import java.text.DecimalFormat; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; @@ -42,22 +47,31 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithmNew; import org.dllearner.core.LearningProblem; +import org.dllearner.core.Reasoner; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; +import org.dllearner.core.Score; import org.dllearner.core.StringConfigOption; import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; +import org.dllearner.kb.OntologyFileFormat; import org.dllearner.kb.SparqlEndpoint; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.parser.ConfParser; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.parser.TokenMgrError; import org.dllearner.reasoning.DIGReasonerNew; +import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.Helper; +import org.dllearner.utilities.RoleComparator; /** * Startup file for Command Line Interface. @@ -140,6 +154,9 @@ initComponent(cm, lp); initComponent(cm, la); + // perform file exports + performExports(parser, baseDir, rs); + // show examples (display each one if they do not take up much space, // otherwise just show the number of examples) boolean oneLineExampleInfo = true; @@ -163,7 +180,11 @@ processCLIOptions(cm, parser, rs); // start algorithm + long algStartTime = System.nanoTime(); la.start(); + long algDuration = System.nanoTime() - algStartTime; + + printConclusions(rs, algDuration); } // creates a mapping from components to option prefix strings @@ -180,6 +201,10 @@ return componentPrefixMapping; } + // convenience method + // basically every prefix (e.g. "refinement" in "refinement.horizontalExpFactor) + // corresponds to a specific component - this way the CLI will automatically + // support any configuration options supported by the component private static void configureComponent(ComponentManager cm, Component component, Map<Class<? extends Component>, String> componentPrefixMapping, ConfParser parser) { String prefix = componentPrefixMapping.get(component.getClass()); @@ -187,6 +212,7 @@ configureComponent(cm, component, parser.getConfOptionsByPrefix(prefix)); } + // convenience method - see above method private static void configureComponent(ComponentManager cm, Component component, List<ConfFileOption> options) { if (options != null) @@ -19... [truncated message content] |
From: <jen...@us...> - 2007-10-08 08:31:03
|
Revision: 176 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=176&view=rev Author: jenslehmann Date: 2007-10-08 01:30:59 -0700 (Mon, 08 Oct 2007) Log Message: ----------- - preliminary adaption of all reasoning algorithms to new structure - refactored LearningAlgorithmNew to LearningAlgorithm and DIGReasonerNew to DIGReasoner Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -11,7 +11,7 @@ import org.dllearner.core.ConfigOption; import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; @@ -34,7 +34,7 @@ * @author Jens Lehmann * */ -public class BruteForceLearner extends LearningAlgorithmNew { +public class BruteForceLearner extends LearningAlgorithm { LearningProblem learningProblem; Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-10-08 08:30:59 UTC (rev 176) @@ -28,13 +28,13 @@ import org.dllearner.core.ConfigOption; import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; -public class RandomGuesser extends LearningAlgorithmNew { +public class RandomGuesser extends LearningAlgorithm { private Concept bestDefinition = null; private Score bestScore; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-08 08:30:59 UTC (rev 176) @@ -50,7 +50,7 @@ import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; @@ -65,7 +65,7 @@ * @author Jens Lehmann * */ -public class GP extends LearningAlgorithmNew { +public class GP extends LearningAlgorithm { // NumberFormat f; DecimalFormat df = new DecimalFormat("0.00"); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -14,7 +14,7 @@ import org.dllearner.core.ConfigEntry; import org.dllearner.core.ConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; @@ -28,7 +28,7 @@ import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; -public class ROLearner extends LearningAlgorithmNew { +public class ROLearner extends LearningAlgorithm { private boolean stop = false; Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 08:30:59 UTC (rev 176) @@ -45,7 +45,7 @@ import org.dllearner.core.IntegerConfigOption; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.LearningAlgorithmNew; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasonerComponent; @@ -67,7 +67,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.parser.TokenMgrError; -import org.dllearner.reasoning.DIGReasonerNew; +import org.dllearner.reasoning.DIGReasoner; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.Helper; @@ -121,7 +121,7 @@ Class<? extends ReasonerComponent> reasonerClass = null; // default value if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) - reasonerClass = DIGReasonerNew.class; + reasonerClass = DIGReasoner.class; else { handleError("Unknown value " + reasonerOption.getStringValue() + "for option \"reasoner\"."); @@ -139,8 +139,8 @@ // step 4: detect learning algorithm ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); - LearningAlgorithmNew la = null; - Class<? extends LearningAlgorithmNew> laClass = null; + LearningAlgorithm la = null; + Class<? extends LearningAlgorithm> laClass = null; if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) laClass = ROLearner.class; @@ -193,7 +193,7 @@ // knowledge sources componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); // reasoners - componentPrefixMapping.put(DIGReasonerNew.class, "digReasoner"); + componentPrefixMapping.put(DIGReasoner.class, "digReasoner"); // learning problems - configured via + and - flags for examples // learning algorithms componentPrefixMapping.put(ROLearner.class, "refinement"); @@ -446,8 +446,8 @@ String message = "OK"; if (component instanceof KBFile) message = ((KBFile) component).getURL().toString() + " read"; - else if (component instanceof DIGReasonerNew) { - DIGReasonerNew reasoner = (DIGReasonerNew) component; + else if (component instanceof DIGReasoner) { + DIGReasoner reasoner = (DIGReasoner) component; message = "using " + reasoner.getIdentifier() + " connected via DIG 1.1 at " + reasoner.getReasonerURL().toString(); } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-10-08 08:30:59 UTC (rev 176) @@ -63,13 +63,13 @@ private static Set<Class<? extends KnowledgeSource>> knowledgeSources; private static Set<Class<? extends ReasonerComponent>> reasonerComponents; private static Set<Class<? extends LearningProblem>> learningProblems; - private static Set<Class<? extends LearningAlgorithmNew>> learningAlgorithms; + private static Set<Class<? extends LearningAlgorithm>> learningAlgorithms; // list of all configuration options of all components private static Map<Class<? extends Component>, String> componentNames; private static Map<Class<? extends Component>, List<ConfigOption<?>>> componentOptions; private static Map<Class<? extends Component>, Map<String, ConfigOption<?>>> componentOptionsByName; - private static Map<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblem>>> algorithmProblemsMapping; + private static Map<Class<? extends LearningAlgorithm>, Collection<Class<? extends LearningProblem>>> algorithmProblemsMapping; private Comparator<Class<?>> classComparator = new Comparator<Class<?>>() { @@ -89,8 +89,8 @@ knowledgeSources = new TreeSet<Class<? extends KnowledgeSource>>(classComparator); reasonerComponents = new TreeSet<Class<? extends ReasonerComponent>>(classComparator); learningProblems = new TreeSet<Class<? extends LearningProblem>>(classComparator); - learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithmNew>>(classComparator); - algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithmNew>, Collection<Class<? extends LearningProblem>>>( + learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithm>>(classComparator); + algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithm>, Collection<Class<? extends LearningProblem>>>( classComparator); // create classes from strings @@ -106,8 +106,8 @@ reasonerComponents.add((Class<? extends ReasonerComponent>) component); else if (LearningProblem.class.isAssignableFrom(component)) learningProblems.add((Class<? extends LearningProblem>) component); - else if (LearningAlgorithmNew.class.isAssignableFrom(component)) { - Class<? extends LearningAlgorithmNew> learningAlgorithmClass = (Class<? extends LearningAlgorithmNew>) component; + else if (LearningAlgorithm.class.isAssignableFrom(component)) { + Class<? extends LearningAlgorithm> learningAlgorithmClass = (Class<? extends LearningAlgorithm>) component; learningAlgorithms.add(learningAlgorithmClass); Collection<Class<? extends LearningProblem>> problems = (Collection<Class<? extends LearningProblem>>) invokeStaticMethod( learningAlgorithmClass, "supportedLearningProblems"); @@ -297,7 +297,7 @@ } // automagically calls the right constructor for the given learning problem - public <T extends LearningAlgorithmNew> T learningAlgorithm(Class<T> la, LearningProblem lp, ReasoningService rs) { + public <T extends LearningAlgorithm> T learningAlgorithm(Class<T> la, LearningProblem lp, ReasoningService rs) { if (!learningAlgorithms.contains(la)) System.err.println("Warning: learning algorithm " + la + " is not a registered learning algorithm component."); Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-10-08 08:30:59 UTC (rev 176) @@ -26,7 +26,7 @@ import org.dllearner.algorithms.RandomGuesser; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.reasoning.DIGReasonerNew; +import org.dllearner.reasoning.DIGReasoner; /** * Test for component based design. @@ -53,7 +53,7 @@ source.init(); // create DIG reasoning service with standard settings - ReasonerComponent reasoner = cm.reasoner(DIGReasonerNew.class, source); + ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); ReasoningService rs = cm.reasoningService(reasoner); reasoner.init(); @@ -73,7 +73,7 @@ lp.init(); // create the learning algorithm - LearningAlgorithmNew la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); + LearningAlgorithm la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); cm.applyConfigEntry(la, "numberOfTrees", 100); cm.applyConfigEntry(la, "maxDepth", 5); la.init(); Copied: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java (from rev 166, trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2007-10-08 08:30:59 UTC (rev 176) @@ -0,0 +1,66 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import java.util.Collection; +import java.util.LinkedList; + +import org.dllearner.core.dl.Concept; + +/** + * @author Jens Lehmann + * + */ +public abstract class LearningAlgorithm extends Component { + + /** + * Starts the algorithm. + * + */ + public abstract void start(); + + + /** + * Stops the algorithm gracefully. + * + */ + public abstract void stop(); + + /** + * Every algorithm must be able to return the score of the + * best solution found. + * @return Best score. + */ + public abstract Score getSolutionScore(); + + /** + * Returns the best solutions obtained so far. + * @return Best solution. + */ + public abstract Concept getBestSolution(); + + /** + * Returns all learning problems supported by this component. + */ + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { + return new LinkedList<Class<? extends LearningProblem>>(); + } + +} Deleted: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithmNew.java 2007-10-08 08:30:59 UTC (rev 176) @@ -1,66 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.core; - -import java.util.Collection; -import java.util.LinkedList; - -import org.dllearner.core.dl.Concept; - -/** - * @author Jens Lehmann - * - */ -public abstract class LearningAlgorithmNew extends Component { - - /** - * Starts the algorithm. - * - */ - public abstract void start(); - - - /** - * Stops the algorithm gracefully. - * - */ - public abstract void stop(); - - /** - * Every algorithm must be able to return the score of the - * best solution found. - * @return Best score. - */ - public abstract Score getSolutionScore(); - - /** - * Returns the best solutions obtained so far. - * @return Best solution. - */ - public abstract Concept getBestSolution(); - - /** - * Returns all learning problems supported by this component. - */ - public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { - return new LinkedList<Class<? extends LearningProblem>>(); - } - -} Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-08 08:30:59 UTC (rev 176) @@ -36,7 +36,6 @@ import org.dllearner.core.dl.SubsumptionHierarchy; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.reasoning.DIGReasonerNew; import org.dllearner.reasoning.KAON2Reasoner; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.SortedSetTuple; @@ -414,7 +413,7 @@ } else if (getReasonerType() == ReasonerType.DIG) { // DIG erzeugt momentan auch nur einen KAON2-Reasoner und // exportiert dann mit der obigen Funktion - ((DIGReasonerNew) reasoner).saveOntology(file, format); + ((DIGReasoner) reasoner).saveOntology(file, format); } } Deleted: trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/reasoning/AbstractReasoner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -1,110 +0,0 @@ -package org.dllearner.reasoning; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.Reasoner; -import org.dllearner.core.ReasoningMethodUnsupportedException; -import org.dllearner.core.dl.AtomicConcept; -import org.dllearner.core.dl.AtomicRole; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.RoleHierarchy; -import org.dllearner.core.dl.SubsumptionHierarchy; -import org.dllearner.utilities.SortedSetTuple; - -public abstract class AbstractReasoner implements Reasoner { - - public boolean subsumes(Concept superConcept, Concept subConcept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<Concept> subsumes(Concept superConcept, Set<Concept> subConcepts) throws ReasoningMethodUnsupportedException { - Set<Concept> returnSet = new HashSet<Concept>(); - for(Concept subConcept : subConcepts) { - if(subsumes(superConcept,subConcept)) - returnSet.add(subConcept); - } - return returnSet; - } - - public Set<Concept> subsumes(Set<Concept> superConcepts, Concept subConcept) throws ReasoningMethodUnsupportedException { - Set<Concept> returnSet = new HashSet<Concept>(); - for(Concept superConcept : superConcepts) { - if(subsumes(superConcept,subConcept)) - returnSet.add(superConcept); - } - return returnSet; - } - - public SortedSet<Individual> retrieval(Concept concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public boolean instanceCheck(Concept concept, Individual individual) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSet<Individual> instanceCheck(Concept concept, Set<Individual> individuals) throws ReasoningMethodUnsupportedException { - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - for(Individual individual : individuals) { - if(instanceCheck(concept,individual)) - returnSet.add(individual); - } - return returnSet; - } - - public SortedSetTuple<Individual> doubleRetrieval(Concept concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSetTuple<Individual> doubleRetrieval(Concept concept, Concept adc) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public boolean isSatisfiable() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - /* - public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - */ - - public SubsumptionHierarchy getSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public void prepareRoleHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public RoleHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<AtomicConcept> getConcepts(Individual i) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 08:17:31 UTC (rev 175) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -1,749 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -package org.dllearner.reasoning; - -import java.io.File; -import java.net.URI; -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import javax.xml.namespace.QName; - -import org.apache.xmlbeans.XmlCursor; -import org.dllearner.Config; -import org.dllearner.core.dl.AtomicConcept; -import org.dllearner.core.dl.AtomicRole; -import org.dllearner.core.dl.Bottom; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.KB; -import org.dllearner.core.dl.RoleHierarchy; -import org.dllearner.core.dl.SubsumptionHierarchy; -import org.dllearner.core.dl.Top; -import org.dllearner.kb.OntologyFileFormat; -import org.dllearner.utilities.ConceptComparator; -import org.dllearner.utilities.Helper; -import org.dllearner.utilities.RoleComparator; -import org.kr.dl.dig.v1_1.Concepts; -import org.kr.dl.dig.v1_1.Csynonyms; -import org.kr.dl.dig.v1_1.IdType; -import org.kr.dl.dig.v1_1.Named; -import org.kr.dl.dig.v1_1.ResponseDocument; -import org.kr.dl.dig.v1_1.ResponsesDocument; -import org.kr.dl.dig.v1_1.Roles; -import org.kr.dl.dig.v1_1.Rsynonyms; -import org.kr.dl.dig.v1_1.IndividualSetDocument.IndividualSet; - -/** - * DIG 1.1 implementation of the reasoner interface. - * - * @author Jens Lehmann - * - */ -public class DIGReasoner extends AbstractReasoner { - - // Variablen für Reasoner - DIGHTTPConnector connector; - String identifier; - URI kbURI; - private String asksPrefix; - Map<URL,OntologyFileFormat> imports; - KB kb; - // Cache für Konzepte, Rollen und Individuen - Set<AtomicConcept> atomicConcepts; - Set<AtomicRole> atomicRoles; - SortedSet<Individual> individuals; - - // Cache für Subsumptionhierarchie - // Comparator ist notwendig, da sonst z.B. verschiedene Instanzen des atomaren Konzepts male - // unterschiedlich sind; - // alternativ wäre auch eine Indizierung über Strings möglich - ConceptComparator conceptComparator = new ConceptComparator(); - RoleComparator roleComparator = new RoleComparator(); - SubsumptionHierarchy subsumptionHierarchy; - RoleHierarchy roleHierarchy; - // enthält atomare Konzepte, sowie Top und Bottom - Set<Concept> allowedConceptsInSubsumptionHierarchy; - - /** - * Creates a DIG reasoner object. - * - * @param kb Internal knowledge base. - * @param url URL of the DIG reasoner e.g. http://localhost:8081. - * @param imports Files to import (format and physical location of each file). - */ - public DIGReasoner(KB kb, URL url, Map<URL,OntologyFileFormat> imports) { - this.imports = imports; - this.kb = kb; - connector = new DIGHTTPConnector(url); - identifier = connector.getIdentifier(); - kbURI = connector.newKB(); - - // asks-Prefix entsprechend der KB-URI initialisieren - asksPrefix = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; - asksPrefix += "<asks xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + - "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + - "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"; - - // erzeuge tell-Anfrage für Knowledgebase - if(kb.getNumberOfAxioms()>0) { - StringBuilder sb = new StringBuilder(); - sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); - sb.append("<tells xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + - "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + - "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); - sb.append(DIGConverter.getDIGString(kb)); - sb.append("</tells>"); - - ResponseDocument rd = connector.tells(sb.toString()); - if(!rd.getResponse().isSetOk()) { - System.err.println("DIG-Reasoner cannot read knowledgebase."); - System.exit(0); - } - } - - String importDIGString = ""; - - // Ontologien mit Hilfe von KAON2 importieren - direkt zur - // KB hinzufügen - for(URL file : imports.keySet()) { - /* - // System.out.println("Importing " + file + " using KAON2."); - Ontology ontology = KAON2Reasoner.importKB(file); - try { - KAON2Reasoner.importKAON2Ontology(kb, ontology); - } catch (KAON2Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - */ - - // mit Hilfe von Jena wird OWL zu DIG konvertiert - // (allein diese Funktion sorgt leider dafür, dass - // DL-Learner stark anwächst, da verschieden Jena-Bibliotheken - // eingebunden werden müssen) - long importStartTime = System.currentTimeMillis(); - - // if the ontology format is N-Triples then Jena is used, otherwise the OWL API - if(imports.get(file).equals(OntologyFileFormat.N_TRIPLES)) { - System.out.print("Converting import file " + file + " to DIG using Jena ... "); - - importDIGString = JenaOWLDIGConverter.getTellsString(file, imports.get(file), kbURI); - } else { - System.out.println("Converting import file " + file + " to DIG using OWL API:"); - - importDIGString = OWLAPIDIGConverter.getTellsString(file, imports.get(file), kbURI); - } - - ResponseDocument rdImport = connector.tells(importDIGString); - if(!rdImport.getResponse().isSetOk()) { - System.err.println("DIG-Reasoner cannot read knowledgebase."); - System.exit(0); - } else { - long importTime = System.currentTimeMillis() - importStartTime; - if(imports.get(file).equals(OntologyFileFormat.N_TRIPLES)) - System.out.println("OK (" + importTime + " ms)"); - // (" + JenaOWLDIGConverter.nrOfStatementsLastConversion + " statements, "+ importTime + " ms)"); - - } - - } - - // es wird jetzt immer der DIG-Reasoner abgefragt (auch ohne Importe), - // da so gleich auch äquivalente Konzepte rausgefiltert werden - - - - // DIG-Abfragen nach Konzepten, Rollen, Individuals - atomicConcepts = getAtomicConceptsDIG(); - atomicRoles = getAtomicRolesDIG(); - individuals = getIndividualsDIG(); - - } - - /** - * Construct a subsumption hierarchy using DIG queries. After calling this - * method one can ask for children or parents in the subsumption hierarchy. - */ - public void prepareSubsumptionHierarchy() { - allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); - allowedConceptsInSubsumptionHierarchy.addAll(Config.Refinement.allowedConcepts); - allowedConceptsInSubsumptionHierarchy.add(new Top()); - allowedConceptsInSubsumptionHierarchy.add(new Bottom()); - - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - - // Subsumptionhierarchy berechnen - // TODO: kann man effizienter auch in einer Abfrage machen - - // Refinements von Top - TreeSet<Concept> tmp = getMoreSpecialConceptsDIG(new Top()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(new Top(), tmp); - - // Refinements von Bottom - tmp = getMoreGeneralConceptsDIG(new Bottom()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(new Bottom(), tmp); - - // Refinement atomarer Konzepte - for(AtomicConcept atom : atomicConcepts) { - tmp = getMoreSpecialConceptsDIG(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(atom, tmp); - - tmp = getMoreGeneralConceptsDIG(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(atom, tmp); - } - - subsumptionHierarchy = new SubsumptionHierarchy(Config.Refinement.allowedConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); - } - - /** - * Constructs a role hierarchy using DIG queries. After calling this method, - * one can query parents or children of roles. - * - * @todo Does not yet take ignored roles into account. - */ - @Override - public void prepareRoleHierarchy() { - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); - TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); - - // Refinement atomarer Konzepte - for(AtomicRole role : atomicRoles) { - roleHierarchyDown.put(role, getMoreSpecialRolesDIG(role)); - roleHierarchyUp.put(role, getMoreGeneralRolesDIG(role)); - } - - roleHierarchy = new RoleHierarchy(Config.Refinement.allowedRoles, roleHierarchyUp, roleHierarchyDown); - } - - // eigentlich müsste man klonen um sicherzustellen, dass der parent-Link - // bei null bleibt; bei der aktuellen Implementierung ist der parent-Link - // nicht immer null, was bei GP negative Auswirkungen haben könnte - // Update: wird durch klonen innerhalb der GP-Operationen erledigt - public Set<AtomicConcept> getAtomicConcepts() { - /* - if(Config.algorithm == Config.Algorithm.GP || Config.algorithm == Config.Algorithm.HYBRID_GP) { - Set<AtomicConcept> returnSet = new HashSet<AtomicConcept>(); - for(AtomicConcept ac : atomicConcepts) - returnSet.add((AtomicConcept)ac.clone()); - return returnSet; - } - */ - return atomicConcepts; - } - - private Set<AtomicConcept> getAtomicConceptsDIG() { - String atomicConceptsDIG = asksPrefix; - atomicConceptsDIG += "<allConceptNames id=\"ask_names\"/></asks>"; - - ResponsesDocument rd = connector.asks(atomicConceptsDIG); - // Struktur: einzelnes conceptSet außen, dann mehrere synonyms, die dann - // die Konzept inkl. Top und Bottom enthalten - Csynonyms[] synonymsArray = rd.getResponses().getConceptSetArray(); - Concepts[] conceptsArray = synonymsArray[0].getSynonymsArray(); - - Set<AtomicConcept> atomicConcepts = new TreeSet<AtomicConcept>(conceptComparator); - for(Concepts concepts : conceptsArray) { - boolean topOrBottomFound = false; - if(concepts.getBottomArray().length != 0 || concepts.getTopArray().length!=0) - topOrBottomFound = true; - - // nur weitersuchen falls das Konzept nicht äquivalent zu Top - // oder Bottom ist - if(!topOrBottomFound) { - boolean nonAnonymousConceptFound = false; - AtomicConcept foundConcept = null; - Named[] catoms = concepts.getCatomArray(); - for(Named catom : catoms) { - String name = catom.getName(); - if(!name.startsWith("anon")) { - if(!nonAnonymousConceptFound) { - nonAnonymousConceptFound = true; - foundConcept = new AtomicConcept(catom.getName()); - atomicConcepts.add(foundConcept); - } else { - System.out.println("Warning: Background knowledge contains synonym concepts. " + - "We decide to pick " + foundConcept + ". \nDIG-XML:\n"+concepts); - } - } - } - } - } - - return atomicConcepts; - } - - public Set<AtomicRole> getAtomicRoles() { - return atomicRoles; - } - - private Set<AtomicRole> getAtomicRolesDIG() { - String atomicRolesDIG = asksPrefix; - atomicRolesDIG += "<allRoleNames id=\"ask_roles\"/></asks>"; - - ResponsesDocument rd = connector.asks(atomicRolesDIG); - // Struktur: einzelnes roleSet außen, dann synonyms mit ratoms - // innen - Rsynonyms[] synonymsArray = rd.getResponses().getRoleSetArray(); - Roles[] rolesArray = synonymsArray[0].getSynonymsArray(); - - Set<AtomicRole> digAtomicRoles = new HashSet<AtomicRole>(); - for(Roles roles : rolesArray) { - // hier koennen wiederum mehrere ratoms enthalten sein, - // aber wir wollen nur eins auslesen - Named[] ratoms = roles.getRatomArray(); - Named role = ratoms[0]; - digAtomicRoles.add(new AtomicRole(role.getName())); - - if(ratoms.length>1) - System.out.println("Warning: Background knowledge contains synonym roles. " + - "Will ignore all but the first. \nDIG-XML:\n"+roles); - } - - return digAtomicRoles; - } - - public SortedSet<Individual> getIndividuals() { - return individuals; - } - - private SortedSet<Individual> getIndividualsDIG() { - String individualsDIG = asksPrefix; - individualsDIG += "<allIndividuals id=\"ask_individuals\"/></asks>"; - - ResponsesDocument rd = connector.asks(individualsDIG); - // Struktur: einzelnes individualSet außen, dann Liste von - // individual-Elementen - IndividualSet[] individualsArray = rd.getResponses().getIndividualSetArray(); - Named[] namedIndividuals = individualsArray[0].getIndividualArray(); - - SortedSet<Individual> digIndividuals = new TreeSet<Individual>(); - for(Named named : namedIndividuals) - digIndividuals.add(new Individual(named.getName())); - - return digIndividuals; - } - - public ReasonerType getReasonerType() { - return ReasonerType.DIG; - } - - @Override - public boolean subsumes(Concept superConcept, Concept subConcept) { - // System.out.println("subsumes(" + superConcept + "," + subConcept + ")"); - String subsumesDIG = asksPrefix; - subsumesDIG += "<subsumes id=\"query_subsume\">"; - subsumesDIG += DIGConverter.getDIGString(superConcept); - subsumesDIG += DIGConverter.getDIGString(subConcept); - subsumesDIG += "</subsumes></asks>"; - - return parseBooleanAnswer(subsumesDIG); - } - - @Override - public Set<Concept> subsumes(Concept superConcept, Set<Concept> subConcepts) { - String subsumesDIG = asksPrefix; - int id = 0; - // ID-Konzept-Zuordnung speichern, da bei der Antwort nur die IDs - // ausgegeben werden - Map<String,Concept> queryMap = new HashMap<String,Concept>(); - for(Concept subConcept : subConcepts) { - queryMap.put("query"+id, subConcept); - subsumesDIG += "<subsumes id=\"query"+id+"\">"; - subsumesDIG += DIGConverter.getDIGString(superConcept); - subsumesDIG += DIGConverter.getDIGString(subConcept); - subsumesDIG += "</subsumes>"; - id++; - } - subsumesDIG += "</asks>"; - - ResponsesDocument rd = connector.asks(subsumesDIG); - IdType[] subsumedConceptsIds = rd.getResponses().getTrueArray(); - - Set<Concept> returnSet = new HashSet<Concept>(); - for(IdType idType : subsumedConceptsIds) { - returnSet.add(queryMap.get(idType.getId())); - } - return returnSet; - } - - @Override - public Set<Concept> subsumes(Set<Concept> superConcepts, Concept subConcept) { - String subsumesDIG = asksPrefix; - int id = 0; - Map<String,Concept> queryMap = new HashMap<String,Concept>(); - for(Concept superConcept : superConcepts) { - queryMap.put("query"+id, superConcept); - subsumesDIG += "<subsumes id=\"query"+id+"\">"; - subsumesDIG += DIGConverter.getDIGString(superConcept); - subsumesDIG += DIGConverter.getDIGString(subConcept); - subsumesDIG += "</subsumes>"; - id++; - } - subsumesDIG += "</asks>"; - - ResponsesDocument rd = connector.asks(subsumesDIG); - IdType[] subsumedConceptsIds = rd.getResponses().getTrueArray(); - - Set<Concept> returnSet = new HashSet<Concept>(); - for(IdType idType : subsumedConceptsIds) { - returnSet.add(queryMap.get(idType.getId())); - } - return returnSet; - } - - /* - // es wird geklont, damit Subsumptionhierarchie nicht von außen verändert werden - // kann - @SuppressWarnings("unchecked") - @Override - public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { - return (TreeSet<Concept>) subsumptionHierarchyUp.get(concept).clone(); - // return subsumptionHierarchyUp.get(concept); // ohne klonen geht es nicht - } - - @SuppressWarnings("unchecked") - @Override - public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { - return (TreeSet<Concept>) subsumptionHierarchyDown.get(concept).clone(); - // return subsumptionHierarchyDown.get(concept); // ohne klonen geht es nicht - } - */ - - @Override - public SubsumptionHierarchy getSubsumptionHierarchy() { - return subsumptionHierarchy; - } - - @Override - public RoleHierarchy getRoleHierarchy() { - return roleHierarchy; - } - - private TreeSet<Concept> getMoreGeneralConceptsDIG(Concept concept) { - String moreGeneralDIG = asksPrefix; - moreGeneralDIG += "<parents id=\"query_parents\">"; - moreGeneralDIG += DIGConverter.getDIGString(concept); - moreGeneralDIG += "</parents></asks>"; - - ResponsesDocument rd = connector.asks(moreGeneralDIG); - TreeSet<Concept> resultsSet = new TreeSet<Concept>(conceptComparator); - // ein Array, der Synomyms-Elemente enthält, die dann Mengen von - // äquivalenten Konzepten enthalten; - // (es wird hier nur das erste Element des ConceptSetArrays gelesen, - // da nur ein solches Element bei dieser Abfrage erwartet wird) - Concepts[] conceptsArray = rd.getResponses().getConceptSetArray()[0].getSynonymsArray(); - - for(int i=0; i<conceptsArray.length; i++) { - // es werden nur atomare Konzepte erwartet - Named[] atoms = conceptsArray[i].getCatomArray(); - - for(Named atom : atoms) { - AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) - resultsSet.add(ac); - } - - // hinzufügen von Top, falls notwendig - if(conceptsArray[i].getTopArray().length>0) - resultsSet.add(new Top()); - - // falls bisher kein erlaubtes Konzept gefunden wurden, dann gibt es - // entweder keine allgemeineren Konzepte oder es handelt sich um - // nicht erlaubte (von Jena erzeugte) Konzepte, die nicht äquivalent - // zu einem erlaubten Konzept sind; in dem Fall muss die Methode rekursiv - // noch einmal aufgerufen werden - if(resultsSet.size()==0 && atoms.length>0) { - // wir wählen das erste Konzept aus, welches ein ignoriertes Konzept ist - // (sonst wäre es weiter oben gefunden wurden) - AtomicConcept ignoredAtomicConcept = new AtomicConcept(atoms[0].getName()); - resultsSet.addAll(getMoreGeneralConceptsDIG(ignoredAtomicConcept)); - } - - } - - return resultsSet; - } - - private TreeSet<Concept> getMoreSpecialConceptsDIG(Concept concept) { - String moreSpecialDIG = asksPrefix; - moreSpecialDIG += "<children id=\"query_children\">"; - moreSpecialDIG += DIGConverter.getDIGString(concept); - moreSpecialDIG += "</children></asks>"; - - // Kommentare siehe getMoreGeneralConcepts(Concept) - ResponsesDocument rd = connector.asks(moreSpecialDIG); - TreeSet<Concept> resultsSet = new TreeSet<Concept>(conceptComparator); - Concepts[] conceptsArray = rd.getResponses().getConceptSetArray()[0].getSynonymsArray(); - - for(int i=0; i<conceptsArray.length; i++) { - Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { - AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) - resultsSet.add(ac); - } - - // hinzufügen von Bottom, falls notwendig - if(conceptsArray[i].getBottomArray().length>0) - resultsSet.add(new Bottom()); - - if(resultsSet.size()==0 && atoms.length>0) { - AtomicConcept ignoredAtomicConcept = new AtomicConcept(atoms[0].getName()); - resultsSet.addAll(getMoreSpecialConceptsDIG(ignoredAtomicConcept)); - } - } - - return resultsSet; - } - - private TreeSet<AtomicRole> getMoreGeneralRolesDIG(AtomicRole role) { - String moreGeneralRolesDIG = asksPrefix; - moreGeneralRolesDIG += "<rparents id=\"query_parents\">"; - moreGeneralRolesDIG += "<ratom name=\"" + role.getName() + "\" />"; - moreGeneralRolesDIG += "</rparents></asks>"; - - ResponsesDocument rd = connector.asks(moreGeneralRolesDIG); - TreeSet<AtomicRole> resultsSet = new TreeSet<AtomicRole>(roleComparator); - Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); - - for(int i=0; i<rolesArray.length; i++) { - Named[] atoms = rolesArray[i].getRatomArray(); - - for(Named atom : atoms) { - AtomicRole ar = new AtomicRole(atom.getName()); - //if(Config.Refinement.allowedRoles.contains(ar)) - resultsSet.add(ar); - } - } - - // System.out.println(rd); - - return resultsSet; - } - - private TreeSet<AtomicRole> getMoreSpecialRolesDIG(AtomicRole role) { - String moreSpecialRolesDIG = asksPrefix; - moreSpecialRolesDIG += "<rchildren id=\"query_children\">"; - moreSpecialRolesDIG += "<ratom name=\"" + role.getName() + "\" />"; - moreSpecialRolesDIG += "</rchildren></asks>"; - - ResponsesDocument rd = connector.asks(moreSpecialRolesDIG); - TreeSet<AtomicRole> resultsSet = new TreeSet<AtomicRole>(roleComparator); - Roles[] rolesArray = rd.getResponses().getRoleSetArray()[0].getSynonymsArray(); - - for(int i=0; i<rolesArray.length; i++) { - Named[] atoms = rolesArray[i].getRatomArray(); - - for(Named atom : atoms) { - AtomicRole ar = new AtomicRole(atom.getName()); - //if(Config.Refinement.allowedRoles.contains(ar)) - resultsSet.add(ar); - } - } - - return resultsSet; - } - - @Override - public boolean instanceCheck(Concept concept, Individual individual) { - String instanceCheckDIG = asksPrefix; - instanceCheckDIG += "<instance id= \"query_instance\">"; - instanceCheckDIG += "<individual name=\""+individual.getName()+"\"/>"; - instanceCheckDIG += DIGConverter.getDIGString(concept); - instanceCheckDIG += "</instance></asks>"; - - return parseBooleanAnswer(instanceCheckDIG); - } - - @Override - public SortedSet<Individual> instanceCheck(Concept concept, Set<Individual> individuals) { - String instanceCheckDIG = asksPrefix; - int id = 0; - // ID-Konzept-Zuordnung speichern, da bei der Antwort nur die IDs - // ausgegeben werden - Map<String,String> queryMap = new HashMap<String,String>(); - for(Individual individual : individuals) { - queryMap.put("query"+id, individual.getName()); - instanceCheckDIG += "<instance id= \"query"+id+"\">"; - instanceCheckDIG += "<individual name=\""+individual.getName()+"\"/>"; - instanceCheckDIG += DIGConverter.getDIGString(concept); - instanceCheckDIG += "</instance>"; - id++; - } - instanceCheckDIG += "</asks>"; - - ResponsesDocument rd = connector.asks(instanceCheckDIG); - IdType[] ids = rd.getResponses().getTrueArray(); - - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - for(IdType idType : ids) { - returnSet.add(new Individual(queryMap.get(idType.getId()))); - } - return returnSet; - } - - @Override - public SortedSet<Individual> retrieval(Concept concept) { - - String retrievalDIG = asksPrefix; - retrievalDIG += "<instances id= \"query_instance\">"; - retrievalDIG += DIGConverter.getDIGString(concept); - retrievalDIG += "</instances></asks>"; - - ResponsesDocument rd = connector.asks(retrievalDIG); - // System.out.println(rd); - Named[] individuals = rd.getResponses().getIndividualSetArray()[0].getIndividualArray(); - - SortedSet<Individual> results = new TreeSet<Individual>(); - for(Named individual : individuals) - results.add(new Individual(individual.getName())); - return results; - } - - // ToDo: gibt momentan nur einen Wert bei äquivalenten Klassen aus - @Override - public Set<AtomicConcept> getConcepts(Individual individual) { - String typesDIG = asksPrefix; - typesDIG += "<types id=\"query_types\">"; - typesDIG += "<individual name=\"" + individual.getName() + "\" />"; - typesDIG += "</types></asks>"; - - ResponsesDocument rd = connector.asks(typesDIG); - TreeSet<AtomicConcept> resultsSet = new TreeSet<AtomicConcept>(conceptComparator); - Concepts[] conceptsArray = rd.getResponses().getConceptSetArray()[0].getSynonymsArray(); - - for(int i=0; i<conceptsArray.length; i++) { - Named[] atoms = conceptsArray[i].getCatomArray(); - for(Named atom : atoms) { - AtomicConcept ac = new AtomicConcept(atom.getName()); - if(allowedConceptsInSubsumptionHierarchy.contains(ac)) - // if(Config.Refinement.allowedConcepts.contains(ac)) - resultsSet.add(ac); - } - } - - // System.out.println("document:"); - // System.out.println(rd); - // System.out.println("parsed:"); - // System.out.println(resultsSet); - - return resultsSet; - } - - // es sieht so aus, als ob die XSD-Datei kaputt ist - es gibt zumindest - // keine getter um ein IndividualPairSet zu finden; in der XSD-Datei ist - // das in Responsegroup auch nicht definiert - // => deswegen wird hier die XML-Cursor-API verwendet - @Override - public Map<Individual, SortedSet<Individual>> getRoleMembers(AtomicRole atomicRole) { - String relatedIndividualsDIG = asksPrefix; - relatedIndividualsDIG += "<relatedIndividuals id=\"related_individuals\">"; - relatedIndividualsDIG += "<ratom name=\"" + atomicRole.getName() + "\" />"; - relatedIndividualsDIG += "</relatedIndividuals></asks>"; - - ResponsesDocument rd = connector.asks(relatedIndividualsDIG); - Map<Individual, SortedSet<Individual>> resultMap = new TreeMap<Individual, SortedSet<Individual>>(); - - QName name = new QName("name"); - XmlCursor cursor = rd.newCursor(); - cursor.toFirstChild(); // Responses - cursor.toFirstChild(); // IndividualPairSet - - int childNumber = 0; - Individual ind1; - Individual ind2; - - // so lange noch Kinder existieren - while(cursor.toChild(childNumber)) { - // Cursor steht jetzt bei einem IndividualPair - cursor.toFirstChild(); - // jetzt steht er bei einem Individual, dessen Namen wir auslesen können - ind1 = new Individual(cursor.getAttributeText(name).toString()); - cursor.toNextSibling(); - ind2 = new Individual(cursor.getAttributeText(name).toString()); - - Helper.addMapEntry(resultMap, ind1, ind2); - - // Cursor wieder hoch auf IndividualPairSet bewegen - cursor.toParent(); - cursor.toParent(); - childNumber++; - } - - /* - System.out.println("document:"); - System.out.println(rd); - System.out.println("parsed:"); - System.out.println(resultMap); - */ - - return resultMap; - } - - @Override - public boolean isSatisfiable() { - String satisfiableDIG = asksPrefix; - // wenn Top erfüllbar ist, dann gibt es auch ein Modell für die KB - // (satisfiability für KB ist nicht Teil von DIG 1.1) - satisfiableDIG += "<satisfiable id=\"query_satisfiable\"><top/></satisfiable>"; - satisfiableDIG += "</asks>"; - - return parseBooleanAnswer(satisfiableDIG); - } - - private boolean parseBooleanAnswer(String asks) { - ResponsesDocument rd = connector.asks(asks); - if(rd.getResponses().getTrueArray().length == 1) - return true; - else - return false; - } - - public String getIdentifier() { - return identifier; - } - - public void releaseKB() { - connector.releaseKB(kbURI); - } - - public void saveOntology(File file, OntologyFileFormat format) { - // KAON2-Reasoner erzeugen und den die Ontologie speichern lassen - // (später könnte man das über Jena erledigen, allerdings funktioniert - // das mit KAON2 auch gut) - KAON2Reasoner kaon2Reasoner = new KAON2Reasoner(kb,imports); - kaon2Reasoner.saveOntology(file, format); - } -} Copied: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java (from rev 174, trunk/src/dl-learner/org/dllearner/reasoning/DIGReasonerNew.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2007-10-08 08:30:59 UTC (rev 176) @@ -0,0 +1,739 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.reasoning; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import javax.xml.namespace.QName; + +import org.apache.xmlbeans.XmlCursor; +import org.dllearner.Config; +import org.dllearner.core.ConfigEntry; +import org.dllearner.core.ConfigOption; +import org.dllearner.core.InvalidConfigOptionValueException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.StringConfigOption; +import org.dllearner.core.dl.AtomicConcept; +import org.dllearner.core.dl.AtomicRole; +import org.dllearner.core.dl.Bottom; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubsumptionHierarchy; +import org.dllearner.core.dl.Top; +import org.dllearner.kb.OntologyFileFormat; +import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.RoleComparator; +import org.kr.dl.dig.v1_1.Concepts; +import org.kr.dl.dig.v1_1.Csynonyms; +import org.kr.dl.dig.v1_1.IdType; +import org.kr.dl.dig.v1_1.Named; +import org.kr.dl.dig.v1_1.ResponseDocument; +import org.kr.dl.dig.v1_1.ResponsesDocument; +import org.kr.dl.dig.v1_1.Roles; +import org.kr.dl.dig.v1_1.Rsynonyms; +import org.kr.dl.dig.v1_1.IndividualSetDocument.IndividualSet; + +/** + * DIG 1.1 implementation of the reasoner interface. + * + * @author Jens Lehmann + * + */ +public class DIGReasoner extends ReasonerComponent { + + URL reasonerURL; + Set<KnowledgeSource> sources; + + // Variablen für Reasoner + DIGHTTPConnector connector; + String identifier; + URI kbURI; + private String asksPrefix; + // Cache für Konzepte, Rollen und Individuen + Set<AtomicConcept> atomicConcepts; + Set<AtomicRole> atomicRoles; + SortedSet<Individual> individuals; + + // Cache für Subsumptionhierarchie + // Comparator ist notwendig, da sonst z.B. verschiedene Instanzen des atomaren Konzepts male + // unterschiedlich sind; + // alternativ wäre auch eine Indizierung über Strings möglich + ConceptComparator conceptComparator = new ConceptComparator(); + RoleComparator roleComparator = new RoleComparator(); + SubsumptionHierarchy subsumptionHierarchy; + RoleHierarchy roleHierarchy; + // enthält atomare Konzepte, sowie Top und Bottom + Set<Concept> allowedConceptsInSubsumptionHierarchy; + + public DIGReasoner(Set<KnowledgeSource> sources) { + this.sources = sources; + try { + reasonerURL = new URL("http://localhost:8081"); + } catch (MalformedURLException e) { } + } + + @Override + public void init() { + connector = new DIGHTTPConnector(reasonerURL); + identifier = connector.getIdentifier(); + kbURI = connector.newKB(); + + // asks-Prefix entsprechend der KB-URI initialisieren + asksPrefix = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; + asksPrefix += "<asks xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + + "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"; + + // momementan wird davon ausgegangen, dass toDIG(kbURI) den gesamten + // tells-Request liefert + StringBuilder sb = new StringBuilder(); +// sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); +// sb.append("<tells xmlns=\"http://dl.kr.org/dig/2003/02/lang\" " + +// "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + +// "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + +// "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); + for(KnowledgeSource source : sources) { + sb.append(source.toDIG(kbURI)); + + ResponseDocument rd = connector.tells(sb.toString()); + if(!rd.getResponse().isSetOk()) { + System.err.println("DIG-Reasoner cannot read knowledgebase."); + System.exit(0); + } + } +// sb.append("</tells>"); + + // DIG-Abfragen nach Konzepten, Rollen, Individuals + atomicConcepts = getAtomicConceptsDIG(); + atomicRoles = getAtomicRolesDIG(); + individuals = getIndividualsDIG(); + } + + public static String getName() { + return "DIG reasoner"; + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringConfigOption("reasonerUrl", "URL of the DIG reasoner")); + return options; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + if (entry.getOptionName().equals("reasonerUrl")) { + String s = (String) entry.getValue(); + try { + reasonerURL = new URL(s); + } catch (MalformedURLException e) { + // e.printStackTrace(); + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue()); + } + } + } + + + /** + * Construct a subsumption hierarchy using DIG queries. After calling this + * method one can ask for children or parents in the subsumption hierarchy. + */ + public void prepareSubsumptionHierarchy() { + allowedConceptsInSubsumptionHierarchy = new TreeSet<Concept>(conceptComparator); + allowedConceptsInSubsumptionHierarchy.addAll(Config.Refinement.allowedConcepts); + allowedConceptsInSubsumptionHierarchy.add(new Top()); + allowedConceptsInSubsumptionHierarchy.add(new Bottom()); + + TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); + + // Subsumptionhierarchy berechnen + // TODO: kann man effizienter auch in einer Abfrage machen + + // Refinements von Top + TreeSet<Concept> tmp = getMoreSpecialConceptsDIG(new Top()); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyDown.put(new Top(), tmp); + + // Refinements von Bottom + tmp = getMoreGeneralConceptsDIG(new Bottom()); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyUp.put(new Bottom(), tmp); + + // Refinement atomarer Konzepte + for(AtomicConcept atom : atomicConcepts) { + tmp = getMoreSpecialConceptsDIG(atom); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyDown.put(atom, tmp); + + tmp = getMoreGeneralConceptsDIG(atom); + tmp.retainAll(allowedConceptsInSubsumptionHierarchy); + subsumptionHierarchyUp.put(atom, tmp); + } + + subsumptionHierarchy = new SubsumptionHierarchy(Config.Refinement.allowedConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); + } + + /** + * Constructs a role hierarchy using DIG queries. After calling this method, + * one can query parents or children of roles. + * + * @todo Does not yet take ignored roles into account. + */ + @Override + public void prepareRoleHierarchy() { + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyUp = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); + TreeMap<AtomicRole,TreeSet<AtomicRole>> roleHierarchyDown = new TreeMap<AtomicRole,TreeSet<AtomicRole>>(roleComparator); + + // Refinement atomarer Konzepte + for(AtomicRole role : atomicRoles) { + roleHierarchyDown.put(role, getMoreSpecialRolesDIG(role)); + roleHierarchyUp.put(role, getMoreGeneralRolesDIG(role)); + } + + roleHierarchy = new RoleHierarchy(Config.Refinement.allowedRoles, roleHierarchyUp, roleHierarchyDown); + } + + // eigentlich müsste man klonen um sicherzustellen, dass der parent-Link + // bei null bleibt; bei der aktuellen Implementierung ist der parent-Link + // nicht immer null, was bei GP negative Auswirkungen haben könnte + // Update: wird durch klonen innerhalb der GP-Operationen erledigt + public Set<AtomicConcept> getAtomicConcepts() { + /* + if(Config.algorithm == Config.Algorithm.GP || Config.algorithm == Config.Algorithm.HYBRID_GP) { + Set<AtomicConcept> returnSet = new HashSet<AtomicConcept>(); + for(AtomicConcept ac : atomicConcepts) + returnSet.add((AtomicConcept)ac.clone()); + return returnSet; + } + */ + return atomicConcepts; + } + + private Set<AtomicConcept> getAtomicConceptsDIG() { + String atomicConceptsDIG = asksPrefix; + atomicConceptsDIG += "<allConceptNames id=\"ask_names\"/></asks>"; + + ResponsesDocument rd = connector.asks(atomicConceptsDIG); + // Struktur: einzelnes conceptSet außen, dann mehrere synonyms, die dann + // die Konzept inkl. Top und Bottom enthalten + Csynonyms[] synonymsArray = rd.getResponse... [truncated message content] |
From: <jen...@us...> - 2007-10-08 12:26:36
|
Revision: 182 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=182&view=rev Author: jenslehmann Date: 2007-10-08 05:26:35 -0700 (Mon, 08 Oct 2007) Log Message: ----------- removed modules package (became obsolete due to new component structure) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/modules/ Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 12:07:11 UTC (rev 181) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2007-10-08 12:26:35 UTC (rev 182) @@ -43,7 +43,6 @@ import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.Individual; -import org.dllearner.modules.sparql.OntologyCollector; import org.dllearner.reasoning.OWLAPIDIGConverter; import org.dllearner.utilities.Datastructures; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 12:52:33
|
Revision: 183 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=183&view=rev Author: jenslehmann Date: 2007-10-08 05:52:31 -0700 (Mon, 08 Oct 2007) Log Message: ----------- cleanup (reduced number of warnings) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java trunk/src/dl-learner/org/dllearner/utilities/Helper.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 12:52:31 UTC (rev 183) @@ -75,7 +75,7 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); + // String name = entry.getOptionName(); } /* (non-Javadoc) @@ -86,6 +86,7 @@ } + @Override public void start() { // FlatABox abox = FlatABox.getInstance(); int maxLength = Config.maxLength; @@ -274,16 +275,17 @@ } } + @Override public Score getSolutionScore() { return bestScore; } + @Override public Concept getBestSolution() { return bestDefinition; } + @Override public void stop() { - // TODO Auto-generated method stub - } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-10-08 12:52:31 UTC (rev 183) @@ -146,7 +146,7 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); + // String name = entry.getOptionName(); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-10-08 12:52:31 UTC (rev 183) @@ -26,7 +26,6 @@ import org.dllearner.core.dl.Negation; import org.dllearner.core.dl.Top; import org.dllearner.learningproblems.PosNegDefinitionLPStrict; -import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.ScoreThreeValued; import org.dllearner.reasoning.FastRetrieval; import org.dllearner.reasoning.ReasonerType; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 12:52:31 UTC (rev 183) @@ -251,6 +251,7 @@ } // Kernalgorithmus + @Override @SuppressWarnings("unchecked") public void start() { Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-10-08 12:52:31 UTC (rev 183) @@ -47,9 +47,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.Reasoner; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.StringConfigOption; Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-10-08 12:52:31 UTC (rev 183) @@ -21,7 +21,6 @@ package org.dllearner.core; import java.io.File; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2007-10-08 12:52:31 UTC (rev 183) @@ -19,20 +19,12 @@ */ package org.dllearner.learningproblems; -import java.util.Collection; -import java.util.LinkedList; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.BooleanConfigOption; -import org.dllearner.core.CommonConfigMappings; -import org.dllearner.core.ConfigEntry; -import org.dllearner.core.ConfigOption; -import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; -import org.dllearner.core.StringSetConfigOption; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java 2007-10-08 12:52:31 UTC (rev 183) @@ -19,14 +19,11 @@ */ package org.dllearner.learningproblems; -import java.util.SortedSet; - import org.dllearner.core.ConfigEntry; import org.dllearner.core.InvalidConfigOptionValueException; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Individual; /** * @author Jens Lehmann Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2007-10-08 12:52:31 UTC (rev 183) @@ -23,7 +23,6 @@ import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.KB; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java 2007-10-08 12:52:31 UTC (rev 183) @@ -13,12 +13,10 @@ import org.dllearner.Config; import org.dllearner.algorithms.refinement.ROLearner; -import org.dllearner.core.LearningProblem; import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.KB; import org.dllearner.kb.OntologyFileFormat; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java 2007-10-08 12:52:31 UTC (rev 183) @@ -1,7 +1,6 @@ package org.dllearner.server; import org.dllearner.Config; -import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/utilities/Helper.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2007-10-08 12:26:35 UTC (rev 182) +++ trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2007-10-08 12:52:31 UTC (rev 183) @@ -11,8 +11,6 @@ import java.util.TreeSet; import org.dllearner.Config; -import org.dllearner.Config.Refinement; -import org.dllearner.core.Reasoner; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.AssertionalAxiom; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-10-08 14:33:13
|
Revision: 188 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=188&view=rev Author: jenslehmann Date: 2007-10-08 07:33:11 -0700 (Mon, 08 Oct 2007) Log Message: ----------- cleaned up brute force learning algorithm Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 13:54:46 UTC (rev 187) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-10-08 14:33:11 UTC (rev 188) @@ -17,7 +17,7 @@ public class Config { // standardmäßig wird bis Tiefe 7 gesucht - public static int maxLength = 7; + // public static int maxLength = 7; public static int maxDepth; Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 13:54:46 UTC (rev 187) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-10-08 14:33:11 UTC (rev 188) @@ -383,7 +383,7 @@ private void applyIntOptions(String option, int value) { if (option.equals("maxLength")) - Config.maxLength = value; + ;//Config.maxLength = value; else if (option.equals("gp.numberOfIndividuals")) Config.GP.numberOfIndividuals = value; else if (option.equals("gp.numberOfSelectedIndividuals")) Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 13:54:46 UTC (rev 187) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2007-10-08 14:33:11 UTC (rev 188) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.algorithms; import java.util.Collection; @@ -27,30 +47,24 @@ import org.dllearner.core.dl.Top; /** - * TODO: Man könnte den Speicherbedarf gegen Null gehen lassen, wenn man gar keine Programme - * generiert, also in einer Menge speichert, sondern sofort testet. Allerdings ist das - * schwierig, da Programme kleinerer Länge immer weiterverwendet werden. + * A brute force learning algorithm. * + * The algorithm works by generating all concepts starting with the shortest + * ones. + * * @author Jens Lehmann * */ public class BruteForceLearner extends LearningAlgorithm { - LearningProblem learningProblem; + private LearningProblem learningProblem; - // Set<String> posExamples = null; - // Set<String> negExamples = null; - private Concept bestDefinition; private Score bestScore; - // private Set<String> bestDefPosSet = new TreeSet<String>(); - // private Set<String> bestDefNegSet = new TreeSet<String>(); - // int bestScore; - // int maxScore; - // Liste aller generierten Programme - // private List<Node> generatedPrograms = new LinkedList<Node>(); - // Programme nach Anzahl Knoten sortiert + private int maxLength = 7; + + // list of all generated concepts sorted by length private Map<Integer,List<Concept>> generatedDefinitions = new HashMap<Integer,List<Concept>>(); public BruteForceLearner(LearningProblem learningProblem, ReasoningService rs) { @@ -65,8 +79,7 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new IntegerConfigOption("numberOfTrees", "number of randomly generated concepts/trees")); - options.add(new IntegerConfigOption("maxDepth", "maximum depth of generated concepts/trees")); + options.add(new IntegerConfigOption("maxLength", "maximum length of generated concepts")); return options; } @@ -75,7 +88,9 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - // String name = entry.getOptionName(); + String name = entry.getOptionName(); + if(name.equals("maxLength")) + maxLength = (Integer) entry.getValue(); } /* (non-Javadoc) @@ -89,7 +104,6 @@ @Override public void start() { // FlatABox abox = FlatABox.getInstance(); - int maxLength = Config.maxLength; System.out.print("Generating definitions up to length " + maxLength + " ... "); long generationStartTime = System.currentTimeMillis(); @@ -100,49 +114,12 @@ long generationTime = System.currentTimeMillis() - generationStartTime; System.out.println("OK (" + generationTime + " ms)"); - // es wird angenommen, dass nur ein Konzept gelernt wird - /* - for(String s : abox.exampleConceptsPos.keySet()) { - posExamples = abox.exampleConceptsPos.get(s); - } - for(String s : abox.exampleConceptsNeg.keySet()) { - negExamples = abox.exampleConceptsNeg.get(s); - } - */ - testGeneratedDefinitions(maxLength); // System.out.println("test duration: " + testDuration + " ms"); System.out.println(); System.out.println("Best definition found: \n" + bestDefinition); - // System.out.println("classified positive: " + bestScore.getPosClassified()); - // System.out.println("classified negative: " + bestScore.getNegClassified()); - - /* - // HIER WIRD ANGENOMMEN, DASS NUR EIN KONZEPT GERLERNT WIRD - Set<String> posExamples = null; - Set<String> negExamples = null; - Set<String> neutralExamples; - // es wird angenommen, dass nur ein Konzept gelernt wird - for(String s : abox.exampleConceptsPos.keySet()) { - posExamples = abox.exampleConceptsPos.get(s); - } - for(String s : abox.exampleConceptsNeg.keySet()) { - negExamples = abox.exampleConceptsNeg.get(s); - } - neutralExamples = Helper.intersection(abox.top,posExamples); - neutralExamples = Helper.intersection(neutralExamples,negExamples); - - Set<String> bestDefNeutralSet = Helper.intersection(abox.top,bestDefPosSet); - bestDefNeutralSet = Helper.intersection(bestDefNeutralSet,bestDefNegSet); - - // Fehler berechnen - // int numberOfErrors = Helper.intersection(bestDefPosSet) - - - DecimalFormat df = new DecimalFormat("0.00"); - */ System.out.println(); System.out.println("Classification results:"); System.out.println(bestScore); @@ -168,21 +145,18 @@ System.out.print("Testing definitions of length " + i + " ... "); count = 0; for(Concept program : generatedDefinitions.get(i)) { - // falls return type angegeben ist, dann wird hier ein - // entsprechender Baum konstruiert + // if a return type is already given an appropriate tree is + // generated here Concept newRoot; if(!Config.returnType.equals("")) { newRoot = new Conjunction(new AtomicConcept(Config.returnType),program); } else newRoot = program; - // int score = computeScore(abox,program); - // tmp = new Score(newRoot); // newRoot.computeScore(); tmp = learningProblem.computeScore(newRoot); score = tmp.getScore(); - // später Abbruch bei maximaler Punktzahl einführen - //if(score == maxScore) - // return; + + // TODO: find termination criterion if(score > bestScorePoints) { bestDefinition = newRoot; bestScorePoints = score; @@ -199,8 +173,6 @@ System.out.println("Overall: " + overallCount + " definitions tested (" + testDuration + " ms)"); } - - private void generatePrograms(int length) { generatedDefinitions.put(length,new LinkedList<Concept>()); if(length==1) { @@ -212,26 +184,27 @@ } if(length>1) { - // Negation + // negation for(Concept childNode : generatedDefinitions.get(length-1)) { Concept root = new Negation(childNode); generatedDefinitions.get(length).add(root); } } - // Mindestlänge 3, da man sonst mit Disjunktion und Konjunktion nichts - // konstruieren kann + // minimum length 3, otherwise conjunctions and disjunctions cannot be + // constructed if(length>2) { - // Konjunktion oder Disjunktion auswählen + // choose conjunction or disjunction for(int i=0; i<=1; i++) { - // Variable von 1 bis angerundet (length-1)/2 gehen lassen - // = Länge des linken Teilbaumes + // let variable run from 1 to (length-1)/2 (rounded down) + // = length of left subtree for(int z=1; z<=Math.floor(0.5*(length-1)); z++) { - // alle Programme der Länge z durchgehen (linker Teilbaum) + + // cycle through all concepts of length z (left subtree) for(Concept leftChild : generatedDefinitions.get(z)) { - // alle Programme der Länge length-z-1 durchgehen (rechter Teilbaum) + // cycle thorugh all concept of lengt "length-z-1" (right subtree) for(Concept rightChild : generatedDefinitions.get(length-z-1)) { - // Baum erzeugen + // create concept tree Concept root; if(i==0) { root = new Disjunction(leftChild,rightChild); @@ -239,18 +212,18 @@ root = new Conjunction(leftChild,rightChild); } - // man beachte, dass hier nur Links gesetzt werden, d.h. - // dass: - // 1. jede Modifikation an einem generierten Programm auch - // andere Programme beeinflussen kann - // 2. wohin der parent-Link eines Knotens zeigt ist nicht - // spezifiziert, da ein Knoten Kind mehererer anderer - // Knoten sein kann - // Das wird gemacht, da der Retrieval-Algorithmus den parent- - // Link nicht benötigt und die Bäume nicht modifiziert, abgesehen - // vom posSet und negSet, welches aber für jeden Baum neu - // berechnet wird. Das speichern der Programme ist auf diese - // Weise platzsparend, also 1 Programm = 1 Knoten. + // Please not that we only set links here, i.e.: + // 1. Every modification of a generated concept can influence + // other concepts. + // 2. It is not specified where the parent link of a concept + // points to, because one node can be child of several nodes. + // + // For the currently implemented reasoning algorithms this + // does not matter, because they do not modify concepts and + // do not care about the parent link. + // + // This way we save space (1 new concept in the brute force + // learner consumes space for only one tree node). // root.addChild(leftChild); // root.addChild(rightChild); // System.out.println(root); @@ -261,9 +234,8 @@ } } - // Exists und All (zählen als Länge 2 wegen Quantor und Rollennamen) + // EXISTS and ALL for(Concept childNode : generatedDefinitions.get(length-2)) { - // for(String roleName : abox.roles) { for(AtomicRole atomicRole : learningProblem.getReasoningService().getAtomicRoles()) { Concept root1 = new Exists(atomicRole,childNode); generatedDefinitions.get(length).add(root1); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 13:54:46 UTC (rev 187) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-10-08 14:33:11 UTC (rev 188) @@ -250,6 +250,10 @@ rs.prepareRoleHierarchy(); } + public static String getName() { + return "refinement operator based learning algorithm"; + } + // Kernalgorithmus @Override @SuppressWarnings("unchecked") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |