// Path: src/main/java/ixa/kaflib/KAFDocument.java
//    public enum AnnotationType {
// WF,
// TERM,
// MW,
// COMPONENT,
// SENTIMENT,
// ENTITY,
// CHUNK,
// DEP,
// TREE,
// NON_TERMINAL,
// TERMINAL,
// EDGE,
// COREF,
// OPINION, 		/* DOC_LVL */
// OPINION_HOLDER,
// OPINION_TARGET,
// OPINION_EXPRESSION,
// CLINK,
// TLINK,
// PREDICATE_ANCHOR,
// PREDICATE,
// ROLE,
// TIMEX3,
// FACTUALITY,
// FACTVALUE,
// MARK,
// PROPERTY,
// CATEGORY,
// LINKED_ENTITY,
// RELATION,
// TOPIC,
// STATEMENT,
// STATEMENT_TARGET,
// STATEMENT_SOURCE,
// STATEMENT_CUE,
//    }
// 
// Path: src/main/java/ixa/kaflib/KAFDocument.java
//    public enum Layer {
// TEXT,
// TERMS,
// ENTITIES,
// CHUNKS,
// DEPS,
// CONSTITUENCY,
// COREFERENCES,
// OPINIONS,
// CAUSAL_RELATIONS,
// TEMPORAL_RELATIONS,
// SRL,
// TIME_EXPRESSIONS,
// FACTUALITIES,
// FACTUALITY_LAYER,
// MARKABLES,
// PROPERTIES,
// CATEGORIES,
// RELATIONS,
// LINKED_ENTITIES,
// TOPICS,
// ATTRIBUTION,
//    }


import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.CDATA;
import org.jdom2.output.XMLOutputter;
import org.jdom2.output.Format;
import org.jdom2.output.LineSeparator;
import org.jdom2.input.SAXBuilder;
import org.jdom2.JDOMException;
import org.jdom2.xpath.XPathExpression;
import ixa.kaflib.KAFDocument.AnnotationType;
import ixa.kaflib.KAFDocument.Layer;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Collections;
import java.util.Comparator;
import java.util.Set;
import java.io.File;
import java.io.Writer;
import java.io.Reader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.regex.*;
import org.apache.commons.lang3.StringEscapeUtils;
		    Element roleElem = new Element("role");
		    roleElem.setAttribute("id", role.getId());
		    roleElem.setAttribute("semRole", role.getSemRole());
		    Span<Term> roleSpan = role.getSpan();
		    if (roleSpan.getTargets().size() > 0) {
			Comment spanComment = new Comment(StringEscapeUtils.escapeXml11(role.getStr()));
			Element spanElem = new Element("span");
			roleElem.addContent(spanComment);
			roleElem.addContent(spanElem);
			for (Term target : roleSpan.getTargets()) {
			    Element targetElem = new Element("target");
			    targetElem.setAttribute("id", target.getId());
			    if (target == roleSpan.getHead()) {
				targetElem.setAttribute("head", "yes");
			    }
			    spanElem.addContent(targetElem);
			}
		    }
		    List<ExternalRef> rExternalReferences = role.getExternalRefs();
		    if (rExternalReferences.size() > 0) {
			Element externalReferencesElem = externalReferencesToDOM(rExternalReferences);
			roleElem.addContent(externalReferencesElem);
		    }
		    predicateElem.addContent(roleElem);
		}
		predicatesElem.addContent(predicateElem);
	    }
	    root.addContent(predicatesElem);
	}

// Path: src/main/java/ixa/kaflib/KAFDocument.java
//    public enum AnnotationType {
// WF,
// TERM,
// MW,
// COMPONENT,
// SENTIMENT,
// ENTITY,
// CHUNK,
// DEP,
// TREE,
// NON_TERMINAL,
// TERMINAL,
// EDGE,
// COREF,
// OPINION, 		/* DOC_LVL */
// OPINION_HOLDER,
// OPINION_TARGET,
// OPINION_EXPRESSION,
// CLINK,
// TLINK,
// PREDICATE_ANCHOR,
// PREDICATE,
// ROLE,
// TIMEX3,
// FACTUALITY,
// FACTVALUE,
// MARK,
// PROPERTY,
// CATEGORY,
// LINKED_ENTITY,
// RELATION,
// TOPIC,
// STATEMENT,
// STATEMENT_TARGET,
// STATEMENT_SOURCE,
// STATEMENT_CUE,
//    }
// 
// Path: src/main/java/ixa/kaflib/KAFDocument.java
//    public enum Layer {
// TEXT,
// TERMS,
// ENTITIES,
// CHUNKS,
// DEPS,
// CONSTITUENCY,
// COREFERENCES,
// OPINIONS,
// CAUSAL_RELATIONS,
// TEMPORAL_RELATIONS,
// SRL,
// TIME_EXPRESSIONS,
// FACTUALITIES,
// FACTUALITY_LAYER,
// MARKABLES,
// PROPERTIES,
// CATEGORIES,
// RELATIONS,
// LINKED_ENTITIES,
// TOPICS,
// ATTRIBUTION,
//    }


// Path: src/main/java/ixa/kaflib/ReadWriteManager.java
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.CDATA;
import org.jdom2.output.XMLOutputter;
import org.jdom2.output.Format;
import org.jdom2.output.LineSeparator;
import org.jdom2.input.SAXBuilder;
import org.jdom2.JDOMException;
import org.jdom2.xpath.XPathExpression;
import ixa.kaflib.KAFDocument.AnnotationType;
import ixa.kaflib.KAFDocument.Layer;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Collections;
import java.util.Comparator;
import java.util.Set;
import java.io.File;
import java.io.Writer;
import java.io.Reader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.regex.*;
import org.apache.commons.lang3.StringEscapeUtils;

		    Element roleElem = new Element("role");
		    roleElem.setAttribute("id", role.getId());
		    roleElem.setAttribute("semRole", role.getSemRole());
		    Span<Term> roleSpan = role.getSpan();
		    if (roleSpan.getTargets().size() > 0) {
			Comment spanComment = new Comment(StringEscapeUtils.escapeXml11(role.getStr()));
			Element spanElem = new Element("span");
			roleElem.addContent(spanComment);
			roleElem.addContent(spanElem);
			for (Term target : roleSpan.getTargets()) {
			    Element targetElem = new Element("target");
			    targetElem.setAttribute("id", target.getId());
			    if (target == roleSpan.getHead()) {
				targetElem.setAttribute("head", "yes");
			    }
			    spanElem.addContent(targetElem);
			}
		    }
		    List<ExternalRef> rExternalReferences = role.getExternalRefs();
		    if (rExternalReferences.size() > 0) {
			Element externalReferencesElem = externalReferencesToDOM(rExternalReferences);
			roleElem.addContent(externalReferencesElem);
		    }
		    predicateElem.addContent(roleElem);
		}
		predicatesElem.addContent(predicateElem);
	    }
	    root.addContent(predicatesElem);
	}

        List<String> treeTypes = annotationContainer.getGroupIDs(AnnotationType.TREE);