Example usage for weka.core TechnicalInformation toString

List of usage examples for weka.core TechnicalInformation toString

Introduction

In this page you can find the example usage for weka.core TechnicalInformation toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns a plain-text string representing this technical information.

Usage

From source file:com.rapidminer.doc.AbstractOperatorDocGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
public void generateDoc(Operator op, RootDoc rootDoc, PrintWriter out) {
    ClassDoc opDoc = rootDoc.classNamed(op.getClass().getName());

    out.println(getOpenTag(OPERATOR));//from  w w w  .j a v a  2 s .c o m
    printTags(out, op.getOperatorDescription().getName(), OPERATOR_NAME);
    out.println();

    if (op.getOperatorDescription().getIconPath() != null)
        out.println(marginIcon(op.getOperatorDescription().getIconPath()));

    if ((op.getOperatorDescription().getGroup() != null)
            && (op.getOperatorDescription().getGroup().trim().length() > 0))
        printTags(out, op.getOperatorDescription().getGroup(), GROUP_NAME);

    if (opDoc != null) {
        Tag[] indexTags = opDoc.tags("rapidminer.index");
        for (int i = 0; i < indexTags.length; i++) {
            printTags(out, indexTags[i].text(), INDEX_ENTRY);
        }
    }

    if (op.getDeprecationInfo() != null) {
        printTags(out, op.getDeprecationInfo(), DEPRECATION_INFO);
        out.println();
    }

    Class[] input = op.getInputClasses();
    if ((input != null) && (input.length > 0)) {
        out.println(getOpenTag(INPUT_CLASSES_LIST));
        for (int i = 0; i < input.length; i++) {
            printTags(out, Tools.classNameWOPackage(input[i]), IO_CLASS);
            out.println();
        }
        out.println(getCloseTag(INPUT_CLASSES_LIST));
    }

    Class[] output = op.getOutputClasses();
    if ((output != null) && (output.length > 0)) {
        out.println(getOpenTag(OUTPUT_CLASSES_LIST));
        for (int i = 0; i < output.length; i++) {
            printTags(out, Tools.classNameWOPackage(output[i]), IO_CLASS);
            out.println();
        }
        out.println(getCloseTag(OUTPUT_CLASSES_LIST));
    }

    List parameters = op.getParameterTypes();
    if (parameters.size() > 0) {
        out.println(getOpenTag(PARAMETER_LIST));
        Iterator i = parameters.iterator();
        while (i.hasNext()) {
            ParameterType type = (ParameterType) i.next();
            out.print(getOpenTag(PARAMETER_ITEM));
            if (type.isOptional()) {
                printTags(out, type.getKey(), PARAMETER_NAME_OPT);
            } else {
                printTags(out, type.getKey(), PARAMETER_NAME_REQ);
            }
            if ((type instanceof ParameterTypeCategory) || (type instanceof ParameterTypeStringCategory)) {
                printTags(out, type.getDescription(), PARAMETER_DESCRIPTION);
            } else {
                printTags(out,
                        type.getDescription() + (type.getRange() != null ? " (" + type.getRange() + ")" : ""),
                        PARAMETER_DESCRIPTION);
            }
            out.println(getCloseTag(PARAMETER_ITEM));
        }
        out.println(getCloseTag(PARAMETER_LIST));
    }

    Collection<Value> values = op.getValues();
    if (values.size() > 0) {
        out.println(getOpenTag(VALUE_LIST));
        Iterator<Value> i = values.iterator();
        while (i.hasNext()) {
            Value value = i.next();
            // if (!value.isDocumented()) continue;
            out.print(getOpenTag(VALUE_ITEM));
            printTags(out, value.getKey(), VALUE_NAME);
            printTags(out, value.getDescription(), VALUE_DESCRIPTION);
            out.println(getCloseTag(VALUE_ITEM));
        }
        out.println(getCloseTag(VALUE_LIST));
    }

    if (op instanceof Learner) {
        Learner learner = (Learner) op;
        StringBuffer learnerCapabilities = new StringBuffer();
        Iterator<LearnerCapability> i = LearnerCapability.getAllCapabilities().iterator();
        boolean first = true;
        while (i.hasNext()) {
            LearnerCapability capability = i.next();
            try {
                if (learner.supportsCapability(capability)) {
                    if (!first)
                        learnerCapabilities.append(", ");
                    learnerCapabilities.append(capability.getDescription());
                    first = false;
                }
            } catch (Exception e) {
                break;
            }
        }
        String result = learnerCapabilities.toString();
        if (result.length() > 0) {
            out.print(getOpenTag(LEARNER_CAPABILITIES));
            out.print(result);
            out.print(getCloseTag(LEARNER_CAPABILITIES));
        }
    }

    StringBuffer classComment = new StringBuffer();
    if (opDoc != null) {
        Tag[] inlineTags = opDoc.inlineTags();
        for (int i = 0; i < inlineTags.length; i++) {
            if (inlineTags[i] instanceof SeeTag) {
                try {
                    Class referencedClass = Class
                            .forName(((SeeTag) inlineTags[i]).referencedClass().qualifiedName());
                    if (Operator.class.isAssignableFrom(referencedClass)) {
                        if (java.lang.reflect.Modifier.isAbstract(referencedClass.getModifiers())) {
                            classComment.append("\\op{" + Tools.classNameWOPackage(referencedClass) + "}");
                        } else {
                            try {
                                Operator refOp = OperatorService.createOperator(referencedClass);
                                classComment
                                        .append("\\refop{" + refOp.getOperatorDescription().getName() + "}");
                            } catch (OperatorCreationException e) {
                                classComment.append("\\op{" + Tools.classNameWOPackage(referencedClass) + "}");
                            }
                        }
                    } else if (IOObject.class.isAssignableFrom(referencedClass)) {
                        classComment.append("\\ioobj{" + Tools.classNameWOPackage(referencedClass) + "}");
                    } else {
                        classComment.append("\\java{" + Tools.classNameWOPackage(referencedClass) + "}");
                    }
                } catch (Throwable e) {
                    LogService.getGlobal().log(
                            "In see tag '" + inlineTags[i] + "' of " + op.getClass().getName() + ": " + e,
                            LogService.ERROR);
                }
            } else {
                Taglet taglet = tagletMap.get(inlineTags[i].name().substring(1));
                if (taglet instanceof TexTaglet) {
                    classComment.append(((TexTaglet) taglet).toTex(inlineTags[i]));
                } else {
                    classComment.append(escape(inlineTags[i].text()));
                }
            }
        }
    }

    if (op instanceof OperatorChain) {
        InnerOperatorCondition condition = ((OperatorChain) op).getInnerOperatorCondition();
        if (condition != null) {
            out.println(getOpenTag(INNER_OPERATOR));
            out.print(transformHTMLJavadocComment(condition.toHTML(), op.getClass(), op.getName()));
            out.println(getCloseTag(INNER_OPERATOR));
        }
    }

    out.println(
            getOpenTag(SHORT_DESCRIPTION)
                    + transformHTMLJavadocComment(op.getOperatorDescription().getShortDescription(),
                            op.getClass(), op.getOperatorDescription().getName())
                    + getCloseTag(SHORT_DESCRIPTION));
    out.println();

    out.print(getOpenTag(OPERATOR_DESCRIPTION) + transformHTMLJavadocComment(classComment.toString(),
            op.getClass(), op.getOperatorDescription().getName()) + getCloseTag(OPERATOR_DESCRIPTION));
    out.println();

    if (op instanceof TechnicalInformationHandler) {
        TechnicalInformation information = ((TechnicalInformationHandler) op).getTechnicalInformation();
        if (information != null) {
            out.println(
                    getOpenTag(TECHNICAL_INFORMATION)
                            + transformHTMLJavadocComment(information.toString(), op.getClass(),
                                    op.getOperatorDescription().getName())
                            + getCloseTag(TECHNICAL_INFORMATION));
            out.println();
        }
    }

    if (opDoc != null) {
        Tag[] citeTags = opDoc.tags("rapidminer.cite");
        if (citeTags.length > 0)
            out.println(getOpenTag(REFERENCE_SECTION));
        for (int i = 0; i < citeTags.length; i++) {
            printTags(out, citeTags[i].text(), REFERENCE_ENTRY);
        }
    }

    out.println(getCloseTag(OPERATOR));
}