Search in sources :

Example 31 with AnnisNode

use of annis.model.AnnisNode in project ANNIS by korpling.

the class TestAnnisResultImpl method setup.

@Before
public void setup() {
    initMocks(this);
    // sanity check: IDS are different
    assertThat(ID1, is(not(ID2)));
    assertThat(ID2, is(not(ID3)));
    assertThat(ID3, is(not(ID1)));
    // set up underlying graph
    token1 = newToken(ID1, TEXT1, TOKEN_INDEX1);
    token2 = newToken(ID2, TEXT2, TOKEN_INDEX2);
    token3 = newToken(ID3, TEXT3, TOKEN_INDEX3);
    node4 = new AnnisNode(ID4);
    node5 = new AnnisNode(ID5);
    when(graph.getNodes()).thenReturn(Arrays.asList(token1, token2, token3, node4, node5));
    when(graph.getTokens()).thenReturn(Arrays.asList(token1, token2, token3));
}
Also used : AnnisNode(annis.model.AnnisNode) Before(org.junit.Before)

Example 32 with AnnisNode

use of annis.model.AnnisNode in project ANNIS by korpling.

the class AomAnnotateSqlGeneratorTest method createDefaultEdge.

private Edge createDefaultEdge() {
    Edge expected = new Edge();
    expected.setPre(PRE);
    expected.setEdgeType(EDGETYPE);
    expected.setNamespace(EDGE_NAMESPACE);
    expected.setName(EDGE_NAME);
    expected.setSource(new AnnisNode(PARENT));
    expected.setDestination(new AnnisNode(NODE_REF));
    return expected;
}
Also used : AnnisNode(annis.model.AnnisNode) Edge(annis.model.Edge)

Example 33 with AnnisNode

use of annis.model.AnnisNode in project ANNIS by korpling.

the class AomAnnotateSqlGeneratorTest method shouldMapNodeWithToken.

@Test
public void shouldMapNodeWithToken() throws SQLException {
    // given
    stubNodeResultSet();
    given(resultSet.wasNull()).willReturn(true);
    // when
    AnnisNode node = generator.mapNode(resultSet, tableAccessStrategy, null);
    // then
    assertThat(node.isToken(), is(false));
}
Also used : AnnisNode(annis.model.AnnisNode) Test(org.junit.Test)

Example 34 with AnnisNode

use of annis.model.AnnisNode in project ANNIS by korpling.

the class LegacyGraphConverterTest method testConvertToAOM.

/**
 * Test of convertToAOM method, of class LegacyGraphConverter.
 */
@Test
public void testConvertToAOM() throws SQLException {
    SaltAnnotateExtractor saltExtractor = new SaltAnnotateExtractor() {

        @Override
        protected SolutionKey<?> createSolutionKey() {
            PostgreSqlArraySolutionKey<Long> key = new PostgreSqlArraySolutionKey<>();
            key.setKeyColumnName("key");
            key.setIdColumnName("id");
            return key;
        }
    };
    CorpusPathExtractor corpusPathExtractor = new ArrayCorpusPathExtractor();
    saltExtractor.setCorpusPathExtractor(corpusPathExtractor);
    TestAnnotateSqlGenerator.setupOuterQueryFactsTableColumnAliases(saltExtractor);
    List<Match> matches = new ArrayList<>();
    matches.add(Match.parseFromString("salt:/pcc2/4282/#tok_155 tiger::pos::salt:/pcc2/4282#tok_156"));
    MatchGroup matchGroup = new MatchGroup(matches);
    SaltProject p = saltExtractor.extractData(new CsvResultSetProvider(annis.sqlgen.SaltAnnotateExtractorTest.class.getResourceAsStream("SampleAnnotateResult.csv")).getResultSet());
    SaltAnnotateExtractor.addMatchInformation(p, matchGroup);
    List<AnnotationGraph> expected = aomSqlGen.extractData(new CsvResultSetProvider(annis.sqlgen.SaltAnnotateExtractorTest.class.getResourceAsStream("SampleAnnotateResult.csv")).getResultSet());
    List<AnnotationGraph> result = LegacyGraphConverter.convertToAOM(p);
    assertEquals(expected.size(), result.size());
    Iterator<AnnotationGraph> itGraphExpected = expected.iterator();
    Iterator<AnnotationGraph> itGraphResult = result.iterator();
    while (itGraphExpected.hasNext() && itGraphResult.hasNext()) {
        AnnotationGraph graphExpected = itGraphExpected.next();
        AnnotationGraph graphResult = itGraphResult.next();
        List<AnnisNode> nodeListExpected = graphExpected.getNodes();
        List<AnnisNode> nodeListResult = graphResult.getNodes();
        assertEquals(nodeListExpected.size(), nodeListResult.size());
        Collections.sort(nodeListExpected, new Comparator<AnnisNode>() {

            @Override
            public int compare(AnnisNode arg0, AnnisNode arg1) {
                return Long.valueOf(arg0.getId()).compareTo(Long.valueOf(arg1.getId()));
            }
        });
        Collections.sort(nodeListResult, new Comparator<AnnisNode>() {

            @Override
            public int compare(AnnisNode arg0, AnnisNode arg1) {
                return Long.valueOf(arg0.getId()).compareTo(Long.valueOf(arg1.getId()));
            }
        });
        Iterator<AnnisNode> itNodeExpected = nodeListExpected.iterator();
        Iterator<AnnisNode> itNodeResult = nodeListResult.iterator();
        while (itNodeExpected.hasNext() && itNodeResult.hasNext()) {
            checkAnnisNodeEqual(itNodeExpected.next(), itNodeResult.next());
        }
    }
}
Also used : ArrayCorpusPathExtractor(annis.sqlgen.ArrayCorpusPathExtractor) CorpusPathExtractor(annis.sqlgen.CorpusPathExtractor) ArrayList(java.util.ArrayList) SaltProject(org.corpus_tools.salt.common.SaltProject) PostgreSqlArraySolutionKey(annis.sqlgen.PostgreSqlArraySolutionKey) SaltAnnotateExtractor(annis.sqlgen.SaltAnnotateExtractor) Match(annis.service.objects.Match) AnnotationGraph(annis.model.AnnotationGraph) ArrayCorpusPathExtractor(annis.sqlgen.ArrayCorpusPathExtractor) MatchGroup(annis.service.objects.MatchGroup) AnnisNode(annis.model.AnnisNode) CsvResultSetProvider(annis.test.CsvResultSetProvider) Test(org.junit.Test)

Example 35 with AnnisNode

use of annis.model.AnnisNode in project ANNIS by korpling.

the class AomAnnotateExtractor method mapEdge.

public Edge mapEdge(ResultSet resultSet, TableAccessStrategy tableAccessStrategy) throws SQLException {
    Edge edge = new Edge();
    edge.setPre(longValue(resultSet, RANK_TABLE, "pre", tableAccessStrategy));
    edge.setComponentID(longValue(resultSet, RANK_TABLE, "component_id", tableAccessStrategy));
    edge.setEdgeType(EdgeType.parseEdgeType(stringValue(resultSet, RANK_TABLE, "edge_type", tableAccessStrategy)));
    edge.setNamespace(stringValue(resultSet, COMPONENT_TABLE, "namespace", tableAccessStrategy));
    edge.setName(stringValue(resultSet, COMPONENT_TABLE, "name", tableAccessStrategy));
    edge.setDestination(new AnnisNode(longValue(resultSet, RANK_TABLE, "node_ref", tableAccessStrategy)));
    edge.setComponentID(longValue(resultSet, COMPONENT_TABLE, "id", tableAccessStrategy));
    edge.setId(longValue(resultSet, RANK_TABLE, "id", tableAccessStrategy));
    // create nodes for src with rank value (parent) as id.
    // this must later be fixed by AnnotationGraphDaoHelper.fixSourceNodeIds().
    // this is simpler than chaining the edgeByPre map in AnnisResultSetBuilder
    // and making the EdgeRowMapper thread-safe.
    // FIXME: use custum mapRow(resultSet, edgeByPre) function, throw Exception here
    // also, no need to implement Spring RowMapper
    long parent = longValue(resultSet, RANK_TABLE, "parent", tableAccessStrategy);
    if (!resultSet.wasNull())
        edge.setSource(new AnnisNode(parent));
    return edge;
}
Also used : AnnisNode(annis.model.AnnisNode) Edge(annis.model.Edge)

Aggregations

AnnisNode (annis.model.AnnisNode)38 Annotation (annis.model.Annotation)10 Edge (annis.model.Edge)9 LinkedList (java.util.LinkedList)8 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Map (java.util.Map)5 AnnotationGraph (annis.model.AnnotationGraph)4 AnnisResult (annis.service.ifaces.AnnisResult)4 DetectHoles (annis.visualizers.iframe.partitur.DetectHoles)2 DocumentNameMapRow (annis.dao.DocumentNameMapRow)1 MatchedNodeColors (annis.libgui.MatchedNodeColors)1 RelannisEdgeFeature (annis.model.RelannisEdgeFeature)1 RelannisNodeFeature (annis.model.RelannisNodeFeature)1 AnnisToken (annis.service.ifaces.AnnisToken)1 Match (annis.service.objects.Match)1 MatchGroup (annis.service.objects.MatchGroup)1 ArrayCorpusPathExtractor (annis.sqlgen.ArrayCorpusPathExtractor)1 CorpusPathExtractor (annis.sqlgen.CorpusPathExtractor)1