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