@Override boolean satisfies(Tree t1, Tree t2, Tree root, final TregexMatcher matcher) { return t2.children().length == 1 && t2.firstChild() == t1; }
@Override boolean satisfies(Tree t1, Tree t2, Tree root, final TregexMatcher matcher) { return t1.children().length == 1 && t1.firstChild() == t2; }
public boolean test(Tree tree) { if(tree.isPreTerminal() && (tree.firstChild().value().equals("") || tree.firstChild().value().equals("-NONE-"))) { return false; } return true; } };
public String apply(TregexMatcher m) { Tree tagNode = m.getMatch(); String yield = tagNode.firstChild().value(); String prefix = yield.substring(0, Math.min(yield.length(), prefixLength)); return "[p," + prefix + ']'; }
public boolean test(Tree t) { return ! (t.numChildren() == 1 && "X".equals(t.firstChild().value())); }
private static String treeToRuleString(Tree tree) { StringBuilder sb = new StringBuilder(); sb.append(tree.value()).append(":").append(tree.firstChild().value()); for (int i = 1; i < tree.numChildren(); ++i) { Tree kid = tree.children()[i]; sb.append("-").append(kid.value()); } return sb.toString(); }
public String apply(TregexMatcher matcher) { Tree matchedTree = matcher.getMatch(); Tree head = headFinder.determineHead(matchedTree); if (!head.isPrePreTerminal()) return ""; Tree lexicalHead = head.firstChild().firstChild(); String headValue = lexicalHead.value(); if (headValue != null) { if (lowerCase) headValue = headValue.toLowerCase(); return '[' + headValue + ']'; } else { return ""; } }
@SuppressWarnings("RedundantIfStatement") @Override public boolean test(Tree t) { // Pronoun deletions if (t.isPreTerminal() && (t.value().equals("PRON_1S") || t.value().equals("PRP")) && (t.firstChild().value().equals("nullp") || t.firstChild().value().equals("نللة") || t.firstChild().value().equals("-~a"))) { return false; // Traces } else if (t.isPreTerminal() && t.value() != null && t.value().equals("-NONE-")) { return false; } return true; } }
private Tree determineBinaryHead(Tree t) { if (t.numChildren() == 1) { return t.firstChild(); } else { String lval = t.firstChild().label().value(); if (lval != null && lval.startsWith("@")) { return t.firstChild(); } else { String rval = t.lastChild().label().value(); if (rval.startsWith("@") || rval.equals(Lexicon.BOUNDARY_TAG)) { return t.lastChild(); } } } return null; }
/** * Returns first child if this is unary and if the label at the current * node is either "ROOT" or empty. * * @return The first child if this is unary and if the label at the current * node is either "ROOT" or empty, else this */ public Tree skipRoot() { if(!isUnaryRewrite()) return this; String lab = label().value(); return (lab == null || lab.isEmpty() || "ROOT".equals(lab)) ? firstChild() : this; }
@Override public Tree readTree() throws IOException { Tree tr = super.readTree(); while (tr != null && tr.firstChild().value().equals("FRAG")) { // if (pw != null) { // pw.println("Discarding Tree:"); // tr.pennPrint(pw); // } tr = super.readTree(); } return tr; } }
private static boolean leftRec(Tree t, String baseCat) { while (!t.isLeaf()) { t = t.firstChild(); String str = t.label().value(); if (str.startsWith(baseCat)) { return true; } } return false; }
private Tree fixNonUnaryRoot(Tree t, TreeFactory tf) { List<Tree> kids = t.getChildrenAsList(); if(kids.size() == 2 && t.firstChild().isPhrasal() && tlp.isSentenceFinalPunctuationTag(t.lastChild().value())) { List<Tree> grandKids = t.firstChild().getChildrenAsList(); grandKids.add(t.lastChild()); t.firstChild().setChildren(grandKids); kids.remove(kids.size() - 1); t.setChildren(kids); t.setValue(tlp.startSymbol()); } else { t.setValue(nonUnaryRoot); t = tf.newTreeNode(tlp.startSymbol(), Collections.singletonList(t)); } return t; }
/** * Sets POS for punctuation to the punctuation token (like the PTB). * * @param t */ private String normalizePreterminal(Tree t) { if (ccTagset) { replacePOSTag(t, morpho); } if(tlp.isPunctuationWord(t.firstChild().value())) return tlp.punctuationTags()[0].intern(); //Map to a common tag // return t.firstChild().value();//Map to the punctuation item return t.value(); }
@Override public Tree normalizeWholeTree(Tree tree, TreeFactory tf) { tree = tree.prune(hebrewEmptyFilter, tf).spliceOut(aOverAFilter, tf); //Add start symbol so that the root has only one sub-state. Escape any enclosing brackets. //If the "tree" consists entirely of enclosing brackets e.g. ((())) then this method //will return null. In this case, readers e.g. PennTreeReader will try to read the next tree. while(tree != null && (tree.value() == null || tree.value().equals("")) && tree.numChildren() <= 1) tree = tree.firstChild(); if(tree != null && !tree.value().equals(tlp.startSymbol())) tree = tf.newTreeNode(tlp.startSymbol(), Collections.singletonList(tree)); return tree; }
public List<LabeledWord> labeledYield(List<LabeledWord> ty) { if (isPreTerminal()) { ty.add(new LabeledWord(firstChild().label(), label())); } else { for (Tree kid : children()) { kid.labeledYield(ty); } } return ty; }
public Tree untransformTree(Tree tree) { TreeFactory tf = tree.treeFactory(); if (tree.isPrePreTerminal()) { if (tree.firstChild().label().value().matches(".*_.")) { StringBuilder word = new StringBuilder(); for (int i = 0; i < tree.children().length; i++) { Tree child = tree.children()[i]; word.append(child.firstChild().label().value()); } Tree newChild = tf.newLeaf(word.toString()); tree.setChildren(Collections.singletonList(newChild)); } } else { for (int i = 0; i < tree.children().length; i++) { Tree child = tree.children()[i]; untransformTree(child); } } return tree; }
private int extractDeps(Tree t, int left, Set<Constituent> deps) { int position = left; // Segmentation constituents if(!useTag && t.isLeaf()) { position += t.label().value().length(); deps.add(cf.newConstituent(left, position - 1, t.label(), 0.0)); // POS tag constituents } else if(useTag && t.isPreTerminal()) { position += t.firstChild().label().value().length(); deps.add(cf.newConstituent(left, position - 1, t.label(), 0.0)); } else { Tree[] kids = t.children(); for (Tree kid : kids) position = extractDeps(kid, position, deps); } return position; }
@Override boolean satisfies(Tree t1, Tree t2, Tree root, final TregexMatcher matcher) { if (t2.isLeaf()) { return false; } else if (t2.isPreTerminal()) { return (t2.firstChild() == t1); } else { HeadFinder headFinder = matcher.getHeadFinder(); if (headFinder == null) headFinder = this.hf; Tree head = headFinder.determineHead(t2); if (head == t1) { return true; } else { return satisfies(t1, head, root, matcher); } } }
public Tree arabicAoverAFilter(Tree t) { if(t == null || t.isLeaf() || t.isPreTerminal()) return t; //Specific nodes to filter out if(t.numChildren() == 1) { final Tree fc = t.firstChild(); //A over A nodes i.e. from BobChrisTreeNormalizer if(t.label() != null && fc.label() != null && t.value().equals(fc.value())) { t.setChildren(fc.children()); } } for(Tree kid : t.getChildrenAsList()) arabicAoverAFilter(kid); return t; }