Search in sources :

Example 6 with AnnisResult

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");
    }
}
Also used : HashMap(java.util.HashMap) AnnisResult(annis.service.ifaces.AnnisResult) LinkedList(java.util.LinkedList) Annotation(annis.model.Annotation) AnnisNode(annis.model.AnnisNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with AnnisResult

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));
}
Also used : AnnisResult(annis.service.ifaces.AnnisResult) Test(org.junit.Test)

Example 8 with AnnisResult

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));
}
Also used : AnnisToken(annis.service.ifaces.AnnisToken) ArrayList(java.util.ArrayList) AnnisResult(annis.service.ifaces.AnnisResult) Test(org.junit.Test)

Example 9 with AnnisResult

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));
}
Also used : AnnisResult(annis.service.ifaces.AnnisResult) Test(org.junit.Test)

Example 10 with AnnisResult

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()));
}
Also used : AnnisResult(annis.service.ifaces.AnnisResult) Test(org.junit.Test)

Aggregations

AnnisResult (annis.service.ifaces.AnnisResult)10 Test (org.junit.Test)6 AnnisNode (annis.model.AnnisNode)4 Annotation (annis.model.Annotation)4 LinkedList (java.util.LinkedList)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Edge (annis.model.Edge)1 AnnisToken (annis.service.ifaces.AnnisToken)1 AbstractImageGraphicsItem (annis.visualizers.component.tree.backends.staticimg.AbstractImageGraphicsItem)1 Graphics2D (java.awt.Graphics2D)1 AffineTransform (java.awt.geom.AffineTransform)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1