setSingleElement(docElem, "docId", NAMESPACE_URI, annotation.get(CoreAnnotations.DocIDAnnotation.class)); setSingleElement(docElem, "docDate", NAMESPACE_URI, annotation.get(CoreAnnotations.DocDateAnnotation.class)); setSingleElement(docElem, "docSourceType", NAMESPACE_URI, annotation.get(CoreAnnotations.DocSourceTypeAnnotation.class)); setSingleElement(docElem, "docType", NAMESPACE_URI, annotation.get(CoreAnnotations.DocTypeAnnotation.class)); setSingleElement(docElem, "author", NAMESPACE_URI, annotation.get(CoreAnnotations.AuthorAnnotation.class)); setSingleElement(docElem, "location", NAMESPACE_URI, annotation.get(CoreAnnotations.LocationAnnotation.class)); setSingleElement(docElem, "text", NAMESPACE_URI, annotation.get(CoreAnnotations.TextAnnotation.class)); for(int j = 0; j < tokens.size(); j ++){ Element wordInfo = new Element("token", NAMESPACE_URI); addWordInfo(wordInfo, tokens.get(j), j + 1, NAMESPACE_URI); wordTable.appendChild(wordInfo); addConstituentTreeInfo(parseInfo, tree, options.constituencyTreePrinter); sentElem.appendChild(parseInfo); Element depInfo = buildDependencyTreeInfo("basic-dependencies", sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class), tokens, NAMESPACE_URI); if (depInfo != null) { sentElem.appendChild(depInfo); depInfo = buildDependencyTreeInfo("collapsed-dependencies", sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class), tokens, NAMESPACE_URI); if (depInfo != null) { sentElem.appendChild(depInfo); depInfo = buildDependencyTreeInfo("collapsed-ccprocessed-dependencies", sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class), tokens, NAMESPACE_URI); if (depInfo != null) { sentElem.appendChild(depInfo);
/** * Generates the XML content for the coreference chain object. */ private static boolean addCorefGraphInfo (Options options, Element corefInfo, List<CoreMap> sentences, Map<Integer, CorefChain> corefChains, String curNS) { boolean foundCoref = false; for (CorefChain chain : corefChains.values()) { if (!options.printSingletons && chain.getMentionsInTextualOrder().size() <= 1) continue; foundCoref = true; Element chainElem = new Element("coreference", curNS); CorefChain.CorefMention source = chain.getRepresentativeMention(); addCorefMention(options, chainElem, curNS, sentences, source, true); for (CorefChain.CorefMention mention : chain.getMentionsInTextualOrder()) { if (mention == source) continue; addCorefMention(options, chainElem, curNS, sentences, mention, false); } corefInfo.appendChild(chainElem); } return foundCoref; }
final boolean isExtra = false; addDependencyInfo(depInfo, rel, isExtra, source, sourceWord, null, target, targetWord, null, curNS); boolean isExtra = edge.isExtra(); addDependencyInfo(depInfo, rel, isExtra, source, sourceWord, sourceCopy, target, targetWord, targetCopy, curNS);
/** * Converts the given annotation to an XML document using options taken from the StanfordCoreNLP pipeline */ public static Document annotationToDoc(Annotation annotation, StanfordCoreNLP pipeline) { Options options = getOptions(pipeline.getProperties()); return annotationToDoc(annotation, options); }
public static void xmlPrint(Annotation annotation, OutputStream os, StanfordCoreNLP pipeline) throws IOException { xmlPrint(annotation, os, getOptions(pipeline)); }
public void outputPretty(PrintWriter out, Annotation annotation) throws ServletException { try { Document input = XMLOutputter.annotationToDoc(annotation, pipeline); Nodes output = corenlpTransformer.transform(input); for (int i = 0; i < output.size(); i++) { out.print(output.get(i).toXML()); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new ServletException(e); } }
/** * Converts the given annotation to an XML document using options taken from the StanfordCoreNLP pipeline */ public static Document annotationToDoc(Annotation annotation, StanfordCoreNLP pipeline) { Options options = getOptions(pipeline); return annotationToDoc(annotation, options); }
/** {@inheritDoc} */ @Override public void print(Annotation annotation, OutputStream os, Options options) throws IOException { Document xmlDoc = annotationToDoc(annotation, options); Serializer ser = new Serializer(os, options.encoding); if (options.pretty) { ser.setIndent(2); } else { ser.setIndent(0); } ser.setMaxLength(0); ser.write(xmlDoc); ser.flush(); }
setSingleElement(docElem, "docId", NAMESPACE_URI, annotation.get(CoreAnnotations.DocIDAnnotation.class)); setSingleElement(docElem, "docDate", NAMESPACE_URI, annotation.get(CoreAnnotations.DocDateAnnotation.class)); setSingleElement(docElem, "docSourceType", NAMESPACE_URI, annotation.get(CoreAnnotations.DocSourceTypeAnnotation.class)); setSingleElement(docElem, "docType", NAMESPACE_URI, annotation.get(CoreAnnotations.DocTypeAnnotation.class)); setSingleElement(docElem, "author", NAMESPACE_URI, annotation.get(CoreAnnotations.AuthorAnnotation.class)); setSingleElement(docElem, "location", NAMESPACE_URI, annotation.get(CoreAnnotations.LocationAnnotation.class)); setSingleElement(docElem, "text", NAMESPACE_URI, annotation.get(CoreAnnotations.TextAnnotation.class)); for(int j = 0; j < tokens.size(); j ++){ Element wordInfo = new Element("token", NAMESPACE_URI); addWordInfo(wordInfo, tokens.get(j), j + 1, NAMESPACE_URI); wordTable.appendChild(wordInfo); addConstituentTreeInfo(parseInfo, tree, options.constituencyTreePrinter); sentElem.appendChild(parseInfo); Element depInfo = buildDependencyTreeInfo("basic-dependencies", sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class), tokens, NAMESPACE_URI); if (depInfo != null) { sentElem.appendChild(depInfo); depInfo = buildDependencyTreeInfo("collapsed-dependencies", sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class), tokens, NAMESPACE_URI); if (depInfo != null) { sentElem.appendChild(depInfo); depInfo = buildDependencyTreeInfo("collapsed-ccprocessed-dependencies", sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class), tokens, NAMESPACE_URI); if (depInfo != null) { sentElem.appendChild(depInfo);
/** * Converts the given annotation to an XML document using options taken from the StanfordCoreNLP pipeline */ public static Document annotationToDoc(Annotation annotation, StanfordCoreNLP pipeline) { Options options = getOptions(pipeline.getProperties()); return annotationToDoc(annotation, options); }
public static void xmlPrint(Annotation annotation, OutputStream os, Options options) throws IOException { Document xmlDoc = annotationToDoc(annotation, options); Serializer ser = new Serializer(os, options.encoding); ser.setIndent(2); ser.setMaxLength(0); ser.write(xmlDoc); ser.flush(); }
/** * Generates the XML content for the coreference chain object. */ private static boolean addCorefGraphInfo (Options options, Element corefInfo, List<CoreMap> sentences, Map<Integer, CorefChain> corefChains, String curNS) { boolean foundCoref = false; for (CorefChain chain : corefChains.values()) { if (!options.printSingletons && chain.getMentionsInTextualOrder().size() <= 1) continue; foundCoref = true; Element chainElem = new Element("coreference", curNS); CorefChain.CorefMention source = chain.getRepresentativeMention(); addCorefMention(options, chainElem, curNS, sentences, source, true); for (CorefChain.CorefMention mention : chain.getMentionsInTextualOrder()) { if (mention == source) continue; addCorefMention(options, chainElem, curNS, sentences, mention, false); } corefInfo.appendChild(chainElem); } return foundCoref; }
final boolean isExtra = false; addDependencyInfo(depInfo, rel, isExtra, source, sourceWord, null, target, targetWord, null, curNS); boolean isExtra = edge.isExtra(); addDependencyInfo(depInfo, rel, isExtra, source, sourceWord, sourceCopy, target, targetWord, targetCopy, curNS);
setSingleElement(docElem, "docId", NAMESPACE_URI, annotation.get(CoreAnnotations.DocIDAnnotation.class)); setSingleElement(docElem, "docDate", NAMESPACE_URI, annotation.get(CoreAnnotations.DocDateAnnotation.class)); setSingleElement(docElem, "docSourceType", NAMESPACE_URI, annotation.get(CoreAnnotations.DocSourceTypeAnnotation.class)); setSingleElement(docElem, "docType", NAMESPACE_URI, annotation.get(CoreAnnotations.DocTypeAnnotation.class)); setSingleElement(docElem, "author", NAMESPACE_URI, annotation.get(CoreAnnotations.AuthorAnnotation.class)); setSingleElement(docElem, "location", NAMESPACE_URI, annotation.get(CoreAnnotations.LocationAnnotation.class)); setSingleElement(docElem, "text", NAMESPACE_URI, annotation.get(CoreAnnotations.TextAnnotation.class)); for(int j = 0; j < tokens.size(); j ++){ Element wordInfo = new Element("token", NAMESPACE_URI); addWordInfo(wordInfo, tokens.get(j), j + 1, NAMESPACE_URI); wordTable.appendChild(wordInfo); addConstituentTreeInfo(parseInfo, tree, options.constituentTreePrinter); sentElem.appendChild(parseInfo); Element depInfo = buildDependencyTreeInfo("basic-dependencies", sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class), tokens, NAMESPACE_URI); if (depInfo != null) { sentElem.appendChild(depInfo); depInfo = buildDependencyTreeInfo("collapsed-dependencies", sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class), tokens, NAMESPACE_URI); if (depInfo != null) { sentElem.appendChild(depInfo); depInfo = buildDependencyTreeInfo("collapsed-ccprocessed-dependencies", sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class), tokens, NAMESPACE_URI); if (depInfo != null) { sentElem.appendChild(depInfo);
/** {@inheritDoc} */ @Override public void print(Annotation annotation, OutputStream os, Options options) throws IOException { Document xmlDoc = annotationToDoc(annotation, options); Serializer ser = new Serializer(os, options.encoding); if (options.pretty) { ser.setIndent(2); } else { ser.setIndent(0); } ser.setMaxLength(0); ser.write(xmlDoc); ser.flush(); }
/** * Generates the XML content for the coreference chain object */ private static boolean addCorefGraphInfo (Options options, Element corefInfo, List<CoreMap> sentences, Map<Integer, CorefChain> corefChains, String curNS) { boolean foundCoref = false; for (CorefChain chain : corefChains.values()) { if (!options.printSingletons && chain.getMentionsInTextualOrder().size() <= 1) continue; foundCoref = true; Element chainElem = new Element("coreference", curNS); CorefChain.CorefMention source = chain.getRepresentativeMention(); addCorefMention(options, chainElem, curNS, sentences, source, true); for (CorefChain.CorefMention mention : chain.getMentionsInTextualOrder()) { if (mention == source) continue; addCorefMention(options, chainElem, curNS, sentences, mention, false); } corefInfo.appendChild(chainElem); } return foundCoref; }
boolean isExtra = false; addDependencyInfo(depInfo, rel, isExtra, source, sourceWord, null, target, targetWord, null, curNS); boolean isExtra = edge.isExtra(); addDependencyInfo(depInfo, rel, isExtra, source, sourceWord, sourceCopy, target, targetWord, targetCopy, curNS);