List of usage examples for edu.stanford.nlp.ling CoreLabel sentIndex
@Override public int sentIndex()
From source file:semRewrite.substitutor.CoreLabelSequence.java
License:Open Source License
/** ************************************************************* * Checks if label is part of current sequence * @param text the label to be checked for in the sequence * @param sentIndex can be CoreLabelSequence.IGNORE_SENTENCE *//* w w w.j a va 2s . c o m*/ public boolean containsLabel(int sentIndex, String text, int index) { //System.out.println("CoreLabelSequence.containsLabel(): sentIndex: " + sentIndex); //System.out.println("CoreLabelSequence.containsLabel(): text: " + text); //System.out.println("CoreLabelSequence.containsLabel(): index: " + index); //System.out.println("CoreLabelSequence.containsLabel(): labels: " + labels); for (CoreLabel label : labels) { //System.out.println("CoreLabelSequence.containsLabel(): value: " + label.value()); //System.out.println("CoreLabelSequence.containsLabel():index: " + label.index()); if ((sentIndex == label.sentIndex() || sentIndex == IGNORE_SENTENCE) && text.equals(label.value()) // && index == label.index() FIXME: total hack! ) { //System.out.println("CoreLabelSequence.containsLabel(): success "); return true; } } //return labels.stream().anyMatch(label -> // (sentIndex == label.sentIndex() || sentIndex == IGNORE_SENTENCE) // && text.equals(label.originalText()) // && index == label.index() //); //System.out.println("CoreLabelSequence.containsLabel(): failure - label not in sequence "); return false; }
From source file:semRewrite.substitutor.StanfordCorefSubstitutor.java
License:Open Source License
/** ************************************************************** *//*from w w w.j av a 2 s . co m*/ private void initialize(Annotation document) { List<CoreLabel> labels = document.get(TokensAnnotation.class); Map<Integer, CorefChain> corefChains = document.get(CorefChainAnnotation.class); Map<semRewrite.substitutor.CoreLabelSequence, semRewrite.substitutor.CoreLabelSequence> collectedGroups = Maps .newHashMap(); for (CoreLabel label : labels) { List<CorefMention> mentions = getMentions(label, corefChains); if (mentions.size() > 1) { if (!ignorablePronouns.contains(label.originalText())) { int index = label.index(); int sentenceIdx = 1 + label.sentIndex(); CorefMention firstMention = findRootMention(mentions); if (sentenceIdx != firstMention.sentNum || index < firstMention.startIndex || index >= firstMention.endIndex) { String masterTag = label.tag(); if (isSubstitutablePronoun(label)) { masterTag = ""; } List<CoreLabel> singleSentence = getSentenceTokens(document, firstMention.sentNum - 1); semRewrite.substitutor.CoreLabelSequence key = extractTextWithSameTag(singleSentence, firstMention, masterTag); if (!key.isEmpty()) { collectedGroups.put(new semRewrite.substitutor.CoreLabelSequence(label), key); } } } } } addGroups(collectedGroups); }
From source file:semRewrite.substitutor.StanfordCorefSubstitutor.java
License:Open Source License
/** ************************************************************* *//* ww w . j a va2 s . c om*/ private List<CorefMention> getMentions(final CoreLabel label, Map<Integer, CorefChain> corefs) { List<CorefMention> mentions = ImmutableList.of(); Integer corefClusterId = label.get(CorefClusterIdAnnotation.class); while (mentions.size() <= 1 && corefClusterId != null && corefClusterId.compareTo(0) > 0) { if (corefs.containsKey(corefClusterId)) { List<CorefMention> candidateMentions = corefs.get(corefClusterId).getMentionsInTextualOrder(); boolean areMentionsContainLabel = candidateMentions.stream().anyMatch( mention -> mention.sentNum == label.sentIndex() + 1 && mention.startIndex == label.index()); if (areMentionsContainLabel) { mentions = candidateMentions; } } corefClusterId = corefClusterId - 1; } return mentions; }