Search in sources :

Example 6 with ClassParameter

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter in project elki by elki-project.

the class DocumentParameters method makeByOptOverviewWiki.

private static void makeByOptOverviewWiki(Map<OptionID, List<Pair<Parameter<?>, Class<?>>>> byopt, WikiStream out) {
    List<OptionID> opts = new ArrayList<>(byopt.keySet());
    Collections.sort(opts, new SortByOption());
    for (OptionID oid : opts) {
        final Parameter<?> firstopt = byopt.get(oid).get(0).getFirst();
        out.indent = 1;
        // 
        out.printitem("").print("{{{").print(SerializedParameterization.OPTION_PREFIX).print(firstopt.getOptionID().getName()).print(' ').print(firstopt.getSyntax()).println("}}}:: ");
        // No BR needed, we increase the indent.
        out.newline = 1;
        out.indent = 2;
        appendMultilineTextWiki(out, firstopt.getShortDescription());
        // class restriction?
        Class<?> superclass = getRestrictionClass(oid, firstopt, byopt);
        if (superclass != null) {
            appendClassRestrictionWiki(out, superclass);
        }
        // default value?
        if (firstopt.hasDefaultValue()) {
            appendDefaultValueWiki(out, firstopt);
        }
        if (FULL_WIKI_OUTPUT) {
            // known values?
            if (superclass != null) {
                appendKnownImplementationsWiki(out, superclass);
            }
            // List of classes that use this parameter
            out.println("Used by:");
            for (Pair<Parameter<?>, Class<?>> clinst : byopt.get(oid)) {
                out.indent = 3;
                out.printitem("* ").javadocLink(clinst.getSecond(), null).println();
                if (clinst.getFirst() instanceof ClassParameter<?> && firstopt instanceof ClassParameter<?>) {
                    ClassParameter<?> cls = (ClassParameter<?>) clinst.getFirst();
                    if (cls.getRestrictionClass() != null) {
                        // TODO: if it is null, it could still be different!
                        if (!cls.getRestrictionClass().equals(superclass)) {
                            appendClassRestrictionWiki(out, cls.getRestrictionClass());
                        }
                    } else {
                        appendNoClassRestrictionWiki(out);
                    }
                }
                Parameter<?> param = clinst.getFirst();
                if (param.getDefaultValue() != null) {
                    if (!param.getDefaultValue().equals(firstopt.getDefaultValue())) {
                        appendDefaultValueWiki(out, param);
                    }
                } else if (firstopt.getDefaultValue() != null) {
                    appendNoDefaultValueWiki(out);
                }
                out.println();
            }
        }
    }
}
Also used : OptionID(de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID) ArrayList(java.util.ArrayList) RandomParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.RandomParameter) ClassParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter) Parameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter) ClassListParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassListParameter) TrackedParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackedParameter) ClassParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter)

Example 7 with ClassParameter

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter in project elki by elki-project.

the class DocumentParameters method appendDefaultClassLink.

private static void appendDefaultClassLink(Document htmldoc, Parameter<?> opt, Element p) {
    Element defa = htmldoc.createElement(HTMLUtil.HTML_A_TAG);
    defa.setAttribute(HTMLUtil.HTML_HREF_ATTRIBUTE, linkForClassName(((ClassParameter<?>) opt).getDefaultValue().getCanonicalName()));
    defa.setTextContent(((ClassParameter<?>) opt).getDefaultValue().getCanonicalName());
    p.appendChild(defa);
}
Also used : Element(org.w3c.dom.Element) ClassParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter)

Example 8 with ClassParameter

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter 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);
    }
}
Also used : StringParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.StringParameter) SerializedParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization) UnspecifiedParameterException(de.lmu.ifi.dbs.elki.utilities.optionhandling.UnspecifiedParameterException) ParameterException(de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException) ClassParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter) Flag(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Flag) UnspecifiedParameterException(de.lmu.ifi.dbs.elki.utilities.optionhandling.UnspecifiedParameterException) WrongParameterValueException(de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) ParameterException(de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException) TrackParameters(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackParameters)

Aggregations

ClassParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter)8 Element (org.w3c.dom.Element)5 TrackedParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackedParameter)4 RandomParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.RandomParameter)3 ArrayList (java.util.ArrayList)3 OptionID (de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID)2 ClassListParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassListParameter)2 Parameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 DOMImplementation (org.w3c.dom.DOMImplementation)2 Document (org.w3c.dom.Document)2 SettingsResult (de.lmu.ifi.dbs.elki.result.SettingsResult)1 ELKIServiceScanner (de.lmu.ifi.dbs.elki.utilities.ELKIServiceScanner)1 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)1 ParameterException (de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException)1 UnspecifiedParameterException (de.lmu.ifi.dbs.elki.utilities.optionhandling.UnspecifiedParameterException)1 WrongParameterValueException (de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException)1 SerializedParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization)1