List of usage examples for edu.stanford.nlp.util StringUtils joinWords
public static String joinWords(Iterable<? extends HasWord> l, String glue)
From source file:knu.univ.lingvo.coref.Mention.java
License:Open Source License
public String nerName() { List<CoreLabel> t = nerTokens(); return (t != null) ? StringUtils.joinWords(t, " ") : null; }
From source file:knu.univ.lingvo.coref.Mention.java
License:Open Source License
private boolean isListLike() { // See if this mention looks to be a conjunction of things // Check for "or" and "and" and "," int commas = 0; // boolean firstLabelLike = false; // if (originalSpan.size() > 1) { // String w = originalSpan.get(1).word(); // firstLabelLike = (w.equals(":") || w.equals("-")); // }//from www .ja v a2 s .co m String mentionSpanString = spanToString(); String subTreeSpanString = StringUtils.joinWords(mentionSubTree.yieldWords(), " "); if (subTreeSpanString.equals(mentionSpanString)) { // subtree represents this mention well.... List<Tree> children = mentionSubTree.getChildrenAsList(); for (Tree t : children) { String label = t.value(); String ner = null; if (t.isLeaf()) { ner = ((CoreLabel) t.getLeaves().get(0).label()).ner(); } if ("CC".equals(label)) { // Check NER type if (ner == null || "O".equals(ner)) { return true; } } else if (label.equals(",")) { if (ner == null || "O".equals(ner)) { commas++; } } } } if (commas <= 2) { // look at the string for and/or boolean first = true; for (CoreLabel t : originalSpan) { String tag = t.tag(); String ner = t.ner(); String w = t.word(); if (tag.equals("TO") || tag.equals("IN") || tag.startsWith("VB")) { // prepositions and verbs are too hard for us return false; } if (!first) { if (w.equalsIgnoreCase("and") || w.equalsIgnoreCase("or")) { // Check NER type if (ner == null || "O".equals(ner)) { return true; } } } first = false; } } return (commas > 2); }
From source file:knu.univ.lingvo.coref.Mention.java
License:Open Source License
private void setHeadString() { this.headString = headWord.get(CoreAnnotations.TextAnnotation.class).toLowerCase(); String ner = headWord.get(CoreAnnotations.NamedEntityTagAnnotation.class); if (ner != null && !ner.equals("O")) { // make sure that the head of a NE is not a known suffix, e.g., Corp. int start = headIndex - startIndex; if (originalSpan.size() > 0 && start >= originalSpan.size()) { throw new RuntimeException("Invalid start index " + start + "=" + headIndex + "-" + startIndex + ": originalSpan=[" + StringUtils.joinWords(originalSpan, " ") + "], head=" + headWord); }// w ww . j a v a2s . co m while (start >= 0) { String head = originalSpan.size() > 0 ? originalSpan.get(start).get(CoreAnnotations.TextAnnotation.class).toLowerCase() : ""; if (knownSuffix(head)) { start--; } else { this.headString = head; this.headWord = originalSpan.get(start); this.headIndex = startIndex + start; break; } } } }
From source file:knu.univ.lingvo.coref.Mention.java
License:Open Source License
private static List<String> getContextHelper(List<? extends CoreLabel> words) { List<List<CoreLabel>> namedEntities = new ArrayList<List<CoreLabel>>(); List<CoreLabel> ne = new ArrayList<CoreLabel>(); String previousNEType = ""; int previousNEIndex = -1; for (int i = 0; i < words.size(); i++) { CoreLabel word = words.get(i);// ww w .j a va 2 s . c om if (!word.ner().equals("O")) { if (!word.ner().equals(previousNEType) || previousNEIndex != i - 1) { ne = new ArrayList<CoreLabel>(); namedEntities.add(ne); } ne.add(word); previousNEType = word.ner(); previousNEIndex = i; } } List<String> neStrings = new ArrayList<String>(); Set<String> hs = Generics.newHashSet(); for (List<CoreLabel> namedEntity : namedEntities) { String ne_str = StringUtils.joinWords(namedEntity, " "); hs.add(ne_str); } neStrings.addAll(hs); return neStrings; }