Search in sources :

Example 6 with AnnotatedMatch

use of annis.dao.objects.AnnotatedMatch in project ANNIS by korpling.

the class WekaHelper method exportArffHeader.

public static SortedMap<Integer, SortedSet<String>> exportArffHeader(Iterator<AnnotatedMatch> matches, PrintWriter w) {
    // header: relation name (unused)
    w.append("@relation name\n");
    w.append("\n");
    // figure out what annotations are used at each match position
    SortedMap<Integer, SortedSet<String>> columnsByNodePos = new TreeMap<>();
    while (matches.hasNext()) {
        AnnotatedMatch match = matches.next();
        for (int j = 0; j < match.size(); ++j) {
            AnnotatedSpan span = match.get(j);
            if (columnsByNodePos.get(j) == null) {
                columnsByNodePos.put(j, new TreeSet<String>());
            }
            for (Annotation annotation : span.getAnnotations()) {
                columnsByNodePos.get(j).add("anno_" + annotation.getQualifiedName());
            }
            for (Annotation meta : span.getMetadata()) {
                columnsByNodePos.get(j).add("meta_" + meta.getQualifiedName());
            }
        }
    }
    // print column names and data types
    int count = columnsByNodePos.keySet().size();
    for (int j = 0; j < count; ++j) {
        w.append("@attribute ").append(fullColumnName(j + 1, "id")).append(" string\n");
        w.append("@attribute ").append(fullColumnName(j + 1, "span")).append(" string\n");
        SortedSet<String> annotationNames = columnsByNodePos.get(j);
        for (String name : annotationNames) {
            w.append("@attribute ").append(fullColumnName(j + 1, name)).append(" string\n");
        }
    }
    return columnsByNodePos;
}
Also used : AnnotatedMatch(annis.dao.objects.AnnotatedMatch) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) AnnotatedSpan(annis.dao.objects.AnnotatedSpan) Annotation(annis.model.Annotation)

Aggregations

AnnotatedMatch (annis.dao.objects.AnnotatedMatch)6 AnnotatedSpan (annis.dao.objects.AnnotatedSpan)6 Annotation (annis.model.Annotation)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 SortedSet (java.util.SortedSet)2 TreeMap (java.util.TreeMap)2 CSVWriter (au.com.bytecode.opencsv.CSVWriter)1 Array (java.sql.Array)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1