public int getSentenceId() { return this.textAnnotation.getSentenceId(this.getStartSpan()); }
public int getSentenceId() { return this.textAnnotation.getSentenceId(this.getStartSpan()); }
public List<Sentence> getSentenceFromTokens(Set<Integer> tokens) { List<Sentence> mySentences = new ArrayList<>(); Set<Integer> sentencesSeen = new HashSet<>(); for (Sentence s : sentences()) { for (int token : tokens) { if (s.getSentenceConstituent().doesConstituentCover(token)) { if (!sentencesSeen.contains(s.getStartSpan())) { mySentences.add(s); sentencesSeen.add(s.getStartSpan()); } break; } } } return mySentences; }
private void initializeTokens() { if (tokens == null) { tokens = textAnnotation.getTokensInSpan(this.getStartSpan(), this.getEndSpan()); } }
private void initializeTokens() { if (tokens == null) { tokens = textAnnotation.getTokensInSpan(this.getStartSpan(), this.getEndSpan()); } }
private int getSentenceStart(int sentenceId) { Sentence sentence = this.getTextAnnotation().getSentence(sentenceId); return sentence.getStartSpan(); }
private int getSentenceStart(int sentenceId) { Sentence sentence = this.getTextAnnotation().getSentence(sentenceId); return sentence.getStartSpan(); }
private void checkViewAvailable(String viewName) { if (!views.containsKey(viewName)) { List<View> taViews = textAnnotation.getTopKViews(viewName); List<View> myViews = new ArrayList<>(); for (View v : taViews) { View restriction = v.getViewCoveringSpan(this.getStartSpan(), this.getEndSpan(), Sentence.defaultViewScoreSplitter); myViews.add(restriction); } this.addTopKView(viewName, myViews); } }
private void checkViewAvailable(String viewName) { if (!views.containsKey(viewName)) { List<View> taViews = textAnnotation.getTopKViews(viewName); List<View> myViews = new ArrayList<>(); for (View v : taViews) { View restriction = v.getViewCoveringSpan(this.getStartSpan(), this.getEndSpan(), Sentence.defaultViewScoreSplitter); myViews.add(restriction); } this.addTopKView(viewName, myViews); } }
@Override public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException { Sentence sentence = ta.getSentenceFromToken(wordPosition); int sentenceStart = sentence.getStartSpan(); int predicatePosition = wordPosition - sentenceStart; Tree<String> tree = ParseHelper.getParseTree(parseViewName, sentence); Tree<Pair<String, IntPair>> spanLabeledTree = ParseUtils.getSpanLabeledTree(tree); Tree<Pair<String, IntPair>> currentNode = spanLabeledTree.getYield().get(predicatePosition).getParent(); String f = getVoice(currentNode); return new LinkedHashSet<Feature>(Collections.singletonList(DiscreteFeature.create(f))); }
@Override public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException { Sentence sentence = ta.getSentenceFromToken(wordPosition); int sentenceStart = sentence.getStartSpan(); int predicatePosition = wordPosition - sentenceStart; Tree<String> tree = ParseHelper.getParseTree(parseViewName, sentence); Tree<Pair<String, IntPair>> spanLabeledTree = ParseUtils.getSpanLabeledTree(tree); Tree<Pair<String, IntPair>> currentNode = spanLabeledTree.getYield().get(predicatePosition).getParent(); String f = getVoice(currentNode); return new LinkedHashSet<Feature>(Collections.singletonList(DiscreteFeature.create(f))); }
/** * Check if the Constituent is a start of a sentence * The size of the Constituent should be 1 */ public static String isSentenceStart (Constituent c){ Sentence sentence = c.getTextAnnotation().getSentenceFromToken(c.getStartSpan()); int sentenceStart = sentence.getStartSpan(); if (c.getStartSpan() == sentenceStart){ return "1"; } return "0"; }
/** * Check if the Constituent is a start of a sentence * The size of the Constituent should be 1 */ public static String isSentenceStart (Constituent c){ Sentence sentence = c.getTextAnnotation().getSentenceFromToken(c.getStartSpan()); int sentenceStart = sentence.getStartSpan(); if (c.getStartSpan() == sentenceStart){ return "1"; } return "0"; }
/** * Check if the Constituent is a start of a sentence * The size of the Constituent should be 1 */ public static String isSentenceStart (Constituent c){ Sentence sentence = c.getTextAnnotation().getSentenceFromToken(c.getStartSpan()); int sentenceStart = sentence.getStartSpan(); if (c.getStartSpan() == sentenceStart){ return "1"; } return "0"; }
/** * given a {@link TextAnnotation} for a sentence with annotations, map its annotations into a * TextAnnotation object for a longer text containing that sentence. * @param sentenceTa annotated TextAnnotation for sentence * @param textTa TextAnnotation for longer text containing sentence, without annotations for that sentence * @param sentenceId index of the sentence in the longer text */ static public void mapSentenceAnnotationsToText(TextAnnotation sentenceTa, TextAnnotation textTa, int sentenceId ) { assert(sentenceId < textTa.getNumberOfSentences()); assert(sentenceTa.getText().equals(textTa.getSentence(sentenceId).getText())); int start = textTa.getSentence(sentenceId).getStartSpan(); int end = textTa.getSentence(sentenceId).getEndSpan(); copyViewsFromTo(sentenceTa, textTa, start, end, start); }
/** * given a {@link TextAnnotation} for a sentence with annotations, map its annotations into a * TextAnnotation object for a longer text containing that sentence. * @param sentenceTa annotated TextAnnotation for sentence * @param textTa TextAnnotation for longer text containing sentence, without annotations for that sentence * @param sentenceId index of the sentence in the longer text */ static public void mapSentenceAnnotationsToText(TextAnnotation sentenceTa, TextAnnotation textTa, int sentenceId ) { assert(sentenceId < textTa.getNumberOfSentences()); assert(sentenceTa.getText().equals(textTa.getSentence(sentenceId).getText())); int start = textTa.getSentence(sentenceId).getStartSpan(); int end = textTa.getSentence(sentenceId).getEndSpan(); copyViewsFromTo(sentenceTa, textTa, start, end, start); }
private static Tree<Pair<String, IntPair>> getTokenIndexedTreeCovering(Constituent predicate, String parseViewName) { TextAnnotation ta = predicate.getTextAnnotation(); int sentenceId = ta.getSentenceId(predicate); Tree<String> tree = getParseTree(parseViewName, ta, sentenceId); int sentenceStartSpan = ta.getSentence(sentenceId).getStartSpan(); int start = predicate.getStartSpan() - sentenceStartSpan; int end = predicate.getEndSpan() - sentenceStartSpan; return getTokenIndexedTreeCovering(tree, start, end); }
private static Tree<Pair<String, IntPair>> getTokenIndexedTreeCovering(Constituent predicate, String parseViewName) { TextAnnotation ta = predicate.getTextAnnotation(); int sentenceId = ta.getSentenceId(predicate); Tree<String> tree = ParseHelper.getParseTree(parseViewName, ta, sentenceId); int sentenceStartSpan = ta.getSentence(sentenceId).getStartSpan(); int start = predicate.getStartSpan() - sentenceStartSpan; int end = predicate.getEndSpan() - sentenceStartSpan; return ParseHelper.getTokenIndexedTreeCovering(tree, start, end); }
private static Tree<Pair<String, IntPair>> getTokenIndexedTreeCovering(Constituent predicate, String parseViewName) { TextAnnotation ta = predicate.getTextAnnotation(); int sentenceId = ta.getSentenceId(predicate); Tree<String> tree = ParseHelper.getParseTree(parseViewName, ta, sentenceId); int sentenceStartSpan = ta.getSentence(sentenceId).getStartSpan(); int start = predicate.getStartSpan() - sentenceStartSpan; int end = predicate.getEndSpan() - sentenceStartSpan; return ParseHelper.getTokenIndexedTreeCovering(tree, start, end); }
private static Tree<Pair<String, IntPair>> getTokenIndexedTreeCovering(Constituent predicate, String parseViewName) { TextAnnotation ta = predicate.getTextAnnotation(); int sentenceId = ta.getSentenceId(predicate); Tree<String> tree = getParseTree(parseViewName, ta, sentenceId); int sentenceStartSpan = ta.getSentence(sentenceId).getStartSpan(); int start = predicate.getStartSpan() - sentenceStartSpan; int end = predicate.getEndSpan() - sentenceStartSpan; return getTokenIndexedTreeCovering(tree, start, end); }