// check if the selected text is added
assertTrue(selectedTextIterator.hasNext());
// test if the selected text is part of the TEXT_TO_TEST
Resource object = selectedTextIterator.next().getObject();
assertTrue(object instanceof Literal);
Literal selectedText = (Literal)object;
object = null;
assertTrue(content.indexOf(selectedText.getLexicalForm()) >= 0);
// test if context is added
//context not present for Zemanta
// Iterator<Triple> selectionContextIterator = g.filter(textAnnotation,
// Properties.ENHANCER_SELECTION_CONTEXT, null);
// assertTrue(selectionContextIterator.hasNext());
// // test if the selected text is part of the TEXT_TO_TEST
// object = selectionContextIterator.next().getObject();
// assertTrue(object instanceof Literal);
// assertTrue(content.indexOf(((Literal)object).getLexicalForm()) >= 0);
// object = null;
//test start/end if present
Iterator<Triple> startPosIterator = g.filter(textAnnotation,
ENHANCER_START, null);
Iterator<Triple> endPosIterator = g.filter(textAnnotation,
ENHANCER_END, null);
//start end is optional, but if start is present, that also end needs to be set
if(startPosIterator.hasNext()){
Resource resource = startPosIterator.next().getObject();
//only a single start position is supported
assertTrue(!startPosIterator.hasNext());
assertTrue(resource instanceof TypedLiteral);
TypedLiteral startPosLiteral = (TypedLiteral) resource;
resource = null;
int start = LiteralFactory.getInstance().createObject(Integer.class, startPosLiteral);
startPosLiteral = null;
//now get the end
//end must be defined if start is present
assertTrue(endPosIterator.hasNext());
resource = endPosIterator.next().getObject();
//only a single end position is supported
assertTrue(!endPosIterator.hasNext());
assertTrue(resource instanceof TypedLiteral);
TypedLiteral endPosLiteral = (TypedLiteral) resource;
resource = null;
int end = LiteralFactory.getInstance().createObject(Integer.class, endPosLiteral);
endPosLiteral = null;
//check for equality of the selected text and the text on the selected position in the content
//System.out.println("TA ["+start+"|"+end+"]"+selectedText.getLexicalForm()+"<->"+content.substring(start,end));
assertTrue(content.substring(start, end).equals(selectedText.getLexicalForm()));
} else {
//if no start position is present, there must also be no end position defined
assertTrue(!endPosIterator.hasNext());
}
}