Search in sources :

Example 6 with Annotation

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;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) GenericType(com.sun.jersey.api.client.GenericType) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) ArrayList(java.util.ArrayList) AsyncWebResource(com.sun.jersey.api.client.AsyncWebResource) WebResource(com.sun.jersey.api.client.WebResource) SAnnotation(org.corpus_tools.salt.core.SAnnotation) Annotation(annis.model.Annotation)

Example 7 with Annotation

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

Example 8 with Annotation

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);
}
Also used : AnnotatedMatch(annis.dao.objects.AnnotatedMatch) ArrayList(java.util.ArrayList) AnnotatedSpan(annis.dao.objects.AnnotatedSpan) Annotation(annis.model.Annotation)

Example 9 with Annotation

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

Example 10 with 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;
}
Also used : Table(com.vaadin.ui.Table) Annotation(annis.model.Annotation)

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