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 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); } }
for (int row = start; row < ta.getSentence(sentenceId).getEndSpan(); row++) { String[] rowData = columns[row];
private static void writeSentences(TextAnnotation ta, JsonObject json) { JsonObject object = new JsonObject(); SpanLabelView sentenceView = (SpanLabelView) ta.getView(ViewNames.SENTENCE); writeString("generator", sentenceView.getViewGenerator(), object); writeDouble("score", sentenceView.getScore(), object); int numSentences = sentenceView.getNumberOfConstituents(); int[] sentenceEndPositions = new int[numSentences]; int id = 0; for (Sentence sentence : ta.sentences()) { sentenceEndPositions[id++] = sentence.getEndSpan(); } writeIntArray("sentenceEndPositions", sentenceEndPositions, object); json.add("sentences", object); }
private static void writeSentences(TextAnnotation ta, JsonObject json) { JsonObject object = new JsonObject(); SpanLabelView sentenceView = (SpanLabelView) ta.getView(ViewNames.SENTENCE); writeString("generator", sentenceView.getViewGenerator(), object); writeDouble("score", sentenceView.getScore(), object); int numSentences = sentenceView.getNumberOfConstituents(); int[] sentenceEndPositions = new int[numSentences]; int id = 0; for (Sentence sentence : ta.sentences()) { sentenceEndPositions[id++] = sentence.getEndSpan(); } writeIntArray("sentenceEndPositions", sentenceEndPositions, object); json.add("sentences", object); }
public static void outputToColumnFormatFile(TextAnnotation ta, String viewName, String outputFilePath){ List<Integer> sentence_ends = new ArrayList<Integer>(); for (int i = 0; i < ta.getNumberOfSentences(); i++){ sentence_ends.add(ta.getSentence(i).getEndSpan());
public static void outputToColumnFormatFile(TextAnnotation ta, String viewName, String outputFilePath){ List<Integer> sentence_ends = new ArrayList<Integer>(); for (int i = 0; i < ta.getNumberOfSentences(); i++){ sentence_ends.add(ta.getSentence(i).getEndSpan());
/** * 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); }
.getEndSpan()) { String nextToken = WordHelpers.getLemma(ta, predicateToken + 1);
TextAnnotation ta = source.getTextAnnotation(); int sentenceStart = ta.getSentence(source.getSentenceId()).getStartSpan(); int sentenceEnd = ta.getSentence(source.getSentenceId()).getEndSpan(); if (source.getStartSpan() - sentenceStart > 0){ ret_features.add("fwM1_" + ta.getToken(source.getStartSpan() - 1));
/** * Process each sentence individually. This potentially allows for failure at an individual * sentence level, without failing for the whole text. THIS REQUIRES THAT ALL RELATIONS ARE * INTRA-SENTENCE. Any that are *not* will be omitted for the sentence-level processing. * * @param annotator Annotator to apply * @param textAnnotation TextAnnotation to augment * @return */ public void processBySentence(Annotator annotator, TextAnnotation textAnnotation) { logger.debug("in processBySentence()..."); for (int sentenceId = 0; sentenceId < textAnnotation.sentences().size(); ++sentenceId) { TextAnnotation sentTa = TextAnnotationUtilities.getSubTextAnnotation(textAnnotation, sentenceId); try { annotator.getView(sentTa); int start = textAnnotation.getSentence(sentenceId).getStartSpan(); int end = textAnnotation.getSentence(sentenceId).getEndSpan(); TextAnnotationUtilities.copyViewFromTo(annotator.getViewName(), sentTa, textAnnotation, start, end, start); } catch (AnnotatorException e) { e.printStackTrace(); } } return; }
/** * Process each sentence individually. This potentially allows for failure at an individual * sentence level, without failing for the whole text. THIS REQUIRES THAT ALL RELATIONS ARE * INTRA-SENTENCE. Any that are *not* will be omitted for the sentence-level processing. * * @param annotator Annotator to apply * @param textAnnotation TextAnnotation to augment * @return */ public void processBySentence(Annotator annotator, TextAnnotation textAnnotation) { logger.debug("in processBySentence()..."); for (int sentenceId = 0; sentenceId < textAnnotation.sentences().size(); ++sentenceId) { TextAnnotation sentTa = TextAnnotationUtilities.getSubTextAnnotation(textAnnotation, sentenceId); try { annotator.getView(sentTa); int start = textAnnotation.getSentence(sentenceId).getStartSpan(); int end = textAnnotation.getSentence(sentenceId).getEndSpan(); TextAnnotationUtilities.copyViewFromTo(annotator.getViewName(), sentTa, textAnnotation, start, end, start); } catch (AnnotatorException e) { e.printStackTrace(); } } return; }
private static void writeSentences(TextAnnotation ta, TextAnnotationProto.Builder taBuilder) { SentenceProto.Builder sentenceBuilder = SentenceProto.newBuilder(); SpanLabelView sentenceView = (SpanLabelView) ta.getView(ViewNames.SENTENCE); sentenceBuilder.setGenerator(sentenceView.getViewGenerator()); sentenceBuilder.setScore(sentenceView.getScore()); for (Sentence sentence: ta.sentences()) { sentenceBuilder.addSentenceEndPositions(sentence.getEndSpan()); } taBuilder.setSentences(sentenceBuilder); }
private static void writeSentences(TextAnnotation ta, TextAnnotationProto.Builder taBuilder) { SentenceProto.Builder sentenceBuilder = SentenceProto.newBuilder(); SpanLabelView sentenceView = (SpanLabelView) ta.getView(ViewNames.SENTENCE); sentenceBuilder.setGenerator(sentenceView.getViewGenerator()); sentenceBuilder.setScore(sentenceView.getScore()); for (Sentence sentence: ta.sentences()) { sentenceBuilder.addSentenceEndPositions(sentence.getEndSpan()); } taBuilder.setSentences(sentenceBuilder); }
/** * Get the form/lemma features of a given Constituent. * The size of the Constituent should be 1 */ public static List<Pair<Integer, String>> getWordFormFeatures (Constituent c){ List<Pair<Integer, String>> ret_features = new ArrayList<>(); TextAnnotation ta = c.getTextAnnotation(); Sentence sentence = ta.getSentenceFromToken(c.getStartSpan()); int sentenceStart = sentence.getStartSpan(); int sentenceEnd = sentence.getEndSpan(); if (c.getStartSpan() > sentenceStart){ ret_features.add(new Pair<>(-1, ta.getToken(c.getStartSpan() - 1))); ret_features.add(new Pair<>(-1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() - 1)))); } ret_features.add(new Pair<>(0, ta.getToken(c.getStartSpan()))); ret_features.add(new Pair<>(0, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan())))); if (c.getEndSpan() < sentenceEnd){ ret_features.add(new Pair<>(1, ta.getToken(c.getStartSpan() + 1))); ret_features.add(new Pair<>(1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 1)))); } if (c.getEndSpan() < sentenceEnd - 1){ ret_features.add(new Pair<>(2, ta.getToken(c.getStartSpan() + 2))); ret_features.add(new Pair<>(2, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 2)))); } return ret_features; }
/** * Get the form/lemma features of a given Constituent. * The size of the Constituent should be 1 */ public static List<Pair<Integer, String>> getWordFormFeatures (Constituent c){ List<Pair<Integer, String>> ret_features = new ArrayList<>(); TextAnnotation ta = c.getTextAnnotation(); Sentence sentence = ta.getSentenceFromToken(c.getStartSpan()); int sentenceStart = sentence.getStartSpan(); int sentenceEnd = sentence.getEndSpan(); if (c.getStartSpan() > sentenceStart){ ret_features.add(new Pair<>(-1, ta.getToken(c.getStartSpan() - 1))); ret_features.add(new Pair<>(-1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() - 1)))); } ret_features.add(new Pair<>(0, ta.getToken(c.getStartSpan()))); ret_features.add(new Pair<>(0, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan())))); if (c.getEndSpan() < sentenceEnd){ ret_features.add(new Pair<>(1, ta.getToken(c.getStartSpan() + 1))); ret_features.add(new Pair<>(1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 1)))); } if (c.getEndSpan() < sentenceEnd - 1){ ret_features.add(new Pair<>(2, ta.getToken(c.getStartSpan() + 2))); ret_features.add(new Pair<>(2, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 2)))); } return ret_features; }
/** * Get the form/lemma features of a given Constituent. * The size of the Constituent should be 1 */ public static List<Pair<Integer, String>> getWordFormFeatures (Constituent c){ List<Pair<Integer, String>> ret_features = new ArrayList<>(); TextAnnotation ta = c.getTextAnnotation(); Sentence sentence = ta.getSentenceFromToken(c.getStartSpan()); int sentenceStart = sentence.getStartSpan(); int sentenceEnd = sentence.getEndSpan(); if (c.getStartSpan() > sentenceStart){ ret_features.add(new Pair<>(-1, ta.getToken(c.getStartSpan() - 1))); ret_features.add(new Pair<>(-1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() - 1)))); } ret_features.add(new Pair<>(0, ta.getToken(c.getStartSpan()))); ret_features.add(new Pair<>(0, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan())))); if (c.getEndSpan() < sentenceEnd){ ret_features.add(new Pair<>(1, ta.getToken(c.getStartSpan() + 1))); ret_features.add(new Pair<>(1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 1)))); } if (c.getEndSpan() < sentenceEnd - 1){ ret_features.add(new Pair<>(2, ta.getToken(c.getStartSpan() + 2))); ret_features.add(new Pair<>(2, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 2)))); } return ret_features; }