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. |