fun buildTextAnnotation( corpusId: String?, textId: String?, text: String?, tokens: Array<String?>, sentenceEndPositions: IntArray, sentenceViewGenerator: String?, sentenceViewScore: Double ): TextAnnotation? { require(sentenceEndPositions[sentenceEndPositions.size - 1] == tokens.size) { "Invalid sentence boundary. Last element should be the number of tokens" } val offsets: Array<IntPair> = TokenUtils.getTokenOffsets(text, tokens) assert(offsets.size == tokens.size) val ta = TextAnnotation(corpusId, textId, text, offsets, tokens, sentenceEndPositions) val view = SpanLabelView(ViewNames.SENTENCE, sentenceViewGenerator, ta, sentenceViewScore) var start = 0 for (s in sentenceEndPositions) { view.addSpanLabel(start, s, ViewNames.SENTENCE, 1.0) start = s } ta.addView(ViewNames.SENTENCE, view) val tokView = SpanLabelView(ViewNames.TOKENS, sentenceViewGenerator, ta, sentenceViewScore) for (tokIndex in tokens.indices) { tokView.addSpanLabel(tokIndex, tokIndex + 1, tokens[tokIndex], 1.0) } ta.addView(ViewNames.TOKENS, tokView) return ta }
instantiate a TextAnnotation using a SentenceViewGenerator to create an explicit Sentence view