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;
}
Aggregations