private void parseAnalyzedTextSpan(JsonNode node, AnalysedText at) throws IOException { if(node.isObject()){ ObjectNode jSpan = (ObjectNode)node; int[] spanPos = new int[]{-1,-1}; Collection<Entry<String,JsonNode>> jAnnotations = new ArrayList<Entry<String,JsonNode>>(4); SpanTypeEnum spanType = parseSpanData(jSpan, spanPos, jAnnotations); if(spanType != SpanTypeEnum.Text || spanPos[0] != 0 || spanPos[1] < 0){ throw new IOException("The AnalyzedText span MUST have the SpanType 'text', a " + "start position of '0' and an end position (ignored, json: "+jSpan); } if(at.getEnd() != spanPos[1]){ throw new IOException("The size of the local text '"+at.getEnd()+"' does not " + "match the span of the parsed AnalyzedText ["+spanPos[0]+","+spanPos[1]+"]!"); } parseAnnotations(at, jAnnotations); } else { throw new IOException("Unable to parse AnalyzedText span form JsonNode "+node+" (expected JSON object)!"); } }
private void parseAnalyzedTextSpan(JsonNode node, AnalysedText at) throws IOException { if(node.isObject()){ ObjectNode jSpan = (ObjectNode)node; int[] spanPos = new int[]{-1,-1}; Collection<Entry<String,JsonNode>> jAnnotations = new ArrayList<Entry<String,JsonNode>>(4); SpanTypeEnum spanType = parseSpanData(jSpan, spanPos, jAnnotations); if(spanType != SpanTypeEnum.Text || spanPos[0] != 0 || spanPos[1] < 0){ throw new IOException("The AnalyzedText span MUST have the SpanType 'text', a " + "start position of '0' and an end position (ignored, json: "+jSpan); } if(at.getEnd() != spanPos[1]){ throw new IOException("The size of the local text '"+at.getEnd()+"' does not " + "match the span of the parsed AnalyzedText ["+spanPos[0]+","+spanPos[1]+"]!"); } parseAnnotations(at, jAnnotations); } else { throw new IOException("Unable to parse AnalyzedText span form JsonNode "+node+" (expected JSON object)!"); } }
private Occurrence(Section sentence,Token start,Token end){ this.start = start.getStart(); this.end = end.getEnd(); String context = sentence.getSpan(); if(context.length() > MAX_CONTEXT_LENGTH){ context = start.getContext().getSpan().substring( Math.max(0, this.start-CONTEXT_TOKEN_COUNT), Math.min(this.end+CONTEXT_TOKEN_COUNT, start.getContext().getEnd())-1); } this.context = context; } /**
private Occurrence(Section sentence,Token start,Token end){ this.start = start.getStart(); this.end = end.getEnd(); String context = sentence.getSpan(); if(context.length() > MAX_CONTEXT_LENGTH){ context = start.getContext().getSpan().substring( Math.max(0, this.start-CONTEXT_TOKEN_COUNT), Math.min(this.end+CONTEXT_TOKEN_COUNT, start.getContext().getEnd())-1); } this.context = context; } /**
graph.add(new TripleImpl(segment, Nif20.before.getUri(), new PlainLiteralImpl( content.substring(prefixStart, span.getStart()), language))); int suffixEnd = Math.min(span.getEnd() + DEFAULT_PREFIX_SUFFIX_LENGTH, text.getEnd()); graph.add(new TripleImpl(segment, Nif20.after.getUri(), new PlainLiteralImpl( content.substring(span.getEnd(), suffixEnd), language)));