use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization in project elki by elki-project.
the class OptionUtil method describeParameterizable.
/**
* Format a description of a Parameterizable (including recursive options).
*
* @param buf Buffer to append to.
* @param pcls Parameterizable class to describe
* @param width Width
* @param indent Text indent
* @return Formatted description
*/
public static StringBuilder describeParameterizable(StringBuilder buf, Class<?> pcls, int width, String indent) {
try {
println(buf, width, "Description for class " + pcls.getName(), "");
String title = DocumentationUtil.getTitle(pcls);
if (title != null && title.length() > 0) {
println(buf, width, title, "");
}
String desc = DocumentationUtil.getDescription(pcls);
if (desc != null && desc.length() > 0) {
println(buf, width, desc, " ");
}
Reference ref = DocumentationUtil.getReference(pcls);
if (ref != null) {
if (ref.prefix().length() > 0) {
println(buf, width, ref.prefix(), "");
}
println(buf, width, ref.authors() + ":", "");
println(buf, width, ref.title(), " ");
println(buf, width, "in: " + ref.booktitle(), "");
if (ref.url().length() > 0) {
println(buf, width, "see also: " + ref.url(), "");
}
}
SerializedParameterization config = new SerializedParameterization();
TrackParameters track = new TrackParameters(config);
@SuppressWarnings("unused") Object p = ClassGenericsUtil.tryInstantiate(Object.class, pcls, track);
Collection<TrackedParameter> options = track.getAllParameters();
if (!options.isEmpty()) {
OptionUtil.formatForConsole(buf, width, indent, options);
}
return buf;
} catch (Exception e) {
LoggingUtil.exception("Error instantiating class to describe.", e.getCause());
return buf.append("No description available: ").append(e);
}
}
use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization in project elki by elki-project.
the class MiniGUI method doSetParameters.
/**
* Do the actual setParameters invocation.
*
* @param params Parameters
*/
protected void doSetParameters(List<String> params) {
if (!params.isEmpty()) {
String first = params.get(0);
if (!first.startsWith("-")) {
Class<? extends AbstractApplication> c = ELKIServiceRegistry.findImplementation(AbstractApplication.class, first);
if (c != null) {
maincls = c;
params.remove(0);
}
}
}
outputArea.clear();
SerializedParameterization config = new SerializedParameterization(params);
TrackParameters track = new TrackParameters(config);
track.tryInstantiate(LoggingStep.class);
track.tryInstantiate(maincls);
config.logUnusedParameters();
// config.logAndClearReportedErrors();
final boolean hasErrors = (config.getErrors().size() > 0);
if (hasErrors && !params.isEmpty()) {
reportErrors(config);
}
runButton.setEnabled(!hasErrors);
List<String> remainingParameters = config.getRemainingParameters();
String mainnam = maincls.getCanonicalName();
if (mainnam.startsWith(APP_PREFIX)) {
mainnam = mainnam.substring(APP_PREFIX.length());
}
commandLine.setText(format(mainnam, params));
// update table:
parameterTable.removeEditor();
parameterTable.setEnabled(false);
parameters.updateFromTrackParameters(track);
// Add remaining parameters
if (remainingParameters != null && !remainingParameters.isEmpty()) {
DynamicParameters.RemainingOptions remo = new DynamicParameters.RemainingOptions();
try {
remo.setValue(FormatUtil.format(remainingParameters, " "));
} catch (ParameterException e) {
LOG.exception(e);
}
int bits = DynamicParameters.BIT_INVALID | DynamicParameters.BIT_SYNTAX_ERROR;
parameters.addParameter(remo, remo.getValue(), bits, 0);
}
config.clearErrors();
parameterTable.revalidate();
parameterTable.setEnabled(true);
}
use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization in project elki by elki-project.
the class MiniGUI method startTask.
/**
* Do a full run of the KDDTask with the specified parameters.
*/
protected void startTask() {
parameterTable.editCellAt(-1, -1);
parameterTable.setEnabled(false);
final ArrayList<String> params = new ArrayList<>(parameters.size() * 2);
parameters.serializeParameters(params);
parameterTable.setEnabled(true);
runButton.setEnabled(false);
outputArea.clear();
SwingWorker<Void, Void> r = new SwingWorker<Void, Void>() {
@Override
public Void doInBackground() {
SerializedParameterization config = new SerializedParameterization(params);
config.tryInstantiate(LoggingStep.class);
AbstractApplication task = config.tryInstantiate(maincls);
try {
config.logUnusedParameters();
if (config.getErrors().size() == 0) {
task.run();
} else {
reportErrors(config);
}
LOG.debug("Task completed successfully.");
} catch (Throwable e) {
LOG.exception("Task failed", e);
}
return null;
}
@Override
protected void done() {
super.done();
runButton.setEnabled(true);
}
};
r.execute();
}
use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization in project elki by elki-project.
the class MultiStepGUI method main.
/**
* Main method that just spawns the UI.
*
* @param args command line parameters
*/
public static void main(final String[] args) {
GUIUtil.logUncaughtExceptions(LOG);
GUIUtil.setLookAndFeel();
OutputStep.setDefaultHandlerVisualizer();
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
final MultiStepGUI gui = new MultiStepGUI();
gui.run();
if (args != null && args.length > 0) {
gui.setParameters(new SerializedParameterization(args));
} else {
gui.setParameters(new SerializedParameterization());
}
} catch (Exception | Error e) {
// Restore error handler, as the GUI is likely broken.
LoggingConfiguration.replaceDefaultHandler(new CLISmartHandler());
LOG.exception(e);
}
}
});
}
use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization in project elki by elki-project.
the class AbstractApplication method runCLIApplication.
/**
* Generic command line invocation.
*
* Refactored to have a central place for outermost exception handling.
*
* @param cls Application class to run.
* @param args the arguments to run this application with
*/
public static void runCLIApplication(Class<?> cls, String[] args) {
SerializedParameterization params = new SerializedParameterization(args);
Flag helpF = new Flag(Parameterizer.HELP_ID);
params.grab(helpF);
Flag helpLongF = new Flag(Parameterizer.HELP_LONG_ID);
params.grab(helpLongF);
try {
ClassParameter<Object> descriptionP = new ClassParameter<>(Parameterizer.DESCRIPTION_ID, Object.class, true);
params.grab(descriptionP);
if (descriptionP.isDefined()) {
params.clearErrors();
printDescription(descriptionP.getValue());
System.exit(1);
}
// Parse debug parameter
StringParameter debugP = new StringParameter(Parameterizer.DEBUG_ID).setOptional(true);
params.grab(debugP);
if (debugP.isDefined()) {
Parameterizer.parseDebugParameter(debugP);
}
// Fail silently on errors.
if (params.getErrors().size() > 0) {
params.logAndClearReportedErrors();
System.exit(1);
}
} catch (Exception e) {
printErrorMessage(e);
System.exit(1);
}
try {
TrackParameters config = new TrackParameters(params);
Flag verboseF = new Flag(Parameterizer.VERBOSE_ID);
if (config.grab(verboseF) && verboseF.isTrue()) {
// Extra verbosity by repeating the flag:
Flag verbose2F = new Flag(Parameterizer.VERBOSE_ID);
LoggingConfiguration.setVerbose((config.grab(verbose2F) && verbose2F.isTrue()) ? Level.VERYVERBOSE : Level.VERBOSE);
}
AbstractApplication task = ClassGenericsUtil.tryInstantiate(AbstractApplication.class, cls, config);
if ((helpF.isDefined() && helpF.getValue()) || (helpLongF.isDefined() && helpLongF.getValue())) {
LoggingConfiguration.setVerbose(Level.VERBOSE);
LOG.verbose(usage(config.getAllParameters()));
System.exit(1);
}
if (params.getErrors().size() > 0) {
LoggingConfiguration.setVerbose(Level.VERBOSE);
LOG.verbose("ERROR: The following configuration errors prevented execution:");
for (ParameterException e : params.getErrors()) {
LOG.verbose(e.getMessage());
LOG.verbose("\n");
}
params.logUnusedParameters();
LOG.verbose("Stopping execution because of configuration errors above.");
System.exit(1);
}
params.logUnusedParameters();
task.run();
} catch (Exception e) {
printErrorMessage(e);
}
}
Aggregations