getEvaluators() {
return evaluators;
}
/**
*
* returns the result storages
*
*
* @return result storages
*/
public List getResultStorages() {
return resultStorages;
}
/**
* returns boolean, if classifier should be saved
*
* @return boolean
*/
public boolean getSaveClassifier() {
return saveClassifier;
}
/**
* number of repetitions of an experiment
*
* @return number of repetitions
*/
public int getRepetitions() {
return repetitions;
}
/**
* returns the execution strategy
*
* @return String execution strategy
*/
public String getExecutionStrategy() {
return executionStrategy;
}
/*
* (non-Javadoc)
*
* @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String,
* java.lang.String, org.xml.sax.Attributes)
*/
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException
{
try {
if (qName.equals("config")) {
// ingore
}
else if (qName.equals("loader")) {
final IVersionLoader loader = (IVersionLoader) Class
.forName("de.ugoe.cs.cpdp.loader." + attributes.getValue("name")).newInstance();
loader.setLocation(attributes.getValue("datalocation"));
loaders.add(loader);
// TODO location as relative
}
else if (qName.equals("resultspath")) {
resultsPath = attributes.getValue("path");
}
else if (qName.equals("versionfilter")) {
final IVersionFilter filter = (IVersionFilter) Class
.forName("de.ugoe.cs.cpdp.versions." + attributes.getValue("name"))
.newInstance();
filter.setParameter(attributes.getValue("param"));
versionFilters.add(filter);
}
else if (qName.equals("testVersionfilter")) {
final IVersionFilter filter = (IVersionFilter) Class
.forName("de.ugoe.cs.cpdp.versions." + attributes.getValue("name"))
.newInstance();
filter.setParameter(attributes.getValue("param"));
testVersionFilters.add(filter);
}
else if (qName.equals("trainVersionfilter")) {
final IVersionFilter filter = (IVersionFilter) Class
.forName("de.ugoe.cs.cpdp.versions." + attributes.getValue("name"))
.newInstance();
filter.setParameter(attributes.getValue("param"));
trainingVersionFilters.add(filter);
}
else if (qName.equals("setwisepreprocessor")) {
final ISetWiseProcessingStrategy processor = (ISetWiseProcessingStrategy) Class
.forName("de.ugoe.cs.cpdp.dataprocessing." + attributes.getValue("name"))
.newInstance();
processor.setParameter(attributes.getValue("param"));
setwisepreprocessors.add(processor);
}
else if (qName.equals("setwiseselector")) {
final ISetWiseDataselectionStrategy selection =
(ISetWiseDataselectionStrategy) Class
.forName("de.ugoe.cs.cpdp.dataselection." + attributes.getValue("name"))
.newInstance();
selection.setParameter(attributes.getValue("param"));
setwiseselectors.add(selection);
}
else if (qName.equals("setwisepostprocessor")) {
final ISetWiseProcessingStrategy processor = (ISetWiseProcessingStrategy) Class
.forName("de.ugoe.cs.cpdp.dataprocessing." + attributes.getValue("name"))
.newInstance();
processor.setParameter(attributes.getValue("param"));
setwisepostprocessors.add(processor);
}
else if (qName.equals("setwisetrainer")) {
final ISetWiseTrainingStrategy trainer = (ISetWiseTrainingStrategy) Class
.forName("de.ugoe.cs.cpdp.training." + attributes.getValue("name"))
.newInstance();
trainer.setParameter(attributes.getValue("param"));
setwiseTrainers.add(trainer);
}
else if (qName.equals("setwisetestdataawaretrainer")) {
final ISetWiseTestdataAwareTrainingStrategy trainer =
(ISetWiseTestdataAwareTrainingStrategy) Class
.forName("de.ugoe.cs.cpdp.training." + attributes.getValue("name"))
.newInstance();
trainer.setParameter(attributes.getValue("param"));
trainer.setMethod(attributes.getValue("method"));
trainer.setThreshold(attributes.getValue("threshold"));
setwiseTestdataAwareTrainers.add(trainer);
}
else if (qName.equals("preprocessor")) {
final IProcessesingStrategy processor = (IProcessesingStrategy) Class
.forName("de.ugoe.cs.cpdp.dataprocessing." + attributes.getValue("name"))
.newInstance();
processor.setParameter(attributes.getValue("param"));
preprocessors.add(processor);
}
else if (qName.equals("pointwiseselector")) {
final IPointWiseDataselectionStrategy selection =
(IPointWiseDataselectionStrategy) Class
.forName("de.ugoe.cs.cpdp.dataselection." + attributes.getValue("name"))
.newInstance();
selection.setParameter(attributes.getValue("param"));
pointwiseselectors.add(selection);
}
else if (qName.equals("postprocessor")) {
final IProcessesingStrategy processor = (IProcessesingStrategy) Class
.forName("de.ugoe.cs.cpdp.dataprocessing." + attributes.getValue("name"))
.newInstance();
processor.setParameter(attributes.getValue("param"));
postprocessors.add(processor);
}
else if (qName.equals("trainer")) {
final ITrainingStrategy trainer = (ITrainingStrategy) Class
.forName("de.ugoe.cs.cpdp.training." + attributes.getValue("name"))
.newInstance();
trainer.setParameter(attributes.getValue("param"));
trainers.add(trainer);
}
else if (qName.equals("testawaretrainer")) {
final ITestAwareTrainingStrategy trainer = (ITestAwareTrainingStrategy) Class
.forName("de.ugoe.cs.cpdp.training." + attributes.getValue("name"))
.newInstance();
trainer.setParameter(attributes.getValue("param"));
testAwareTrainers.add(trainer);
}
else if (qName.equals("eval")) {
final IEvaluationStrategy evaluator = (IEvaluationStrategy) Class
.forName("de.ugoe.cs.cpdp.eval." + attributes.getValue("name")).newInstance();
evaluators.add(evaluator);
}
else if (qName.equals("storage")) {
final IResultStorage resultStorage = (IResultStorage) Class
.forName("de.ugoe.cs.cpdp.eval." + attributes.getValue("name")).newInstance();
resultStorages.add(resultStorage);
}
else if (qName.equals("saveClassifier")) {
saveClassifier = true;
}
else if (qName.equals("repetitions")) {
repetitions = Integer.parseInt(attributes.getValue("number"));
}
else if (qName.equals("executionStrategy")) {
executionStrategy = attributes.getValue("name");
}
else if (qName.equals("partialconfig")) {
String path = attributes.getValue("path");
try {
boolean relative = true;
if (attributes.getValue("relative") != null) {
relative = Boolean.parseBoolean(attributes.getValue("relative"));
}
if (relative) {
path = configFile.getParentFile().getPath() + "/" + path;
}
addConfigurations(new ExperimentConfiguration(path));
}
catch (ExperimentConfigurationException e) {
throw new SAXException("Could not load partial configuration: " + path, e);
}
}
else {
Console.traceln(Level.WARNING, "element in config-file " + configFile.getName() +
" ignored: " + qName);
}
}
catch (NoClassDefFoundError | ClassNotFoundException | IllegalAccessException
| InstantiationException | ClassCastException e)
{
throw new SAXException("Could not initialize class correctly", (Exception) e);
}
}
/**
* Adds the information of another experiment configuration to this configuration. This
* mechanism allows the usage of partial configuration files. The name of the other
* configuration is lost.
*
* If the current data path is the empty string (""), it is override by the datapath
* of the other configuration. Otherwise, the current data path is kept.
*
* @param other
* experiment whose information is added
* @throws ExperimentConfigurationException
*/
private void addConfigurations(ExperimentConfiguration other)
throws ExperimentConfigurationException
{
if ("results".equals(resultsPath)) {
resultsPath = other.resultsPath;
}
loaders.addAll(other.loaders);
versionFilters.addAll(other.versionFilters);
testVersionFilters.addAll(other.testVersionFilters);
trainingVersionFilters.addAll(other.trainingVersionFilters);
setwisepreprocessors.addAll(other.setwisepreprocessors);
setwiseselectors.addAll(other.setwiseselectors);
setwisepostprocessors.addAll(other.setwisepostprocessors);
setwiseTrainers.addAll(other.setwiseTrainers);
setwiseTestdataAwareTrainers.addAll(other.setwiseTestdataAwareTrainers);
preprocessors.addAll(other.preprocessors);
pointwiseselectors.addAll(other.pointwiseselectors);
postprocessors.addAll(other.postprocessors);
trainers.addAll(other.trainers);
evaluators.addAll(other.evaluators);
if (!executionStrategy.equals(other.executionStrategy)) {
throw new ExperimentConfigurationException("Executionstrategies must be the same, if config files should be added.");
}
/*
* Only if saveClassifier is not set in the main config and the other configs saveClassifier
* is true, it must be set.
*/
if (saveClassifier == null && other.saveClassifier == true) {
saveClassifier = other.saveClassifier;
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("Experiment name: " + experimentName + StringTools.ENDLINE);
builder.append("Loaders: " + loaders + StringTools.ENDLINE);
builder.append("Results path: " + resultsPath + StringTools.ENDLINE);
builder.append("Version filters: " + versionFilters.toString() + StringTools.ENDLINE);
builder
.append("Test version filters: " + testVersionFilters.toString() + StringTools.ENDLINE);
builder.append("Training version filters: " + trainingVersionFilters.toString() +
StringTools.ENDLINE);
builder.append("Setwise preprocessors: " + setwisepreprocessors.toString() +
StringTools.ENDLINE);
builder.append("Setwise selectors: " + setwiseselectors.toString() + StringTools.ENDLINE);
builder.append("Setwise postprocessors: " + setwisepostprocessors.toString() +
StringTools.ENDLINE);
builder.append("Setwise trainers: " + setwiseTrainers.toString() + StringTools.ENDLINE);
builder.append("Setwise Testdata Aware trainers: " +
setwiseTestdataAwareTrainers.toString() + StringTools.ENDLINE);
builder
.append("Pointwise preprocessors: " + preprocessors.toString() + StringTools.ENDLINE);
builder
.append("Pointwise selectors: " + pointwiseselectors.toString() + StringTools.ENDLINE);
builder
.append("Pointwise postprocessors: " + postprocessors.toString() + StringTools.ENDLINE);
builder.append("Pointwise trainers: " + trainers.toString() + StringTools.ENDLINE);
builder.append("Evaluators: " + evaluators.toString() + StringTools.ENDLINE);
builder.append("Save Classifier?: " + saveClassifier + StringTools.ENDLINE);
builder.append("Execution Strategy: " + executionStrategy + StringTools.ENDLINE);
return builder.toString();
}
}