Search in sources :

Example 6 with AnnotatedSpan

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

the class AnnotatedSpanExtractor method mapRow.

@Override
public AnnotatedSpan mapRow(ResultSet resultSet, int rowNum) throws SQLException {
    long id = resultSet.getLong("id");
    String coveredText = resultSet.getString("span");
    Array arrayAnnotation = resultSet.getArray("annotations");
    ResultSetMetaData rsMeta = resultSet.getMetaData();
    Array arrayMeta = null;
    for (int i = 1; i <= rsMeta.getColumnCount(); i++) {
        if ("metadata".equals(rsMeta.getColumnName(i))) {
            arrayMeta = resultSet.getArray(i);
            break;
        }
    }
    List<Annotation> annotations = extractAnnotations(arrayAnnotation);
    List<Annotation> metaData = arrayMeta == null ? new LinkedList<Annotation>() : extractAnnotations(arrayMeta);
    // create key
    Array sqlKey = resultSet.getArray("key");
    Validate.isTrue(!resultSet.wasNull(), "Match group identifier must not be null");
    Validate.isTrue(sqlKey.getBaseType() == Types.BIGINT, "Key in database must be from the type \"bigint\" but was \"" + sqlKey.getBaseTypeName() + "\"");
    List<Long> key = Arrays.asList((Long[]) sqlKey.getArray());
    return new AnnotatedSpan(id, coveredText, annotations, metaData, key);
}
Also used : Array(java.sql.Array) ResultSetMetaData(java.sql.ResultSetMetaData) AnnotatedSpan(annis.dao.objects.AnnotatedSpan) Annotation(annis.model.Annotation)

Example 7 with AnnotatedSpan

use of annis.dao.objects.AnnotatedSpan 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

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