Example #1
0
  public boolean hasAttribute(String key) {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);

    NodeList<Node> childNodes = attributesNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
      Element node = (Element) childNodes.getItem(i);
      if (node.hasAttribute("name") && node.getAttribute("name").equals(key)) {
        return true;
      }
    }

    return false;
  }
Example #2
0
  public String getAttribute(String key) {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);

    NodeList<Node> childNodes = attributesNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
      Element node = (Element) childNodes.getItem(i);
      if (node.hasAttribute("name") && node.getAttribute("name").equals(key)) {
        return node.getAttribute("value");
      }
    }

    throw new RuntimeException("TaggedEntity does not have attribute '" + key + "'");
  }
Example #3
0
  public void setAttributes(HashMap<String, String> map) {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);
    attributesNode.removeAllChildren();

    Node last = null;

    for (String key : map.keySet()) {
      Element element = JSFunctions.createTextElement("attribute", "");
      element.setAttribute("name", key);
      element.setAttribute("value", map.get(key));
      last = attributesNode.insertAfter(element, last);
    }
  }
Example #4
0
  /**
   * Returns a mutable map which is not bound to the TaggedEntity; any changes made in the map will
   * not be reflected in the tagName.
   *
   * @return mutable unbound map
   */
  public HashMap<String, String> getAttributes() {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);

    HashMap<String, String> rvalue = new HashMap<>();
    for (int i = 0; i < attributesNode.getChildCount(); i++) {
      final Node node = attributesNode.getChild(i);
      JsArray<Node> attributeList = getAttributes((Element) node);
      String name = attributeList.get(0).getNodeValue();
      String value = attributeList.get(1).getNodeValue();
      rvalue.put(name, value);
    }

    return rvalue;
  }
Example #5
0
  /**
   * Adds a new key-value attribute pair or changes an existing one.
   *
   * @param key
   * @param value
   */
  public void setAttribute(String key, String value) {
    NodeList<Element> elements = rootElement.getElementsByTagName("attributes");
    assert elements.getLength() > 0;
    Element attributesNode = elements.getItem(0);

    NodeList<Node> childNodes = attributesNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
      Element node = (Element) childNodes.getItem(i);
      if (node.hasAttribute("name") && node.getAttribute("name").equals(key)) {
        node.setAttribute("value", value);
        return;
      }
    }

    /* if you get here, the rootElement wasn't found */
    Element element = JSFunctions.createPlainElement("attribute");
    element.setAttribute("name", key);
    element.setAttribute("value", value);
    attributesNode.insertAfter(element, attributesNode.getLastChild());
  }
Example #6
0
 public String getTag() {
   NodeList<Element> elements = rootElement.getElementsByTagName("tagname");
   assert elements.getLength() > 0;
   Element tagname = elements.getItem(0);
   return tagname.getInnerText();
 }
Example #7
0
 public String getText() {
   NodeList<Element> elements = rootElement.getElementsByTagName("entity");
   assert elements.getLength() > 0;
   Element entity = elements.getItem(0);
   return entity.getInnerText();
 }
Example #8
0
 public void setLemma(String text) {
   NodeList<Element> elements = rootElement.getElementsByTagName("lemma");
   assert elements.getLength() > 0;
   assert text != null;
   elements.getItem(0).setInnerText(text);
 }
Example #9
0
 public String getLemma() {
   NodeList<Element> elements = rootElement.getElementsByTagName("lemma");
   assert elements.getLength() > 0;
   Element lemma = elements.getItem(0);
   return lemma.getInnerText();
 }