Search in sources :

Example 1 with ArrayCorpusPathExtractor

use of annis.sqlgen.ArrayCorpusPathExtractor 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)

Aggregations

AnnisNode (annis.model.AnnisNode)1 AnnotationGraph (annis.model.AnnotationGraph)1 Match (annis.service.objects.Match)1 MatchGroup (annis.service.objects.MatchGroup)1 ArrayCorpusPathExtractor (annis.sqlgen.ArrayCorpusPathExtractor)1 CorpusPathExtractor (annis.sqlgen.CorpusPathExtractor)1 PostgreSqlArraySolutionKey (annis.sqlgen.PostgreSqlArraySolutionKey)1 SaltAnnotateExtractor (annis.sqlgen.SaltAnnotateExtractor)1 CsvResultSetProvider (annis.test.CsvResultSetProvider)1 ArrayList (java.util.ArrayList)1 SaltProject (org.corpus_tools.salt.common.SaltProject)1 Test (org.junit.Test)1