List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration()
XMLConfiguration
. From source file:com.example.TestClass.java
@Test public void testWithSeparatingNonWhitespace() throws Exception { String source = "<configuration><key0></key0><key1>,</key1>A<key2></key2><key3></key3></configuration>"; XMLConfiguration config = new XMLConfiguration(); config.load(new StringReader(source)); checkConfiguration(config);/*from w ww . j a va 2 s . co m*/ }
From source file:com.voidsearch.voidbase.config.VoidBaseConfig.java
protected XMLConfiguration mergeConfiguration(List<String> files) throws ConfigException { XMLConfiguration config = new XMLConfiguration(); for (String file : files) { Iterator<String> keys; XMLConfiguration fragment;/* w ww. j a v a 2s . c om*/ try { logger.info("Loading configuration file: " + file); fragment = new XMLConfiguration(file); keys = fragment.getKeys(); } catch (ConfigurationException e) { GenericUtil.logException(e); throw new ConfigException("Failed to load configuration from: " + file); } while (keys.hasNext()) { String key = keys.next(); // sanity check if (config.containsKey(key)) { throw new ConfigException("Collision of keys for: " + key); } // merge configuration config.addProperty(key, fragment.getProperty(key)); } } return config; }
From source file:edu.uw.sig.frames2owl.util.ConfigReader.java
public ConfigReader(String configPath) throws ConfigurationException { config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); config.load(configPath);//from w w w .ja v a 2 s . c om init(); }
From source file:com.eyeq.pivot4j.ui.condition.OrConditionTest.java
@Test public void testSettingsManagement() throws ConfigurationException { RenderContext context = createDummyRenderContext(); OrCondition or = new OrCondition(conditionFactory); or.setSubConditions(Arrays.asList(TestCondition.TRUE, TestCondition.FALSE)); XMLConfiguration configuration = new XMLConfiguration(); configuration.setRootElementName("condition"); or.saveSettings(configuration);//w w w .j av a 2 s . c o m or = new OrCondition(conditionFactory); or.restoreSettings(configuration); assertThat("Sub conditions should not be null.", or.getSubConditions(), is(notNullValue())); assertThat("Sub condition count should be 2.", or.getSubConditions().size(), is(2)); assertThat("'true || false' should be true.", or.matches(context), is(true)); System.out.println("Saved configuration : "); configuration.save(System.out); }
From source file:keel.Algorithms.Genetic_Rule_Learning.Bojarczuk_GP.Main.java
/** * <p>/* ww w .j a va 2s .c om*/ * Configure the execution of the algorithm. * * @param jobFilename Name of the KEEL file with properties of the execution * </p> */ private static void configureJob(String jobFilename) { Properties props = new Properties(); try { InputStream paramsFile = new FileInputStream(jobFilename); props.load(paramsFile); paramsFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } // Files training and test String trainFile; String testFile; StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData")); tokenizer.nextToken(); trainFile = tokenizer.nextToken(); trainFile = trainFile.substring(1, trainFile.length() - 1); testFile = tokenizer.nextToken(); testFile = testFile.substring(1, testFile.length() - 1); tokenizer = new StringTokenizer(props.getProperty("outputData")); String reportTrainFile = tokenizer.nextToken(); reportTrainFile = reportTrainFile.substring(1, reportTrainFile.length() - 1); String reportTestFile = tokenizer.nextToken(); reportTestFile = reportTestFile.substring(1, reportTestFile.length() - 1); String reportRulesFile = tokenizer.nextToken(); reportRulesFile = reportRulesFile.substring(1, reportRulesFile.length() - 1); // Algorithm auxiliar configuration XMLConfiguration algConf = new XMLConfiguration(); algConf.setRootElementName("experiment"); algConf.addProperty("process[@algorithm-type]", "net.sourceforge.jclec.problem.classification.freitas.FreitasAlgorithm"); algConf.addProperty("process.rand-gen-factory[@type]", "net.sourceforge.jclec.util.random.RanecuFactory"); algConf.addProperty("process.rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); algConf.addProperty("process.population-size", Integer.parseInt(props.getProperty("population-size"))); algConf.addProperty("process.max-of-generations", Integer.parseInt(props.getProperty("max-generations"))); algConf.addProperty("process.max-deriv-size", Integer.parseInt(props.getProperty("max-deriv-size"))); algConf.addProperty("process.dataset[@type]", "net.sourceforge.jclec.util.dataset.KeelDataSet"); algConf.addProperty("process.dataset.train-data.file-name", trainFile); algConf.addProperty("process.dataset.test-data.file-name", testFile); algConf.addProperty("process.species[@type]", "net.sourceforge.jclec.problem.classification.freitas.FreitasSyntaxTreeSpecies"); algConf.addProperty("process.evaluator[@type]", "net.sourceforge.jclec.problem.classification.freitas.FreitasEvaluator"); algConf.addProperty("process.provider[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeCreator"); algConf.addProperty("process.parents-selector[@type]", "net.sourceforge.jclec.selector.RouletteSelector"); algConf.addProperty("process.recombinator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeRecombinator"); algConf.addProperty("process.recombinator[@rec-prob]", Double.parseDouble(props.getProperty("rec-prob"))); algConf.addProperty("process.recombinator.base-op[@type]", "net.sourceforge.jclec.problem.classification.freitas.FreitasCrossover"); algConf.addProperty("process.copy-prob", Double.parseDouble(props.getProperty("copy-prob"))); algConf.addProperty("process.listener[@type]", "net.sourceforge.jclec.problem.classification.freitas.KeelFreitasPopulationReport"); algConf.addProperty("process.listener.report-dir-name", "./"); algConf.addProperty("process.listener.train-report-file", reportTrainFile); algConf.addProperty("process.listener.test-report-file", reportTestFile); algConf.addProperty("process.listener.rules-report-file", reportRulesFile); algConf.addProperty("process.listener.global-report-name", "resumen"); algConf.addProperty("process.listener.report-frequency", 50); try { algConf.save(new File("configure.txt")); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } net.sourceforge.jclec.RunExperiment.main(new String[] { "configure.txt" }); }
From source file:com.eyeq.pivot4j.ui.condition.AndConditionTest.java
@Test public void testSettingsManagement() throws ConfigurationException { RenderContext context = createDummyRenderContext(); AndCondition and = new AndCondition(conditionFactory); and.setSubConditions(Arrays.asList(TestCondition.TRUE, TestCondition.TRUE)); XMLConfiguration configuration = new XMLConfiguration(); configuration.setRootElementName("condition"); and.saveSettings(configuration);/* w w w. jav a2s . co m*/ and = new AndCondition(conditionFactory); and.restoreSettings(configuration); assertThat("Sub conditions should not be null.", and.getSubConditions(), is(notNullValue())); assertThat("Sub condition count should be 2.", and.getSubConditions().size(), is(2)); assertThat("'true && true' should be true.", and.matches(context), is(true)); System.out.println("Saved configuration : "); configuration.save(System.out); }
From source file:keel.Algorithms.Genetic_Rule_Learning.Falco_GP.Main.java
/** * <p>/*from ww w .j a v a2s . c o m*/ * Configure the execution of the algorithm. * * @param jobFilename Name of the KEEL file with properties of the * execution * </p> */ private static void configureJob(String jobFilename) { Properties props = new Properties(); try { InputStream paramsFile = new FileInputStream(jobFilename); props.load(paramsFile); paramsFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } // Files training and test String trainFile; String testFile; StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData")); tokenizer.nextToken(); trainFile = tokenizer.nextToken(); trainFile = trainFile.substring(1, trainFile.length() - 1); testFile = tokenizer.nextToken(); testFile = testFile.substring(1, testFile.length() - 1); tokenizer = new StringTokenizer(props.getProperty("outputData")); String reportTrainFile = tokenizer.nextToken(); reportTrainFile = reportTrainFile.substring(1, reportTrainFile.length() - 1); String reportTestFile = tokenizer.nextToken(); reportTestFile = reportTestFile.substring(1, reportTestFile.length() - 1); String reportRulesFile = tokenizer.nextToken(); reportRulesFile = reportRulesFile.substring(1, reportRulesFile.length() - 1); // Algorithm auxiliar configuration XMLConfiguration algConf = new XMLConfiguration(); algConf.setRootElementName("experiment"); algConf.addProperty("process[@algorithm-type]", "net.sourceforge.jclec.problem.classification.falco.FalcoAlgorithm"); algConf.addProperty("process.rand-gen-factory[@type]", "net.sourceforge.jclec.util.random.RanecuFactory"); algConf.addProperty("process.rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); algConf.addProperty("process.population-size", Integer.parseInt(props.getProperty("population-size"))); algConf.addProperty("process.max-of-generations", Integer.parseInt(props.getProperty("max-generations"))); algConf.addProperty("process.max-deriv-size", Integer.parseInt(props.getProperty("max-deriv-size"))); algConf.addProperty("process.dataset[@type]", "net.sourceforge.jclec.util.dataset.KeelDataSet"); algConf.addProperty("process.dataset.train-data.file-name", trainFile); algConf.addProperty("process.dataset.test-data.file-name", testFile); algConf.addProperty("process.species[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoSyntaxTreeSpecies"); algConf.addProperty("process.evaluator[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoEvaluator"); algConf.addProperty("process.evaluator.alpha", Double.parseDouble(props.getProperty("alpha"))); algConf.addProperty("process.provider[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeCreator"); algConf.addProperty("process.parents-selector[@type]", "net.sourceforge.jclec.selector.RouletteSelector"); algConf.addProperty("process.recombinator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeRecombinator"); algConf.addProperty("process.recombinator[@rec-prob]", Double.parseDouble(props.getProperty("rec-prob"))); algConf.addProperty("process.recombinator.base-op[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoCrossover"); algConf.addProperty("process.mutator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeMutator"); algConf.addProperty("process.mutator[@mut-prob]", Double.parseDouble(props.getProperty("mut-prob"))); algConf.addProperty("process.mutator.base-op[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoMutator"); algConf.addProperty("process.copy-prob", Double.parseDouble(props.getProperty("copy-prob"))); algConf.addProperty("process.listener[@type]", "net.sourceforge.jclec.problem.classification.falco.KeelFalcoPopulationReport"); algConf.addProperty("process.listener.report-dir-name", "./"); algConf.addProperty("process.listener.train-report-file", reportTrainFile); algConf.addProperty("process.listener.test-report-file", reportTestFile); algConf.addProperty("process.listener.rules-report-file", reportRulesFile); algConf.addProperty("process.listener.global-report-name", "resumen"); algConf.addProperty("process.listener.report-frequency", 50); try { algConf.save(new File("configure.txt")); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } net.sourceforge.jclec.RunExperiment.main(new String[] { "configure.txt" }); }
From source file:keel.Algorithms.Genetic_Rule_Learning.Tan_GP.Main.java
/** * <p>// w w w .j a va 2 s .c o m * Configure the execution of the algorithm. * * @param jobFilename Name of the KEEL file with properties of the * execution * </p> */ private static void configureJob(String jobFilename) { Properties props = new Properties(); try { InputStream paramsFile = new FileInputStream(jobFilename); props.load(paramsFile); paramsFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } // Files training and test String trainFile; String testFile; StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData")); tokenizer.nextToken(); trainFile = tokenizer.nextToken(); trainFile = trainFile.substring(1, trainFile.length() - 1); testFile = tokenizer.nextToken(); testFile = testFile.substring(1, testFile.length() - 1); tokenizer = new StringTokenizer(props.getProperty("outputData")); String reportTrainFile = tokenizer.nextToken(); reportTrainFile = reportTrainFile.substring(1, reportTrainFile.length() - 1); String reportTestFile = tokenizer.nextToken(); reportTestFile = reportTestFile.substring(1, reportTestFile.length() - 1); String reportRulesFile = tokenizer.nextToken(); reportRulesFile = reportRulesFile.substring(1, reportRulesFile.length() - 1); // Algorithm auxiliar configuration XMLConfiguration algConf = new XMLConfiguration(); algConf.setRootElementName("experiment"); algConf.addProperty("process[@algorithm-type]", "net.sourceforge.jclec.problem.classification.tan.TanAlgorithm"); algConf.addProperty("process.rand-gen-factory[@type]", "net.sourceforge.jclec.util.random.RanecuFactory"); algConf.addProperty("process.rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); algConf.addProperty("process.population-size", Integer.parseInt(props.getProperty("population-size"))); algConf.addProperty("process.max-of-generations", Integer.parseInt(props.getProperty("max-generations"))); algConf.addProperty("process.max-deriv-size", Integer.parseInt(props.getProperty("max-deriv-size"))); algConf.addProperty("process.dataset[@type]", "net.sourceforge.jclec.util.dataset.KeelDataSet"); algConf.addProperty("process.dataset.train-data.file-name", trainFile); algConf.addProperty("process.dataset.test-data.file-name", testFile); algConf.addProperty("process.species[@type]", "net.sourceforge.jclec.problem.classification.tan.TanSyntaxTreeSpecies"); algConf.addProperty("process.evaluator[@type]", "net.sourceforge.jclec.problem.classification.tan.TanEvaluator"); algConf.addProperty("process.evaluator.w1", Double.parseDouble(props.getProperty("w1"))); algConf.addProperty("process.evaluator.w2", Double.parseDouble(props.getProperty("w2"))); algConf.addProperty("process.provider[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeCreator"); algConf.addProperty("process.parents-selector[@type]", "net.sourceforge.jclec.selector.RouletteSelector"); algConf.addProperty("process.recombinator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeRecombinator"); algConf.addProperty("process.recombinator[@rec-prob]", Double.parseDouble(props.getProperty("rec-prob"))); algConf.addProperty("process.recombinator.base-op[@type]", "net.sourceforge.jclec.problem.classification.tan.TanCrossover"); algConf.addProperty("process.mutator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeMutator"); algConf.addProperty("process.mutator[@mut-prob]", Double.parseDouble(props.getProperty("mut-prob"))); algConf.addProperty("process.mutator.base-op[@type]", "net.sourceforge.jclec.problem.classification.tan.TanMutator"); algConf.addProperty("process.copy-prob", Double.parseDouble(props.getProperty("copy-prob"))); algConf.addProperty("process.elitist-prob", Double.parseDouble(props.getProperty("elitist-prob"))); algConf.addProperty("process.support", Double.parseDouble(props.getProperty("support"))); algConf.addProperty("process.listener[@type]", "net.sourceforge.jclec.problem.classification.tan.KeelTanPopulationReport"); algConf.addProperty("process.listener.report-dir-name", "./"); algConf.addProperty("process.listener.train-report-file", reportTrainFile); algConf.addProperty("process.listener.test-report-file", reportTestFile); algConf.addProperty("process.listener.rules-report-file", reportRulesFile); algConf.addProperty("process.listener.global-report-name", "resumen"); algConf.addProperty("process.listener.report-frequency", 50); try { algConf.save(new File("configure.txt")); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } net.sourceforge.jclec.RunExperiment.main(new String[] { "configure.txt" }); }
From source file:keel.Algorithms.MIL.G3PMI.Main.java
/** * <p>/* w w w .jav a 2s .co m*/ * Configure the execution of the algorithm. * * @param jobFilename Name of the KEEL file with properties of the execution * </p> */ private static void configureJob(String jobFilename) { Properties props = new Properties(); try { InputStream paramsFile = new FileInputStream(jobFilename); props.load(paramsFile); paramsFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } // Files training and test String trainFile; String testFile; StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData")); tokenizer.nextToken(); trainFile = tokenizer.nextToken(); trainFile = trainFile.substring(1, trainFile.length() - 1); testFile = tokenizer.nextToken(); testFile = testFile.substring(1, testFile.length() - 1); tokenizer = new StringTokenizer(props.getProperty("outputData")); String reportTrainFile = tokenizer.nextToken(); reportTrainFile = reportTrainFile.substring(1, reportTrainFile.length() - 1); String reportTestFile = tokenizer.nextToken(); reportTestFile = reportTestFile.substring(1, reportTestFile.length() - 1); //System.out.println("SALIDA: " + reportTestFile); //String reportRulesFile = tokenizer.nextToken(); //reportRulesFile = reportRulesFile.substring(1, reportRulesFile.length()-1); // Algorithm auxiliar configuration XMLConfiguration algConf = new XMLConfiguration(); algConf.setRootElementName("experiment"); algConf.addProperty("process.algorithm[@type]", "org.ayrna.jclec.problem.classification.syntaxtree.multiinstance.G3PMIKeel.G3PMIAlgorithm"); algConf.addProperty("process.algorithm.rand-gen-factory[@type]", "org.ayrna.jclec.util.random.RanecuFactory"); algConf.addProperty("process.algorithm.rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); algConf.addProperty("process.algorithm.population-size", Integer.parseInt(props.getProperty("population-size"))); algConf.addProperty("process.algorithm.max-of-generations", Integer.parseInt(props.getProperty("max-generations"))); algConf.addProperty("process.algorithm.max-deriv-size", Integer.parseInt(props.getProperty("max-deriv-size"))); algConf.addProperty("process.algorithm.species[@type]", "org.ayrna.jclec.problem.classification.syntaxtree.multiinstance.G3PMIKeel.G3PMISyntaxTreeSpecies"); algConf.addProperty("process.algorithm.species.max-deriv-size", Integer.parseInt(props.getProperty("max-deriv-size"))); algConf.addProperty("process.algorithm.species.dataset[@type]", "org.ayrna.jclec.util.dataset.KeelMultiInstanceDataSet"); algConf.addProperty("process.algorithm.species.dataset.file-name", trainFile); algConf.addProperty("process.algorithm.species.rand-gen-factory[@type]", "org.ayrna.jclec.util.random.RanecuFactory"); algConf.addProperty("process.algorithm.species.rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); algConf.addProperty("process.algorithm.evaluator[@type]", "org.ayrna.jclec.problem.classification.syntaxtree.multiinstance.G3PMIKeel.G3PMIEvaluator"); algConf.addProperty("process.algorithm.evaluator.rand-gen-factory[@type]", "org.ayrna.jclec.util.random.RanecuFactory"); algConf.addProperty("process.algorithm.evaluator.rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); algConf.addProperty("process.algorithm.evaluator.dataset[@type]", "org.ayrna.jclec.util.dataset.KeelMultiInstanceDataSet"); algConf.addProperty("process.algorithm.evaluator.dataset.file-name", trainFile); algConf.addProperty("process.algorithm.evaluator.max-deriv-size", Integer.parseInt(props.getProperty("max-deriv-size"))); algConf.addProperty("process.algorithm.provider[@type]", "org.ayrna.jclec.syntaxtree.SyntaxTreeCreator"); algConf.addProperty("process.algorithm.parents-selector[@type]", "org.ayrna.jclec.selector.RouletteSelector"); algConf.addProperty("process.algorithm.recombinator.decorated[@type]", "org.ayrna.jclec.problem.classification.syntaxtree.multiinstance.G3PMIKeel.G3PMICrossover"); algConf.addProperty("process.algorithm.recombinator.recombination-prob", Double.parseDouble(props.getProperty("rec-prob"))); algConf.addProperty("process.algorithm.mutator.decorated[@type]", "org.ayrna.jclec.problem.classification.syntaxtree.multiinstance.G3PMIKeel.G3PMIMutator"); algConf.addProperty("process.algorithm.mutator.mutation-prob", Double.parseDouble(props.getProperty("mut-prob"))); algConf.addProperty("process.listeners.listener[@type]", "org.ayrna.jclec.problem.classification.syntaxtree.multiinstance.G3PMIKeel.G3PMIPopulationReport"); algConf.addProperty("process.listeners.listener.report-dir-name", "./"); algConf.addProperty("process.listeners.listener.train-report-file", reportTrainFile); algConf.addProperty("process.listeners.listener.test-report-file", reportTestFile); algConf.addProperty("process.listeners.listener.global-report-name", "resumen"); algConf.addProperty("process.listeners.listener.report-frequency", 50); algConf.addProperty("process.listeners.listener.test-dataset[@type]", "org.ayrna.jclec.util.dataset.KeelMultiInstanceDataSet"); algConf.addProperty("process.listeners.listener.test-dataset.file-name", testFile); try { algConf.save(new File("configure.txt")); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } org.ayrna.jclec.genlab.GenLab.main(new String[] { "configure.txt" }); }
From source file:com.example.TestClass.java
@Test public void testWithOnlyCommaWithoutDelimiterParsing() throws Exception { String source = "<configuration><key0></key0><key1>,</key1><key2></key2><key3></key3></configuration>"; XMLConfiguration config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); config.load(new StringReader(source)); checkConfiguration(config);//from w ww . java2 s . c o m }