public TextAnnotation(String corpusId, String id, String text, IntPair[] characterOffsets, String[] tokens, int[] sentenceEndPositions) { super(); // if the string is non-empty, the position of the last element should equal to the number of tokens if (tokens.length > 0 && sentenceEndPositions[sentenceEndPositions.length - 1] != tokens.length) throw new IllegalArgumentException("Invalid sentence boundary. " + "Last element should be the number of tokens"); this.corpusId = corpusId; this.id = id; this.text = text; this.symtab = new SymbolTable(); this.setTokens(tokens, characterOffsets); SpanLabelView view = new SpanLabelView(ViewNames.SENTENCE, "UserSpecified", this, 1d); int start = 0; for (int s : sentenceEndPositions) { view.addSpanLabel(start, s, ViewNames.SENTENCE, 1d); start = s; } this.addView(ViewNames.SENTENCE, view); // Add a TOKENS view in order to access tokens the same way as everything else in the // sentence TokenLabelView tokenLabelView = new TokenLabelView(ViewNames.TOKENS, "UserSpecified", this, 1d); for (int i = 0; i < tokens.length; i++) { tokenLabelView.addConstituent(new Constituent("", ViewNames.TOKENS, this, i, i + 1)); } this.addView(ViewNames.TOKENS, tokenLabelView); }
public TextAnnotation(String corpusId, String id, String text, IntPair[] characterOffsets, String[] tokens, int[] sentenceEndPositions) { super(); // if the string is non-empty, the position of the last element should equal to the number of tokens if (tokens.length > 0 && sentenceEndPositions[sentenceEndPositions.length - 1] != tokens.length) throw new IllegalArgumentException("Invalid sentence boundary. " + "Last element should be the number of tokens"); this.corpusId = corpusId; this.id = id; this.text = text; this.symtab = new SymbolTable(); this.setTokens(tokens, characterOffsets); SpanLabelView view = new SpanLabelView(ViewNames.SENTENCE, "UserSpecified", this, 1d); int start = 0; for (int s : sentenceEndPositions) { view.addSpanLabel(start, s, ViewNames.SENTENCE, 1d); start = s; } this.addView(ViewNames.SENTENCE, view); // Add a TOKENS view in order to access tokens the same way as everything else in the // sentence TokenLabelView tokenLabelView = new TokenLabelView(ViewNames.TOKENS, "UserSpecified", this, 1d); for (int i = 0; i < tokens.length; i++) { tokenLabelView.addConstituent(new Constituent("", ViewNames.TOKENS, this, i, i + 1)); } this.addView(ViewNames.TOKENS, tokenLabelView); }