List of usage examples for edu.stanford.nlp.trees Tree yield
public ArrayList<Label> yield()
From source file:pltag.parser.semantics.discriminative.ExtractFeatures.java
License:Open Source License
private String getCoLenParString(Tree left, Tree right, boolean endOfSent) { int leftSize = left.yield().size(); int rightSize = right.yield().size(); int diff = Math.abs(rightSize - leftSize); return String.format("%s %s", diff > 5 ? "5+" : String.valueOf(diff), endOfSent ? "y" : "n"); }
From source file:wtute.parser.EssayParser.java
public void commaSplice(List<HasWord> sentence) { System.out.println("SPLICEr"); Tree sentenceTree = lp.parse(sentence); Iterator<Tree> iter = sentenceTree.iterator(); TregexPattern pattern = TregexPattern .compile("@S < (@S $+ (/,/ $+ (@NP $+ @VP))) | < (@NP $+ (@VP $+ (/,/ $+ @VP)))"); TregexPattern patternTwo = TregexPattern.compile("@VP < (@VP $+ (/,/ $+ @VP))"); TregexPattern patternThree = TregexPattern.compile("@S < (@S $+ (/,/ $+ @S))"); TregexMatcher matcher = pattern.matcher(sentenceTree); TregexMatcher matcherTwo = patternTwo.matcher(sentenceTree); TregexMatcher matcherThree = patternThree.matcher(sentenceTree); boolean oneFound, twoFound = false, threeFound = false; while ((oneFound = matcher.findNextMatchingNode()) || (twoFound = matcherTwo.findNextMatchingNode()) || (threeFound = matcherThree.findNextMatchingNode())) { Tree match; if (oneFound) { System.out.println("1"); match = matcher.getMatch();//from w w w . ja v a 2 s . c o m } else if (twoFound) { System.out.println("2"); match = matcherTwo.getMatch(); } else { System.out.println("3"); match = matcherThree.getMatch(); } System.out.println(Sentence.listToString(match.yield())); List<Tree> tl = match.preOrderNodeList(); String errorSect = tl.get(tl.indexOf(Tree.valueOf("(, ,)")) - 1) + ", " + Sentence.listToString(tl.get(tl.indexOf(Tree.valueOf("(, ,)")) + 2).yieldWords()); System.out.println(errorSect); xmlc.addError(errorSect, "Comma splice: You have used a comma to separate two individual sentences", null, new String[] { "or", "and", "but", "so", " ; ", " . " }, "grammar", "Consider using a " + "conjunction after the comma, a semi-colon or a full-stop to break the sentence."); } }