protected Tree findMarkedHead(Tree t) { Tree[] kids = t.children(); for (Tree kid : kids) { if (headMarkedPattern.matcher(kid.label().value()).find() || headMarkedPattern2.matcher(kid.label().value()).find()) { //log.info("found manually-labeled head " + kids[i] + " for tree " + t); return kid; } } return null; }
/** Divides a sentence into clauses and sort the antecedents for pronoun matching */ private static List<Mention> sortMentionsByClause(List<Mention> l, Mention m1) { List<Mention> sorted = new ArrayList<>(); Tree tree = m1.contextParseTree; Tree current = m1.mentionSubTree; if(tree==null || current==null) return l; while(true){ current = current.ancestor(1, tree); String curLabel = current.label().value(); if("TOP".equals(curLabel) || curLabel.startsWith("S") || curLabel.equals("NP")){ // if(current.label().value().startsWith("S")){ for(Mention m : l){ if(!sorted.contains(m) && current.dominates(m.mentionSubTree)) sorted.add(m); } } if(current.ancestor(1, tree)==null) break; } return sorted; } }
/** * Return a null list if we don't care about context words, return a * list of the words at the leaves of the tree if we do care */ private List<String> getContextWords(Tree tree) { List<String> words = null; if (op.trainOptions.useContextWords) { words = Generics.newArrayList(); List<Label> leaves = tree.yield(); for (Label word : leaves) { words.add(word.value()); } } return words; }
private int findLeftDisHead(Tree[] daughterTrees, String[] how) { for (int headIdx = 0; headIdx < daughterTrees.length; headIdx++) { String childCat = tlp.basicCategory(daughterTrees[headIdx].label().value()); for (int i = 1; i < how.length; i++) { if (how[i].equals(childCat)) { return headIdx; } } } return -1; }
boolean isPunc(Tree t) { if (t.isPreTerminal()) { String s = t.label().value(); if (tlp.isEvalBIgnoredPunctuationTag(s)) { return true; } } return false; }
/** Doesn't accept nodes that only cover an empty. */ @Override public boolean test(Tree t) { Tree[] kids = t.children(); Label l = t.label(); // Delete (return false for) empty/trace nodes (ones marked '-NONE-') return ! ((l != null) && "-NONE-".equals(l.value()) && !t.isLeaf() && kids.length == 1 && kids[0].isLeaf()); }
/** Divides a sentence into clauses and sort the antecedents for pronoun matching */ private static List<Mention> sortMentionsForPronoun(List<Mention> l, Mention m1) { List<Mention> sorted = new ArrayList<>(); Tree tree = m1.contextParseTree; Tree current = m1.mentionSubTree; if(tree==null || current==null) return l; while(true){ current = current.ancestor(1, tree); if(current.label().value().startsWith("S")){ for(Mention m : l){ if(!sorted.contains(m) && current.dominates(m.mentionSubTree)) sorted.add(m); } } if(current.ancestor(1, tree)==null) break; } if(l.size()!=sorted.size()) { sorted=l; } else if(!l.equals(sorted)){ for(int i=0; i<l.size(); i++){ Mention ml = l.get(i); Mention msorted = sorted.get(i); } } else { } return sorted; }
int yieldLen = yield.size(); for (int i = 0; i < yieldLen; ++i) { String tag = preterm.get(i).value(); int tagId = lexicon.tagIndex.indexOf(tag); String word = yield.get(i).value(); int wordId = lexicon.wordIndex.indexOf(word); int morphId = lexicon.morphIndex.indexOf(reducedTag); FactoredLexiconEvent event = new FactoredLexiconEvent(wordId, tagId, lemmaId, morphId, i, word, featureStr); events.add(event);
private String ditrans(Tree t) { int n = 0; for (Tree kid : t.children()) { String childStr = kid.label().value(); if (childStr.startsWith("NP") && !childStr.contains("-TMP")) { n++; } else if (englishTrain.markDitransV == 1 && childStr.startsWith("S")) { n++; } } if (n >= 2) { return "^2Arg"; } else { return ""; } }
public String apply(TregexMatcher m) { String node = m.getNode(key).label().value(); // We also tried if (node.startsWith("V")) [var2] and if (node.startsWith("V") || node.startsWith("S")) [var3]. Both seemed markedly worse than the basic function or this var form (which seems a bit better than the basic equiv option). if (node.startsWith("S") || node.startsWith("V") || node.startsWith("A")) { return annotationMark + "VSA"; } else { return ""; } }
private boolean isVerbalAuxiliary(Tree preterminal, Set<String> verbalSet, boolean allowJustTagMatch) { if (preterminal.isPreTerminal()) { Label kidLabel = preterminal.label(); String tag = null; if (kidLabel instanceof HasTag) { tag = preterminal.value(); Label wordLabel = preterminal.firstChild().label(); String word = null; if (wordLabel instanceof HasWord) { word = wordLabel.value();
@Override public boolean test(Tree t) { Tree[] kids = t.children(); Label l = t.label(); // The special Switchboard non-terminals clause. // Note that it deletes IP which other Treebanks might use! if ("RS".equals(t.label().value()) || "RM".equals(t.label().value()) || "IP".equals(t.label().value()) || "CODE".equals(t.label().value())) { return t.isLeaf(); //Prevents deletion of the word "IP" } if ((l != null) && l.value() != null && (l.value().equals("-NONE-")) && !t.isLeaf() && kids.length == 1 && kids[0].isLeaf()) { // Delete empty/trace nodes (ones marked '-NONE-') return false; } return true; } };
/** * Create a sentence as a List of {@code CoreLabel} objects from * a List of other label objects. * * @param words The words to make it from * @return The Sentence */ public static List<CoreLabel> toCoreLabelList(List<? extends HasWord> words) { List<CoreLabel> sent = new ArrayList<>(words.size()); for (HasWord word : words) { CoreLabel cl = new CoreLabel(); if (word instanceof Label) { cl.setValue(((Label) word).value()); } cl.setWord(word.word()); if (word instanceof HasTag) { cl.setTag(((HasTag) word).tag()); } if (word instanceof HasLemma) { cl.setLemma(((HasLemma) word).lemma()); } sent.add(cl); } return sent; }
private int findRightDisHead(Tree[] daughterTrees, String[] how) { for (int headIdx = daughterTrees.length - 1; headIdx >= 0; headIdx--) { String childCat = tlp.basicCategory(daughterTrees[headIdx].label().value()); for (int i = 1; i < how.length; i++) { if (how[i].equals(childCat)) { return headIdx; } } } return -1; }