use of annis.model.Annotation in project ANNIS by korpling.
the class MetaDataPanel method splitListAnnotations.
/**
* Returns empty map if no metadata are available.
*/
private Map<Integer, List<Annotation>> splitListAnnotations() {
List<Annotation> metadata = Helper.getMetaData(toplevelCorpusName, documentName);
Map<Integer, List<Annotation>> hashMetaData = new HashMap<>();
if (metadata != null && !metadata.isEmpty()) {
// if called from corpus browser sort the other way around.
if (documentName != null) {
hashMetaData = new TreeMap<>(Collections.reverseOrder());
} else {
hashMetaData = new TreeMap<>();
}
for (Annotation metaDatum : metadata) {
int pre = metaDatum.getPre();
if (!hashMetaData.containsKey(pre)) {
hashMetaData.put(pre, new ArrayList<Annotation>());
hashMetaData.get(pre).add(metaDatum);
} else {
hashMetaData.get(pre).add(metaDatum);
}
}
}
return hashMetaData;
}
use of annis.model.Annotation in project ANNIS by korpling.
the class MetaDataPanel method getAllSubcorpora.
private List<Annotation> getAllSubcorpora(String toplevelCorpusName) {
List<Annotation> result = new LinkedList<>();
WebResource res = Helper.getAnnisWebResource();
try {
res = res.path("meta").path("docnames").path(urlPathEscape.escape(toplevelCorpusName));
result = res.get(new Helper.AnnotationListType());
Collections.sort(result, new Comparator<Annotation>() {
@Override
public int compare(Annotation arg0, Annotation arg1) {
return ComparisonChain.start().compare(arg0.getName(), arg1.getName()).result();
}
});
} catch (UniformInterfaceException | ClientHandlerException ex) {
log.error(null, ex);
if (!AnnisBaseUI.handleCommonError(ex, "get documents")) {
Notification.show("Remote exception: " + ex.getLocalizedMessage(), Notification.Type.WARNING_MESSAGE);
}
}
return result;
}
use of annis.model.Annotation in project ANNIS by korpling.
the class GeneralTextExporter method appendMetaData.
public void appendMetaData(Writer out, List<String> metaKeys, String toplevelCorpus, String documentName, Map<String, Map<String, Annotation>> metadataCache) throws IOException {
Map<String, Annotation> metaData = new HashMap<>();
if (metadataCache.containsKey(toplevelCorpus + ":" + documentName)) {
metaData = metadataCache.get(toplevelCorpus + ":" + documentName);
} else {
List<Annotation> asList = Helper.getMetaData(toplevelCorpus, documentName);
for (Annotation anno : asList) {
metaData.put(anno.getQualifiedName(), anno);
metaData.put(anno.getName(), anno);
}
metadataCache.put(toplevelCorpus + ":" + documentName, metaData);
}
for (String key : metaKeys) {
Annotation anno = metaData.get(key);
if (anno != null) {
out.append("\tmeta::" + key + "\t" + anno.getValue()).append("\n");
}
}
}
use of annis.model.Annotation in project ANNIS by korpling.
the class DocBrowserTable method getDocMetaData.
/**
* Retrieves date from the cache or from the annis rest service for a specific
* document.
*
* @param document The document the data are fetched for.
* @return The a list of meta data. Can be empty but never null.
*/
private List<Annotation> getDocMetaData(String document) {
// lookup up meta data in the cache
if (!docMetaDataCache.containsKey(docBrowserPanel.getCorpus())) {
// get the metadata for the corpus
WebResource res = Helper.getAnnisWebResource();
res = res.path("meta/corpus/").path(urlPathEscape.escape(docBrowserPanel.getCorpus())).path("closure");
Map<String, List<Annotation>> metaDataMap = new HashMap<>();
// create a document -> metadata map
for (Annotation a : res.get(new Helper.AnnotationListType())) {
if (a.getAnnotationPath() != null && !a.getAnnotationPath().isEmpty() && a.getType().equals("DOCUMENT")) {
String docName = a.getAnnotationPath().get(0);
if (!metaDataMap.containsKey(docName)) {
metaDataMap.put(docName, new ArrayList<Annotation>());
}
metaDataMap.get(docName).add(a);
}
}
docMetaDataCache.put(docBrowserPanel.getCorpus(), metaDataMap);
}
if (docMetaDataCache.get(docBrowserPanel.getCorpus()).containsKey(document)) {
return docMetaDataCache.get(docBrowserPanel.getCorpus()).get(document);
} else {
return new ArrayList<Annotation>();
}
}
use of annis.model.Annotation in project ANNIS by korpling.
the class DocBrowserTable method generateInfoButtonCell.
public Button generateInfoButtonCell(final String docName) {
Button btn = new Button();
btn.setStyleName(ChameleonTheme.BUTTON_BORDERLESS);
btn.setIcon(INFO_ICON);
btn.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
try {
List<Annotation> annos = getDocMetaData(docName);
/**
* Transforms to a list of key value pairs. The values concates the
* namespace and ordinary value. Namespaces "NULL" are ignored.
*/
// create datasource and bind it to a table
BeanItemContainer<Annotation> metaContainer = new BeanItemContainer<>(Annotation.class);
metaContainer.addAll(annos);
metaContainer.sort(new Object[] { "namespace", "name" }, new boolean[] { true, true });
Table metaTable = new Table();
metaTable.setContainerDataSource(metaContainer);
metaTable.addGeneratedColumn("genname", new MetaDataPanel.MetaTableNameGenerator(metaContainer));
metaTable.addGeneratedColumn("genvalue", new MetaDataPanel.MetaTableValueGenerator(metaContainer));
metaTable.setVisibleColumns("genname", "genvalue");
metaTable.setColumnHeaders(new String[] { "Name", "Value" });
metaTable.setSizeFull();
metaTable.setColumnWidth("genname", -1);
metaTable.setColumnExpandRatio("genvalue", 1.0f);
metaTable.addStyleName(ChameleonTheme.TABLE_STRIPED);
// create and style the extra window for the metadata table
Window metaWin = new Window();
metaWin.setContent(metaTable);
metaWin.setCaption("metadata doc " + docName);
metaWin.center();
metaWin.setWidth(400, Unit.PIXELS);
metaWin.setHeight(400, Unit.PIXELS);
// paint the window
docBrowserPanel.getUI().addWindow(metaWin);
} catch (UniformInterfaceException ex) {
log.error("can not retrieve metadata for document " + docName, ex);
}
}
});
return btn;
}
Aggregations