use of annis.model.Annotation in project ANNIS by korpling.
the class Helper method getMetaData.
/**
* Retrieve all the meta data for a given document of a corpus including the
* metadata of all corora in the path to the document.
*
* @param toplevelCorpusName Specifies the the toplevel corpus
* @param documentName Specifies the document
* @return Returns also the metada of the all parent corpora. There must be at
* least one of them.
*/
public static List<Annotation> getMetaData(String toplevelCorpusName, String documentName) {
List<Annotation> result = new ArrayList<Annotation>();
WebResource res = Helper.getAnnisWebResource();
try {
res = res.path("meta").path("doc").path(urlPathEscape.escape(toplevelCorpusName));
if (documentName != null) {
res = res.path(urlPathEscape.escape(documentName));
}
if (documentName != null && !toplevelCorpusName.equals(documentName)) {
res = res.path("path");
}
result = res.get(new GenericType<List<Annotation>>() {
});
} catch (UniformInterfaceException | ClientHandlerException ex) {
log.error(null, ex);
if (!AnnisBaseUI.handleCommonError(ex, "retrieve metada")) {
Notification.show("Remote exception: " + ex.getLocalizedMessage(), Notification.Type.WARNING_MESSAGE);
}
}
return result;
}
use of annis.model.Annotation in project ANNIS by korpling.
the class AnnotatedSpanExtractor method extractAnnotations.
private List<Annotation> extractAnnotations(Array array) throws SQLException {
List<Annotation> result = new ArrayList<>();
if (array != null) {
String[] arrayLines = (String[]) array.getArray();
for (String line : arrayLines) {
if (line != null) {
String namespace = null;
String name = null;
String value = null;
String[] split = line.split(":", 3);
Preconditions.checkState(split.length == 3, "The annotation string for the matrix entry must contain a namespace, name and value");
if (split.length == 3) {
namespace = split[0];
name = split[1];
value = split[2];
}
if ("".equals(namespace)) {
namespace = null;
}
result.add(new annis.model.Annotation(namespace, name, value));
}
// if line not null
}
}
return result;
}
use of annis.model.Annotation in project ANNIS by korpling.
the class AnnotatedMatchIterator method next.
@Override
public AnnotatedMatch next() {
List<Long> key = new ArrayList<>();
AnnotatedSpan[] matchedSpans = new AnnotatedSpan[0];
if (lastSpan != null) {
key = lastSpan.getKey();
if (key == null) {
matchedSpans = new AnnotatedSpan[0];
} else {
matchedSpans = new AnnotatedSpan[key.size()];
setSpanForAllMatchedPositions(key, matchedSpans, lastSpan);
}
lastSpan = null;
}
while (itSpan.hasNext()) {
AnnotatedSpan span = itSpan.next();
List<Long> newKey = span.getKey();
if (matchedSpans.length == 0) {
matchedSpans = new AnnotatedSpan[newKey.size()];
}
if (key.isEmpty() || newKey.equals(key)) {
setSpanForAllMatchedPositions(newKey, matchedSpans, span);
key = newKey;
lastSpan = null;
} else {
// save reference to the already fetched span since we can't get back
lastSpan = span;
// we finished collecting all relevant spans
break;
}
}
// HACK: delete metadata spans for non-first nodes
for (int i = 1; i < matchedSpans.length; i++) {
if (matchedSpans[i] != null) {
matchedSpans[i].setMetadata(new LinkedList<Annotation>());
}
}
return new AnnotatedMatch(matchedSpans);
}
use of annis.model.Annotation in project ANNIS by korpling.
the class ListDocumentsSqlHelper method mapRow.
@Override
public Annotation mapRow(ResultSet rs, int rowNum) throws SQLException {
Annotation annotation = new Annotation();
annotation.setName(rs.getString("name"));
annotation.setPre(rs.getInt("pre"));
Array annotationPathArray = rs.getArray("path_name");
List<String> annotationPath = new LinkedList<>();
if (annotationPathArray.getBaseType() == Types.VARCHAR) {
annotationPath = Arrays.asList((String[]) annotationPathArray.getArray());
}
annotation.setAnnotationPath(annotationPath);
return annotation;
}
use of annis.model.Annotation in project ANNIS by korpling.
the class MetaDataPanel method setupTable.
private Table setupTable(BeanItemContainer<Annotation> metaData) {
final BeanItemContainer<Annotation> mData = metaData;
mData.sort(new Object[] { "namespace", "name" }, new boolean[] { true, true });
Table tblMeta = new Table();
tblMeta.setContainerDataSource(mData);
tblMeta.addGeneratedColumn("genname", new MetaTableNameGenerator(mData));
tblMeta.addGeneratedColumn("genvalue", new MetaTableValueGenerator(mData));
tblMeta.setVisibleColumns("genname", "genvalue");
tblMeta.setColumnHeaders("Name", "Value");
tblMeta.setSizeFull();
tblMeta.setColumnWidth("genname", -1);
tblMeta.setColumnExpandRatio("genvalue", 1.0f);
tblMeta.addStyleName(ChameleonTheme.TABLE_STRIPED);
return tblMeta;
}
Aggregations