@Override public Tree evaluate(Tree tree, TregexMatcher tregex) { Tree result = newNodeNames.get(label); if (result == null) { result = tregex.getNode(label); } if (result == null) { log.warn("Null node fetched by Tsurgeon operation for node: " + label + " (either no node labeled this, or the labeled node didn't match anything)"); } return result; }
TreeGraphNode target = (TreeGraphNode) m.getNode("target"); if (target == null) { throw new AssertionError("Expression has no target: " + p); log.info("found " + this + "(" + t + "-" + t.headWordNode() + ", " + m.getNode("target") + "-" + ((TreeGraphNode) m.getNode("target")).headWordNode() + ") using pattern " + p); for (String nodeName : m.getNodeNames()) { if (nodeName.equals("target")) continue; log.info(" node " + nodeName + ": " + m.getNode(nodeName));
@Override public Tree evaluate(Tree tree, TregexMatcher tregex) { if (invert ^ (tregex.getNode(name) != null)) { for (TsurgeonMatcher child : childMatcher) { child.evaluate(tree, tregex); } } return tree; } }
public String apply(TregexMatcher m) { String type = m.getNode("c").value().toUpperCase(); return "-conj" + type; }
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 ""; } }
public String apply(TregexMatcher m) { String node = m.getNode(key).value(); String eqClass = tlp.basicCategory(node); if(nnTagClass.contains(eqClass)) eqClass = "noun"; else if(jjTagClass.contains(eqClass)) eqClass = "adj"; else if(vbTagClass.contains(eqClass)) eqClass = "vb"; return annotationMark + eqClass; }
public String apply(TregexMatcher m) { String node = m.getNode(key).label().value(); if (node.startsWith("S")) { return annotationMark + 'S'; } else if (node.startsWith("V")) { return annotationMark + 'V'; } else { return ""; } }
@Override public String apply(TregexMatcher m) { String punc = m.getNode(key).value(); String punctClass = PunctEquivalenceClasser.getPunctClass(punc); return punctClass.equals("") ? "" : annotationMark + punctClass; }
public Tree transformTree(Tree t) { TregexMatcher matcher = tregexMonthYear.matcher(t); while (matcher.find()) { Tree root = matcher.getNode("root"); Tree month = matcher.getNode("month"); Tree year = matcher.getNode("year"); Tree[] children = new Tree[] {month, year}; root.setChildren(children); matcher = tregexMonthYear.matcher(t); } matcher = tregexMonthDayYear.matcher(t); while (matcher.find()) { Tree root = matcher.getNode("root"); Tree month = matcher.getNode("month"); Tree day = matcher.getNode("day"); Tree comma = matcher.getNode("comma"); Tree year = matcher.getNode("year"); Tree[] children = new Tree[] {month, day, comma, year}; root.setChildren(children); matcher = tregexMonthDayYear.matcher(t); } return t; } }
public String apply(TregexMatcher m) { String val = m.getNode(key).label().value(); if (pattern != null) { Matcher mat = pattern.matcher(val); if (mat.find()) { val = mat.group(1); } } if(key2 != null && pattern2 != null) { String val2 = m.getNode(key2).label().value(); Matcher mat2 = pattern2.matcher(val2); if(mat2.find()) { val = val + annotationMark + mat2.group(1); } else { val = val + annotationMark + val2; } } return annotationMark + val; }
public String apply(TregexMatcher m) { final String punc = m.getNode(key).value();
public String apply(TregexMatcher m) { final String punc = m.getNode(key).value(); if (punc.equals(".")) return "-fs"; else if (punc.equals("?")) return "-quest"; else if (punc.equals(",")) return "-comma"; else if (punc.equals(":") || punc.equals(";")) return "-colon"; else if (punc.equals("-LRB-")) return "-lrb"; else if (punc.equals("-RRB-")) return "-rrb"; else if (punc.equals("-PLUS-")) return "-plus"; else if (punc.equals("-")) return "-dash"; else if (quote.matcher(punc).matches()) return "-quote"; // else if(punc.equals("/")) // return "-slash"; // else if(punc.equals("%")) // return "-perc"; // else if(punc.contains("..")) // return "-ellipses"; return ""; }
private void findTreePattern(Tree tree, TregexPattern tgrepPattern, Set<Pair<Integer, Integer>> foundPairs) { try { TregexMatcher m = tgrepPattern.matcher(tree); while (m.find()) { Tree t = m.getMatch(); Tree np1 = m.getNode("m1"); Tree np2 = m.getNode("m2"); Tree np3 = null; if(tgrepPattern.pattern().contains("m3")) np3 = m.getNode("m3"); addFoundPair(np1, np2, t, foundPairs); if(np3!=null) addFoundPair(np2, np3, t, foundPairs); } } catch (Exception e) { // shouldn't happen.... throw new RuntimeException(e); } }
public String apply(TregexMatcher m) { String tag; if(key2 == null) tag = annotationMark + ((doBasicCat) ? tlp.basicCategory(m.getNode(key).label().value()) : m.getNode(key).label().value()); else { String annot1 = (doBasicCat) ? tlp.basicCategory(m.getNode(key).label().value()) : m.getNode(key).label().value(); String annot2 = (doBasicCat) ? tlp.basicCategory(m.getNode(key2).label().value()) : m.getNode(key2).label().value(); tag = annotationMark + annot1 + annotationMark + annot2; } return (toLower) ? tag.toLowerCase() : tag; }
public String apply(TregexMatcher m) { if(key2 == null) return annotationMark + ((doBasicCat) ? tlp.basicCategory(m.getNode(key).label().value()) : m.getNode(key).label().value()); else { String annot1 = (doBasicCat) ? tlp.basicCategory(m.getNode(key).label().value()) : m.getNode(key).label().value(); String annot2 = (doBasicCat) ? tlp.basicCategory(m.getNode(key2).label().value()) : m.getNode(key2).label().value(); return annotationMark + annot1 + annotationMark + annot2; } }
} else if (nodePattern.matcher(chunk).matches()) { String name = chunk.substring(2, chunk.length() - 1); label.append(Matcher.quoteReplacement(tregex.getNode(name).value())); } else { label.append(chunk);
/** * ¡Venga, expand conmigo! */ private static Tree expandConmigo(Tree t) { TregexMatcher matcher = conmigoPattern.matcher(t); while (matcher.find()) { Tree conmigoNode = matcher.getNode("conmigo"); String word = conmigoNode.value(); String newPronoun = null; if (word.equalsIgnoreCase("conmigo")) newPronoun = "mÃ"; else if (word.equalsIgnoreCase("contigo")) newPronoun = "ti"; else if (word.equalsIgnoreCase("consigo")) newPronoun = "sÃ"; if (word.charAt(0) == 'C') newPronoun = newPronoun.toUpperCase(); String tsurgeon = String.format( "[relabel conmigo /%s/]" + "[adjoinF (sp (prep (sp000 con)) foot@) sn]", newPronoun); TsurgeonPattern pattern = Tsurgeon.parseOperation(tsurgeon); t = pattern.matcher().evaluate(t, matcher); } return t; }
private static boolean checkPleonastic(Mention m, Tree tree, TregexPattern tgrepPattern) { try { TregexMatcher matcher = tgrepPattern.matcher(tree); while (matcher.find()) { Tree np1 = matcher.getNode("m1"); if (((CoreLabel)np1.label()).get(CoreAnnotations.BeginIndexAnnotation.class)+1 == m.headWord.get(CoreAnnotations.IndexAnnotation.class)) { return true; } } } catch (Exception e) { e.printStackTrace(); } return false; }
private static boolean checkPleonastic(Mention m, Tree tree, TregexPattern tgrepPattern) { try { TregexMatcher matcher = tgrepPattern.matcher(tree); while (matcher.find()) { Tree np1 = matcher.getNode("m1"); if (((CoreLabel)np1.label()).get(CoreAnnotations.BeginIndexAnnotation.class)+1 == m.headWord.get(CoreAnnotations.IndexAnnotation.class)) { return true; } } } catch (Exception e) { e.printStackTrace(); } return false; } }
protected static void extractEnumerations(CoreMap s, List<Mention> mentions, Set<IntPair> mentionSpanSet, Set<IntPair> namedEntitySpanSet) { List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class); Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class); SemanticGraph dependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class); TregexPattern tgrepPattern = enumerationsMentionPattern; TregexMatcher matcher = tgrepPattern.matcher(tree); Map<IntPair, Tree> spanToMentionSubTree = Generics.newHashMap(); while (matcher.find()) { matcher.getMatch(); Tree m1 = matcher.getNode("m1"); Tree m2 = matcher.getNode("m2"); List<Tree> mLeaves = m1.getLeaves(); int beginIdx = ((CoreLabel)mLeaves.get(0).label()).get(CoreAnnotations.IndexAnnotation.class)-1; int endIdx = ((CoreLabel)mLeaves.get(mLeaves.size()-1).label()).get(CoreAnnotations.IndexAnnotation.class); spanToMentionSubTree.put(new IntPair(beginIdx, endIdx), m1); mLeaves = m2.getLeaves(); beginIdx = ((CoreLabel)mLeaves.get(0).label()).get(CoreAnnotations.IndexAnnotation.class)-1; endIdx = ((CoreLabel)mLeaves.get(mLeaves.size()-1).label()).get(CoreAnnotations.IndexAnnotation.class); spanToMentionSubTree.put(new IntPair(beginIdx, endIdx), m2); } for(IntPair mSpan : spanToMentionSubTree.keySet()){ if(!mentionSpanSet.contains(mSpan) && !insideNE(mSpan, namedEntitySpanSet)) { int dummyMentionId = -1; Mention m = new Mention(dummyMentionId, mSpan.get(0), mSpan.get(1), dependency, new ArrayList<>(sent.subList(mSpan.get(0), mSpan.get(1))), spanToMentionSubTree.get(mSpan)); mentions.add(m); mentionSpanSet.add(mSpan); } } }