Example usage for org.jdom2 Element getName

List of usage examples for org.jdom2 Element getName

Introduction

In this page you can find the example usage for org.jdom2 Element getName.

Prototype

public String getName() 

Source Link

Document

Returns the (local) name of the element (without any namespace prefix).

Usage

From source file:core.xml.java

public static void extraerInformacion(List l) {
    for (int i = 0; i < l.size(); i++) {
        Element e = (Element) l.get(i);
        if (e.getChildren().size() > 0) {
            extraerInformacion(e.getChildren());
        } else if (e.getName().equals("nombre") || e.getName().equals("descripcion")
                || e.getName().equals("version")) {
            System.err.println("valor de la etiqueta : " + e.getName());
            descripcion.add(e.getText());
        } else if (e.getName().equals("columnas")) {
            num_columnas = e.getText();//from www .  j  a v a 2 s  . c om
        } else if (e.getName().equals("atributo")) {
            atributos.add(e.getText());
        } else if (e.getName().equals("tipo")) {
            parametros.add(e.getText());
        } else if (e.getName().equals("columna")) {
            cabecera.add(e.getText());
        }
    }

}

From source file:count_dep.Count_dep.java

public static LinkedList<Event> ReadEvents(File f) throws JDOMException, IOException {
    LinkedList<Event> res = new LinkedList<>();
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(f);
    Element foo = doc.getRootElement();
    List<Element> one_document = foo.getChildren();
    for (Element one_document1 : one_document) {
        List<Element> ERE = one_document1.getChildren();
        for (Element e : ERE) {
            if ("event".equals(e.getName())) {
                List<Element> mentions = e.getChildren("event_mention");
                for (Element m : mentions) {
                    Event eve = new Event();
                    Element charseq;
                    Element ldcscpope = m.getChild("ldc_scope");
                    charseq = ldcscpope.getChild("charseq");
                    eve.span = charseq.getText().replace("\n", " ");
                    Element anchor = m.getChild("anchor");
                    charseq = anchor.getChild("charseq");
                    eve.trigger = charseq.getText();
                    if (eve.trigger.equalsIgnoreCase("saturday")) {
                        int a = 0;
                        a = a + 1;/*ww  w.j ava2  s .c om*/
                    }
                    eve.eventtype = e.getAttribute("SUBTYPE").getValue();
                    eve.eventlargetype = e.getAttribute("TYPE").getValue();
                    List<Element> arguments = m.getChildren("event_mention_argument");
                    for (Element argu : arguments) {
                        String argumentstr = argu.getChild("extent").getChild("charseq").getText();
                        if ("U.S".equals(argumentstr) || "U.N".equals(argumentstr)
                                || "Feb".equals(argumentstr)) {
                            argumentstr += ".";
                        }
                        if (argumentstr.equalsIgnoreCase("Basra")) {
                            int a = 0;
                            a = a + 1;
                        }
                        eve.arguments.add(new EventArgument(argumentstr, argu.getAttributeValue("ROLE")));
                    }
                    eve.filename = f.getName();
                    res.add(eve);
                }

            }
        }
    }
    return res;
}

From source file:count_dep.Count_dep.java

public static LinkedList<Event> ReadGrishmanEvents(File f) throws JDOMException, IOException {
    LinkedList<Event> res = new LinkedList<>();
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(f);
    Element foo = doc.getRootElement();
    List<Element> one_document = foo.getChildren();
    for (Element one_document1 : one_document) {
        List<Element> ERE = one_document1.getChildren();
        for (Element e : ERE) {
            if ("event".equals(e.getName())) {
                List<Element> mentions = e.getChildren("event_mention");
                for (Element m : mentions) {
                    Event eve = new Event();
                    eve.filename = f.getName();
                    Element charseq;
                    Element anchor = m.getChild("anchor");
                    charseq = anchor.getChild("charseq");
                    eve.span = m.getChild("extent").getChild("charseq").getText();
                    eve.trigger = charseq.getText();
                    eve.eventtype = e.getAttribute("SUBTYPE").getValue();
                    List<Element> arguments = m.getChildren("event_mention_argument");
                    for (Element argu : arguments) {
                        eve.arguments//from w w w  .jav a  2s  .c om
                                .add(new EventArgument(argu.getChild("extent").getChild("charseq").getText(),
                                        argu.getAttributeValue("ROLE")));
                    }
                    //   eve.filename = f.getName();
                    res.add(eve);
                }

            }

        }
    }
    return res;
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.AbstractModule.java

License:Apache License

protected boolean isOperator(final Element element) {
    assert element != null;
    return element.getName().equals(OPERATOR);
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.FunctionNormalizer.java

License:Apache License

private void normalizeFunctionApplication(final Element element, final Collection<String> functionOperators) {
    assert element != null && functionOperators != null;
    final List<Element> children = element.getChildren();
    for (int i = 0; i < children.size(); i++) {
        if (isFunction(i, children, functionOperators)) {
            final int parameterPosition = i + 2;
            Element parameter = children.get(parameterPosition);
            // mrow in which the parameter will be stored
            final Element newParameter = new Element(ROW);

            if (parameter.getName().equals(ROW)) {
                if (hasInsideBrackets(parameter)) {
                    children.get(i + 1).detach(); // just detach operator
                } else { // add parentheses
                    parameter.addContent(1, new Element(OPERATOR).setText("("));
                    parameter.addContent(new Element(OPERATOR).setText(")"));
                    LOGGER.fine("Parentheses around function argument added");
                    children.get(i + 1).detach(); // detach funct app operator
                }/*from   w w w .  j av  a 2 s.com*/
                LOGGER.fine("Function application operator removed");
                continue; // no need to set newParameter
            } else if (isOperator(parameter, "(")) {
                int bracketsDepth = 1;
                newParameter.addContent(parameter.detach());

                while ((parameterPosition < children.size()) && (bracketsDepth > 0)) {
                    parameter = children.get(parameterPosition);
                    if (isOperator(parameter, "(")) {
                        bracketsDepth++;
                    } else if (isOperator(parameter, ")")) {
                        bracketsDepth--;
                    }
                    newParameter.addContent(parameter.detach());
                }
                for (; bracketsDepth > 0; bracketsDepth--) { // add missing right brackets
                    newParameter.addContent(new Element(OPERATOR).setText(")"));
                    LOGGER.fine("Added missing )");
                }
            } else { // if the paramether is neither mrow or (
                newParameter.addContent(new Element(OPERATOR).setText("(")); // add left bracket
                newParameter.addContent(children.get(parameterPosition).detach());
                newParameter.addContent(new Element(OPERATOR).setText(")")); // add right bracket
                LOGGER.fine("Function argument wrapped with parentheses and mrow");
            }
            children.set(i + 1, newParameter); // replace function app operator with newParameter
            LOGGER.fine("Function application operator removed");
        } else { // if there isnt start of function application apply normalization on children
            normalizeFunctionApplication(children.get(i), functionOperators);
        }
    }
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MrowNormalizer.java

License:Apache License

/**
 * Recursively searches element content to possibly remove or add mrow where
 * needed./*from  w  w  w  .  j  ava2 s  .c  o m*/
 *
 * @param element element to start at
 */
private void traverseChildrenElements(final Element element) {
    assert element != null;
    final List<Element> children = new ArrayList<Element>(element.getChildren());
    for (Element child : children) {
        traverseChildrenElements(child);
    }
    if (element.getName().equals(ROW)) {
        checkRemoval(element);
    } else {
        checkAddition(element);
    }
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MrowNormalizer.java

License:Apache License

/**
 * Removes a mrow element if possible.//from   www.j a va2 s.com
 *
 * @param mrowElement the mrow element
 */
private void checkRemoval(final Element mrowElement) {
    assert mrowElement != null && mrowElement.getName().equals(ROW);
    final Parent parent = mrowElement.getParent();
    if (!(parent instanceof Element)) {
        return; // no parent element
    }
    final Element parentElement = (Element) parent;
    final List<Element> children = mrowElement.getChildren();

    if (children.size() <= 1) {
        removeElement(mrowElement, parentElement);
        LOGGER.log(Level.FINE, "Element {0} removed", mrowElement);
        return;
    }

    final String childCountPropertyName = CHILD_COUNT_PREFIX + parentElement.getName();
    if (!isProperty(childCountPropertyName)) {
        return; // unknown parent element
    }
    final String childCountProperty = getProperty(childCountPropertyName);
    final int childCount;
    try {
        childCount = Integer.parseInt(childCountProperty);
    } catch (NumberFormatException e) {
        LOGGER.log(Level.WARNING, "{0} must be an integer, property ignored", childCountProperty);
        return;
    }

    if (childCount == 1 || // parent can accept any number of elements so we can remove mrow
            children.size() + parentElement.getChildren().size() - 1 == childCount) {
        removeElement(mrowElement, parentElement);
    }
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MrowNormalizer.java

License:Apache License

/**
 * Test if element is an operator representing an opening or closing
 * parenthesis according to properties/* w  w w.j  a  v  a 2s. c o  m*/
 *
 * @param element element to test
 * @param propertyName name of property specifiyng opening or closing
 * parentheses
 * @return true if element is a parentheses according to propertyName
 */
private Boolean isParenthesis(final Element element, final String propertyName) {
    assert element != null && propertyName != null && isProperty(propertyName);
    if (!element.getName().equals(OPERATOR)) {
        return false;
    }
    return getPropertySet(propertyName).contains(element.getTextNormalize());
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MrowNormalizer.java

License:Apache License

/**
 * Wrap previously detected fenced expressions in mrow to be same as output
 * of MfencedReplacer// www .  j  av a 2  s. c  o  m
 *
 * @param siblings children of parent element
 * @param fenced list of elements inside parentheses, children of parent
 * element
 * @param opening opening parenthesis, child of parent element
 * @param closing closing parenthesis, child of parent element
 */
private void wrapFenced(final List<Element> siblings, final List<Element> fenced, final Element opening,
        final Element closing) {
    assert siblings != null && fenced != null && opening != null;
    final Element parent = opening.getParentElement();
    assert closing != null && closing.getParentElement().equals(parent);
    for (Element e : fenced) {
        e.detach();
    }
    final int openingIndex = parent.indexOf(opening);

    // Element to be placed inside parentheses.
    // If null, the original 'fenced' list will be used.
    final Element innerElement;
    if (fenced.isEmpty() || !isEnabled(WRAP_ISIDE)) {
        innerElement = null; // will not wrap inside in mrow
    } else if (fenced.size() == 1) {
        innerElement = fenced.get(0); // no need to wrap, just one element
    } else {
        innerElement = new Element(ROW);
        innerElement.addContent(fenced);
        LOGGER.fine("Inner mrow added");
    }

    if (((parent.getName().equals(ROW) && siblings.get(0) == opening
            && siblings.get(siblings.size() - 1) == closing)) || !isEnabled(WRAP_OUTSIDE)) {
        // will not wrap outside in mrow
        if (innerElement == null) {
            parent.addContent(openingIndex + 1, fenced);
        } else {
            parent.addContent(openingIndex + 1, innerElement);
        }
        return;
    }
    // wrap outside in mrow
    opening.detach();
    closing.detach();
    final Element outerMrowElement = new Element(ROW);
    outerMrowElement.addContent(opening);
    if (innerElement != null) {
        outerMrowElement.addContent(innerElement);
    } else {
        outerMrowElement.addContent(fenced);
    }
    outerMrowElement.addContent(closing);
    parent.addContent(openingIndex, outerMrowElement);
    LOGGER.fine("Outer mrow added");
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.ScriptNormalizer.java

License:Apache License

private void normalizeSupInSub(final Element element) {
    assert element != null;
    final List<Element> children = element.getChildren();
    for (int i = 0; i < children.size(); i++) {
        final Element actual = children.get(i);
        normalizeSupInSub(actual);/*from w w w .j  av a 2  s. c  o  m*/
        if (!actual.getName().equals(SUBSCRIPT)) {
            continue;
        }
        List<Element> subscriptChildren = actual.getChildren();
        if (subscriptChildren.size() != 2) {
            LOGGER.info("Invalid msub, skipped");
            continue;
        }
        if (!subscriptChildren.get(0).getName().equals(SUPERSCRIPT)) {
            continue;
        }
        final List<Element> superscriptChildren = subscriptChildren.get(0).getChildren();
        if (superscriptChildren.size() != 2) {
            LOGGER.info("Invalid msup, skipped");
            continue;
        }
        final Element newMsub = new Element(SUBSCRIPT);
        newMsub.addContent(superscriptChildren.get(0).detach());
        newMsub.addContent(subscriptChildren.get(1).detach());
        final Element newMsup = new Element(SUPERSCRIPT);
        newMsup.addContent(newMsub);
        newMsup.addContent(superscriptChildren.get(0).detach());
        children.set(i, newMsup);
        LOGGER.fine("Sub/sup scripts swapped");
    }
}