コード例 #1
0
  private void generateNodeInfo() {
    NodeInfo nodeInfo = info.getNodeInfo();
    Element nodeInfoElement = document.createElement(NodeInfo.class.getSimpleName());
    infoElement.appendChild(nodeInfoElement);
    if (nodeInfo != null) {
      nodeInfoElement.setAttribute(EXIST_ATTRIBUTE_NAME, TRUE_VALUE);

      if (nodeInfo.isVariable()) {
        nodeInfoElement.setAttribute(VARIABLE_ATTRIBUTE_NAME, TRUE_VALUE);
      }

      NamedEntity namedEntity = nodeInfo.getNamedEntityAnnotation();
      Element namedEntityElement = document.createElement(NamedEntity.class.getSimpleName());
      nodeInfoElement.appendChild(namedEntityElement);
      if (namedEntity != null) {
        namedEntityElement.setAttribute(EXIST_ATTRIBUTE_NAME, TRUE_VALUE);
        Text namedEntityText = document.createTextNode(namedEntity.name());
        namedEntityElement.appendChild(namedEntityText);
      } else {
        namedEntityElement.setAttribute(EXIST_ATTRIBUTE_NAME, FALSE_VALUE);
      }

      int serial = nodeInfo.getSerial();
      Element serialElement = document.createElement(SERIAL_ELEMENT_NAME);
      nodeInfoElement.appendChild(serialElement);
      Text serialText = document.createTextNode(String.valueOf(serial));
      serialElement.appendChild(serialText);

      SyntacticInfo syntacticInfo = nodeInfo.getSyntacticInfo();
      Element syntacticInfoElement = document.createElement(SyntacticInfo.class.getSimpleName());
      nodeInfoElement.appendChild(syntacticInfoElement);
      if (syntacticInfo != null) {
        syntacticInfoElement.setAttribute(EXIST_ATTRIBUTE_NAME, TRUE_VALUE);
        PartOfSpeech partOfSpeech = syntacticInfo.getPartOfSpeech();
        Element partOfSpeechElement = document.createElement(PartOfSpeech.class.getSimpleName());
        syntacticInfoElement.appendChild(partOfSpeechElement);
        if (partOfSpeech != null) {
          partOfSpeechElement.setAttribute(EXIST_ATTRIBUTE_NAME, TRUE_VALUE);

          Element canonicalPartOfSpeechElement =
              document.createElement(CanonicalPosTag.class.getSimpleName());
          partOfSpeechElement.appendChild(canonicalPartOfSpeechElement);
          Text canonicalPosText = document.createTextNode(partOfSpeech.getCanonicalPosTag().name());
          canonicalPartOfSpeechElement.appendChild(canonicalPosText);

          Element posStringElement = document.createElement(POS_STRING_ELEMENT_NAME);
          partOfSpeechElement.appendChild(posStringElement);
          Text posStringText = document.createTextNode(partOfSpeech.getStringRepresentation());
          posStringElement.appendChild(posStringText);
        } else {
          partOfSpeechElement.setAttribute(EXIST_ATTRIBUTE_NAME, TRUE_VALUE);
        }
      } else {
        syntacticInfoElement.setAttribute(EXIST_ATTRIBUTE_NAME, FALSE_VALUE);
      }

      Integer variableId = nodeInfo.getVariableId();
      if (variableId != null) {
        Element variableIdElement = document.createElement(VARIABLE_ID_ELEMENT_NAME);
        nodeInfoElement.appendChild(variableIdElement);
        Text variableIdText = document.createTextNode(variableId.toString());
        variableIdElement.appendChild(variableIdText);
      }

      String word = nodeInfo.getWord();
      Element wordElement = document.createElement(WORD_ELEMENT_NAME);
      nodeInfoElement.appendChild(wordElement);
      if (word != null) {
        wordElement.setAttribute(EXIST_ATTRIBUTE_NAME, TRUE_VALUE);
        Text wordText = document.createTextNode(word);
        wordElement.appendChild(wordText);
      } else {
        wordElement.setAttribute(EXIST_ATTRIBUTE_NAME, FALSE_VALUE);
      }

      String lemma = nodeInfo.getWordLemma();
      Element lemmaElement = document.createElement(LEMMA_ELEMENT_NAME);
      nodeInfoElement.appendChild(lemmaElement);
      if (lemma != null) {
        lemmaElement.setAttribute(EXIST_ATTRIBUTE_NAME, TRUE_VALUE);
        Text lemmaText = document.createTextNode(lemma);
        lemmaElement.appendChild(lemmaText);
      } else {
        lemmaElement.setAttribute(EXIST_ATTRIBUTE_NAME, FALSE_VALUE);
      }
    } else {
      nodeInfoElement.setAttribute(EXIST_ATTRIBUTE_NAME, FALSE_VALUE);
    }
  }