List of usage examples for opennlp.tools.parser Parse show
public void show(StringBuffer sb)
From source file:es.ehu.si.ixa.pipe.parse.Annotate.java
/** * @param kaf/*from ww w . j av a 2 s . c o m*/ * document containing <text> and <terms> elements * @return StringBuffer containing the Parse tree * @throws IOException */ private StringBuffer getParse(KAFDocument kaf) throws IOException { StringBuffer parsingDoc = new StringBuffer(); List<List<WF>> sentences = kaf.getSentences(); for (List<WF> sentence : sentences) { // get array of token forms from a list of WF objects String[] tokens = new String[sentence.size()]; for (int i = 0; i < sentence.size(); i++) { tokens[i] = sentence.get(i).getForm(); } // Constituent Parsing String sent = getSentenceFromTokens(tokens); Parse[] parsedSentence = parser.parse(sent, 1); if (MARKHEADS) { for (Parse parse : parsedSentence) { headFinder.printHeads(parse); } } for (Parse parsedSent : parsedSentence) { parsedSent.show(parsingDoc); parsingDoc.append("\n"); } } return parsingDoc; }
From source file:es.ehu.si.ixa.pipe.parse.Annotate.java
public void parseForTesting(File inputText) throws IOException { StringBuffer parsingDoc = new StringBuffer(); if (inputText.isFile()) { List<String> inputTrees = FileUtils.readLines(inputText, "UTF-8"); for (String sentence : inputTrees) { Parse parsedSentence = parser.parse(sentence, 1)[0]; parsedSentence.show(parsingDoc); parsingDoc.append("\n"); }/*from w w w.jav a 2 s . c o m*/ File outfile = new File(FilenameUtils.removeExtension(inputText.getPath()) + ".test"); System.err.println("Writing test parse file to " + outfile); FileUtils.writeStringToFile(outfile, parsingDoc.toString(), "UTF-8"); } else { System.out.println("Choose a correct file!"); System.exit(1); } }
From source file:es.ehu.si.ixa.pipe.parse.Annotate.java
/** * Takes as input a list of parse strings, one for line, and annotates the * headwords/* ww w .java2 s. c o m*/ * * @param inputTrees * @return a list of parse trees with headwords annotated */ private String addHeadWordsToTreebank(List<String> inputTrees) { StringBuffer parsedDoc = new StringBuffer(); for (String parseSent : inputTrees) { Parse parsedSentence = Parse.parseParse(parseSent); headFinder.printHeads(parsedSentence); parsedSentence.show(parsedDoc); parsedDoc.append("\n"); } return parsedDoc.toString(); }
From source file:de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpParser.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { CAS cas = aJCas.getCas();// w ww . j a v a 2 s . c o m modelProvider.configure(cas); mappingProvider.configure(cas); for (Sentence sentence : select(aJCas, Sentence.class)) { List<Token> tokens = selectCovered(aJCas, Token.class, sentence); Parse parseInput = new Parse(cas.getDocumentText(), new Span(sentence.getBegin(), sentence.getEnd()), AbstractBottomUpParser.INC_NODE, 0, 0); int i = 0; for (Token t : tokens) { parseInput.insert(new Parse(cas.getDocumentText(), new Span(t.getBegin(), t.getEnd()), AbstractBottomUpParser.TOK_NODE, 0, i)); i++; } Parse parseOutput = modelProvider.getResource().parse(parseInput); createConstituentAnnotationFromTree(aJCas, parseOutput, null, tokens); if (createPennTreeString) { StringBuffer sb = new StringBuffer(); parseOutput.setType("ROOT"); // in DKPro the root is ROOT, not TOP parseOutput.show(sb); PennTree pTree = new PennTree(aJCas, sentence.getBegin(), sentence.getEnd()); pTree.setPennTree(sb.toString()); pTree.addToIndexes(); } } }
From source file:es.ehu.si.ixa.pipe.convert.Convert.java
/** * It takes as input a semi-pruned penn treebank tree (e.g., with -NONE- * traces removed) via sed 's/-NONE-\s[\*A-Za-z0-9]*[\*]*[\-]*[A-Za-z0-9]*' * //from w w w .ja v a2 s .co m * and prunes the empty trees remaining from the sed operation. The parseParse * function also removes function tags by default. * * @param inputTrees * @return */ // TODO add the sed regexp to this function private String normalizeParse(List<String> inputTrees) { StringBuilder parsedDoc = new StringBuilder(); for (String parseSent : inputTrees) { Parse parse = Parse.parseParse(parseSent); Parse.pruneParse(parse); StringBuffer sentBuilder = new StringBuffer(); parse.show(sentBuilder); parsedDoc.append(sentBuilder.toString()).append("\n"); } return parsedDoc.toString(); }