use of annis.service.ifaces.AnnisResult in project ANNIS by korpling.
the class TokenExporter method convertText.
@Override
public void convertText(AnnisResultSet queryResult, List<String> keys, Map<String, String> args, Writer out, int offset) throws IOException {
Map<String, Map<String, Annotation>> metadataCache = new HashMap<>();
List<String> metaKeys = new LinkedList<>();
if (args.containsKey("metakeys")) {
Iterable<String> it = Splitter.on(",").trimResults().split(args.get("metakeys"));
for (String s : it) {
metaKeys.add(s);
}
}
int counter = 0;
for (AnnisResult annisResult : queryResult) {
Set<Long> matchedNodeIds = annisResult.getGraph().getMatchedNodeIds();
counter++;
out.append((counter + offset) + ". ");
List<AnnisNode> tok = annisResult.getGraph().getTokens();
for (AnnisNode annisNode : tok) {
Long tokID = annisNode.getId();
if (matchedNodeIds.contains(tokID)) {
out.append("[");
out.append(annisNode.getSpannedText());
out.append("]");
} else {
out.append(annisNode.getSpannedText());
}
for (Annotation annotation : annisNode.getNodeAnnotations()) {
out.append("/" + annotation.getValue());
}
out.append(" ");
}
out.append("\n");
if (!metaKeys.isEmpty()) {
String[] path = annisResult.getPath();
super.appendMetaData(out, metaKeys, path[path.length - 1], annisResult.getDocumentName(), metadataCache);
}
out.append("\n");
}
}
use of annis.service.ifaces.AnnisResult in project ANNIS by korpling.
the class TestAnnisResultImpl method getStartEndNodeId.
// return last token
@Test
public void getStartEndNodeId() {
// wrap and test
AnnisResult annisResult = new AnnisResultImpl(graph);
assertThat(annisResult.getEndNodeId(), is(ID3));
}
use of annis.service.ifaces.AnnisResult in project ANNIS by korpling.
the class TestAnnisResultImpl method getTokenList.
// convert token list
@Test
public void getTokenList() {
// expected
List<AnnisToken> expected = new ArrayList<>();
expected.add(new AnnisTokenImpl(ID1, TEXT1, LEFT, RIGHT, TOKEN_INDEX1, 1L));
expected.add(new AnnisTokenImpl(ID2, TEXT2, LEFT, RIGHT, TOKEN_INDEX2, 1L));
expected.add(new AnnisTokenImpl(ID3, TEXT3, LEFT, RIGHT, TOKEN_INDEX3, 1L));
// wrap and test
AnnisResult annisResult = new AnnisResultImpl(graph);
assertThat(annisResult.getTokenList(), is(expected));
}
use of annis.service.ifaces.AnnisResult in project ANNIS by korpling.
the class TestAnnisResultImpl method hasMarkerId.
// a node is marked if it is a matched node
@Test
public void hasMarkerId() {
// underlying graph has marker for node ID1
when(graph.getMatchedNodeIds()).thenReturn(new HashSet<>(Arrays.asList(ID1)));
// wrap and test: ID1 is marked, ID2 is not
AnnisResult annisResult = new AnnisResultImpl(graph);
assertThat(annisResult.hasMarker(String.valueOf(ID1)), is(true));
assertThat(annisResult.hasMarker(String.valueOf(ID2)), is(false));
}
use of annis.service.ifaces.AnnisResult in project ANNIS by korpling.
the class TestAnnisResultImpl method getMarkerIdMatchedNode.
// return ID (as string) if node is a matched node, otherwise return null
@Test
public void getMarkerIdMatchedNode() {
// underlying graph has marker for node ID1
when(graph.getMatchedNodeIds()).thenReturn(new HashSet<>(Arrays.asList(ID1)));
// wrap and test: ID1 is marked, ID2 is not
AnnisResult annisResult = new AnnisResultImpl(graph);
assertThat(annisResult.getMarkerId(ID1), is(String.valueOf(ID1)));
assertThat(annisResult.getMarkerId(ID2), is(nullValue()));
}
Aggregations