Search in sources :

Example 1 with OptionID

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

the class VisualizerParameterizer method getTitle.

/**
 * Try to automatically generate a title for this.
 *
 * @param db Database
 * @param result Result object
 * @return generated title
 */
public static String getTitle(Database db, Result result) {
    List<TrackedParameter> settings = new ArrayList<>();
    for (SettingsResult sr : SettingsResult.getSettingsResults(result)) {
        settings.addAll(sr.getSettings());
    }
    String algorithm = null;
    String distance = null;
    String dataset = null;
    for (TrackedParameter setting : settings) {
        Parameter<?> param = setting.getParameter();
        OptionID option = param.getOptionID();
        String value = param.isDefined() ? param.getValueAsString() : null;
        if (option.equals(AlgorithmStep.Parameterizer.ALGORITHM_ID)) {
            algorithm = value;
        }
        if (option.equals(DistanceBasedAlgorithm.DISTANCE_FUNCTION_ID)) {
            distance = value;
        }
        if (option.equals(FileBasedDatabaseConnection.Parameterizer.INPUT_ID)) {
            dataset = value;
        }
    }
    StringBuilder buf = new StringBuilder();
    if (algorithm != null) {
        buf.append(shortenClassname(algorithm.split(",")[0], '.'));
    }
    if (distance != null) {
        if (buf.length() > 0) {
            buf.append(" using ");
        }
        buf.append(shortenClassname(distance, '.'));
    }
    if (dataset != null) {
        if (buf.length() > 0) {
            buf.append(" on ");
        }
        buf.append(shortenClassname(dataset, File.separatorChar));
    }
    if (buf.length() > 0) {
        return buf.toString();
    }
    return null;
}
Also used : OptionID(de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID) ArrayList(java.util.ArrayList) SettingsResult(de.lmu.ifi.dbs.elki.result.SettingsResult) TrackedParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackedParameter)

Example 2 with OptionID

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

the class DocumentParameters method makeByOptOverviewHTML.

private static Document makeByOptOverviewHTML(Map<OptionID, List<Pair<Parameter<?>, Class<?>>>> byopt) throws IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e1) {
        throw new IOException(e1);
    }
    DOMImplementation impl = builder.getDOMImplementation();
    Document htmldoc = impl.createDocument(HTMLUtil.HTML_NAMESPACE, HTMLUtil.HTML_HTML_TAG, null);
    // head
    Element head = htmldoc.createElement(HTMLUtil.HTML_HEAD_TAG);
    htmldoc.getDocumentElement().appendChild(head);
    // body
    Element body = htmldoc.createElement(HTMLUtil.HTML_BODY_TAG);
    htmldoc.getDocumentElement().appendChild(body);
    // modification warnings
    head.appendChild(htmldoc.createComment(MODIFICATION_WARNING));
    body.appendChild(htmldoc.createComment(MODIFICATION_WARNING));
    // meta with charset information
    {
        Element meta = htmldoc.createElement(HTMLUtil.HTML_META_TAG);
        meta.setAttribute(HTMLUtil.HTML_HTTP_EQUIV_ATTRIBUTE, HTMLUtil.HTML_HTTP_EQUIV_CONTENT_TYPE);
        meta.setAttribute(HTMLUtil.HTML_CONTENT_ATTRIBUTE, HTMLUtil.CONTENT_TYPE_HTML_UTF8);
        head.appendChild(meta);
    }
    // stylesheet
    {
        Element css = htmldoc.createElement(HTMLUtil.HTML_LINK_TAG);
        css.setAttribute(HTMLUtil.HTML_REL_ATTRIBUTE, HTMLUtil.HTML_REL_STYLESHEET);
        css.setAttribute(HTMLUtil.HTML_TYPE_ATTRIBUTE, HTMLUtil.CONTENT_TYPE_CSS);
        css.setAttribute(HTMLUtil.HTML_HREF_ATTRIBUTE, CSSFILE);
        head.appendChild(css);
    }
    // title
    {
        Element title = htmldoc.createElement(HTMLUtil.HTML_TITLE_TAG);
        title.setTextContent("Command line parameter overview - by option");
        head.appendChild(title);
    }
    // Heading
    {
        Element h1 = htmldoc.createElement(HTMLUtil.HTML_H1_TAG);
        h1.setTextContent("ELKI command line parameter overview:");
        body.appendChild(h1);
    }
    // Main definition list
    Element maindl = htmldoc.createElement(HTMLUtil.HTML_DL_TAG);
    body.appendChild(maindl);
    final Comparator<OptionID> osort = new SortByOption();
    final Comparator<Class<?>> csort = new ELKIServiceScanner.ClassSorter();
    Comparator<Pair<Parameter<?>, Class<?>>> psort = new Comparator<Pair<Parameter<?>, Class<?>>>() {

        @Override
        public int compare(Pair<Parameter<?>, Class<?>> o1, Pair<Parameter<?>, Class<?>> o2) {
            int c = osort.compare(o1.first.getOptionID(), o2.first.getOptionID());
            return (c != 0) ? c : csort.compare(o1.second, o2.second);
        }
    };
    List<OptionID> opts = new ArrayList<>(byopt.keySet());
    Collections.sort(opts, osort);
    for (OptionID oid : opts) {
        final Parameter<?> firstopt = byopt.get(oid).get(0).getFirst();
        // DT = definition term
        Element optdt = htmldoc.createElement(HTMLUtil.HTML_DT_TAG);
        // Anchor for references
        {
            Element optan = htmldoc.createElement(HTMLUtil.HTML_A_TAG);
            optan.setAttribute(HTMLUtil.HTML_NAME_ATTRIBUTE, firstopt.getOptionID().getName());
            optdt.appendChild(optan);
        }
        // option name
        {
            Element elemtt = htmldoc.createElement(HTMLUtil.HTML_TT_TAG);
            elemtt.setTextContent(SerializedParameterization.OPTION_PREFIX + firstopt.getOptionID().getName() + " " + firstopt.getSyntax());
            optdt.appendChild(elemtt);
        }
        maindl.appendChild(optdt);
        // DD = definition description
        Element optdd = htmldoc.createElement(HTMLUtil.HTML_DD_TAG);
        {
            Element elemp = htmldoc.createElement(HTMLUtil.HTML_P_TAG);
            HTMLUtil.appendMultilineText(htmldoc, elemp, firstopt.getShortDescription());
            optdd.appendChild(elemp);
        }
        // class restriction?
        Class<?> superclass = getRestrictionClass(oid, firstopt, byopt);
        if (superclass != null) {
            appendClassRestriction(htmldoc, superclass, optdd);
        }
        // default value?
        appendDefaultValueIfSet(htmldoc, firstopt, optdd);
        // known values?
        if (superclass != null) {
            appendKnownImplementationsIfNonempty(htmldoc, superclass, optdd);
        }
        maindl.appendChild(optdd);
        // nested definition list for options
        Element classesul = htmldoc.createElement(HTMLUtil.HTML_UL_TAG);
        {
            Element p = htmldoc.createElement(HTMLUtil.HTML_P_TAG);
            p.appendChild(htmldoc.createTextNode(HEADER_PARAMETER_FOR));
            optdd.appendChild(p);
        }
        optdd.appendChild(classesul);
        List<Pair<Parameter<?>, Class<?>>> plist = byopt.get(oid);
        Collections.sort(plist, psort);
        for (Pair<Parameter<?>, Class<?>> clinst : plist) {
            // DT definition term: option name, in TT for typewriter optics
            Element classli = htmldoc.createElement(HTMLUtil.HTML_LI_TAG);
            // Link back to original class
            {
                Element classa = htmldoc.createElement(HTMLUtil.HTML_A_TAG);
                classa.setAttribute(HTMLUtil.HTML_HREF_ATTRIBUTE, linkForClassName(clinst.getSecond().getName()));
                classa.setTextContent(clinst.getSecond().getName());
                classli.appendChild(classa);
            }
            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)) {
                        appendClassRestriction(htmldoc, cls.getRestrictionClass(), classli);
                    }
                } else {
                    appendNoClassRestriction(htmldoc, classli);
                }
            }
            Parameter<?> param = clinst.getFirst();
            if (param.getDefaultValue() != null) {
                if (!param.getDefaultValue().equals(firstopt.getDefaultValue())) {
                    appendDefaultValueIfSet(htmldoc, param, classli);
                }
            } else if (firstopt.getDefaultValue() != null) {
                appendNoDefaultValue(htmldoc, classli);
            }
            classesul.appendChild(classli);
        }
    }
    return htmldoc;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) Comparator(java.util.Comparator) OptionID(de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Pair(de.lmu.ifi.dbs.elki.utilities.pairs.Pair) IOException(java.io.IOException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) 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 3 with OptionID

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

the class DocumentParameters method main.

/**
 * @param args Command line arguments
 */
public static void main(String[] args) {
    LoggingConfiguration.setVerbose(Level.VERBOSE);
    if (args.length != 2 && args.length != 4) {
        LOG.warning("I need exactly two or four file names to operate!");
        System.exit(1);
    }
    if (!args[0].endsWith(".html")) {
        LOG.warning("First file name doesn't end with .html!");
        System.exit(1);
    }
    if (!args[1].endsWith(".html")) {
        LOG.warning("Second file name doesn't end with .html!");
        System.exit(1);
    }
    if (args.length > 2 && !args[2].endsWith(".trac")) {
        LOG.warning("Third file name doesn't end with .trac!");
        System.exit(1);
    }
    if (args.length > 3 && !args[3].endsWith(".trac")) {
        LOG.warning("Fourth file name doesn't end with .trac!");
        System.exit(1);
    }
    File byclsname = new File(args[0]);
    File byoptname = new File(args[1]);
    File byclsnamew = args.length >= 3 ? new File(args[2]) : null;
    File byoptnamew = args.length >= 4 ? new File(args[3]) : null;
    try {
        Files.createDirectories(byclsname.toPath().getParent());
        Files.createDirectories(byoptname.toPath().getParent());
        if (byclsnamew != null) {
            Files.createDirectories(byclsnamew.toPath().getParent());
        }
        if (byoptnamew != null) {
            Files.createDirectories(byoptnamew.toPath().getParent());
        }
    } catch (IOException e) {
        LOG.exception(e);
        System.exit(1);
    }
    Map<Class<?>, List<Parameter<?>>> byclass = new HashMap<>();
    Map<OptionID, List<Pair<Parameter<?>, Class<?>>>> byopt = new HashMap<>();
    try {
        buildParameterIndex(byclass, byopt);
    } catch (Exception e) {
        LOG.exception(e);
        System.exit(1);
    }
    try (// 
    FileOutputStream byclassfo = new FileOutputStream(byclsname);
        OutputStream byclassstream = new BufferedOutputStream(byclassfo)) {
        Document byclassdoc = makeByClassOverviewHTML(byclass);
        HTMLUtil.writeXHTML(byclassdoc, byclassstream);
    } catch (IOException e) {
        LOG.exception("IO Exception writing output.", e);
        System.exit(1);
    }
    if (byclsnamew != null) {
        try (// 
        FileOutputStream byclassfo = new FileOutputStream(byclsnamew);
            PrintStream byclassstream = new PrintStream(new BufferedOutputStream(byclassfo), false, "UTF-8")) {
            makeByClassOverviewWiki(byclass, new WikiStream(byclassstream));
        } catch (IOException e) {
            LOG.exception("IO Exception writing output.", e);
            System.exit(1);
        }
    }
    try (// 
    FileOutputStream byoptfo = new FileOutputStream(byoptname);
        OutputStream byoptstream = new BufferedOutputStream(byoptfo)) {
        Document byoptdoc = makeByOptOverviewHTML(byopt);
        HTMLUtil.writeXHTML(byoptdoc, byoptfo);
    } catch (IOException e) {
        LOG.exception("IO Exception writing output.", e);
        System.exit(1);
    }
    if (byoptnamew != null) {
        try (// 
        FileOutputStream byoptfo = new FileOutputStream(byoptnamew);
            PrintStream byoptstream = new PrintStream(new BufferedOutputStream(byoptfo))) {
            makeByOptOverviewWiki(byopt, new WikiStream(byoptstream));
        } catch (IOException e) {
            LOG.exception("IO Exception writing output.", e);
            throw new RuntimeException(e);
        }
    }
    // Forcibly terminate, as some class may have spawned a thread.
    System.exit(0);
}
Also used : PrintStream(java.io.PrintStream) HashMap(java.util.HashMap) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) OptionID(de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID) FileOutputStream(java.io.FileOutputStream) 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) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 4 with OptionID

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID 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)

Aggregations

OptionID (de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID)4 TrackedParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackedParameter)4 ArrayList (java.util.ArrayList)4 ClassListParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassListParameter)3 ClassParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter)3 Parameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter)3 RandomParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.RandomParameter)3 IOException (java.io.IOException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Document (org.w3c.dom.Document)2 SettingsResult (de.lmu.ifi.dbs.elki.result.SettingsResult)1 Pair (de.lmu.ifi.dbs.elki.utilities.pairs.Pair)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1