Search in sources :

Example 11 with Annotation

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Annotation(annis.model.Annotation)

Example 12 with Annotation

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;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) WebResource(com.sun.jersey.api.client.WebResource) Annotation(annis.model.Annotation) LinkedList(java.util.LinkedList)

Example 13 with Annotation

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");
        }
    }
}
Also used : HashMap(java.util.HashMap) Annotation(annis.model.Annotation)

Example 14 with Annotation

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>();
    }
}
Also used : Helper(annis.libgui.Helper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WebResource(com.sun.jersey.api.client.WebResource) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Annotation(annis.model.Annotation)

Example 15 with 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;
}
Also used : Window(com.vaadin.ui.Window) Table(com.vaadin.ui.Table) BeanItemContainer(com.vaadin.data.util.BeanItemContainer) Annotation(annis.model.Annotation) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) Button(com.vaadin.ui.Button) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

Annotation (annis.model.Annotation)43 ArrayList (java.util.ArrayList)13 LinkedList (java.util.LinkedList)12 HashMap (java.util.HashMap)11 AnnisNode (annis.model.AnnisNode)10 AnnotatedSpan (annis.dao.objects.AnnotatedSpan)6 Test (org.junit.Test)6 AnnotatedMatch (annis.dao.objects.AnnotatedMatch)5 List (java.util.List)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)5 SAnnotation (org.corpus_tools.salt.core.SAnnotation)5 AnnisResult (annis.service.ifaces.AnnisResult)4 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)4 WebResource (com.sun.jersey.api.client.WebResource)4 Array (java.sql.Array)4 SNode (org.corpus_tools.salt.core.SNode)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 SToken (org.corpus_tools.salt.common.SToken)3 AnnotationGraph (annis.model.AnnotationGraph)2