Search in sources :

Example 1 with TsvChain

use of de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvChain in project webanno by webanno.

the class Tsv3XDeserializer method read.

public void read(LineNumberReader aIn, JCas aJCas) throws IOException {
    deferredActions.set(new ArrayList<>());
    TsvFormatHeader format = readFormat(aIn);
    TsvSchema schema = readSchema(aIn, aJCas);
    // Read the extra blank line after the schema declaration
    String emptyLine = aIn.readLine();
    assert isEmpty(emptyLine);
    TsvDocument doc = new TsvDocument(format, schema, aJCas);
    for (TsvColumn column : schema.getColumns()) {
        doc.activateColumn(column);
        doc.activateType(column.uimaType);
    }
    readContent(aIn, doc);
    // Complete the addition of the chains
    CAS cas = aJCas.getCas();
    for (TsvChain chain : doc.getChains()) {
        if (chain.getElements().isEmpty()) {
            continue;
        }
        Iterator<AnnotationFS> linkIterator = chain.getElements().iterator();
        AnnotationFS link = linkIterator.next();
        // Create the chain head
        FeatureStructure head = cas.createFS(chain.getHeadType());
        setFeature(head, CHAIN_FIRST_FEAT, link);
        cas.addFsToIndexes(head);
        // Connect the links to each other
        AnnotationFS prevLink = link;
        while (linkIterator.hasNext()) {
            link = linkIterator.next();
            setFeature(prevLink, CHAIN_NEXT_FEAT, link);
            prevLink = link;
        }
    }
    // Run deferred actions
    for (Runnable action : deferredActions.get()) {
        action.run();
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) TsvFormatHeader(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvFormatHeader) TsvColumn(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvColumn) CAS(org.apache.uima.cas.CAS) TsvChain(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvChain) TsvDocument(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvDocument) TsvSchema(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvSchema)

Example 2 with TsvChain

use of de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvChain in project webanno by webanno.

the class Tsv3XSerializer method writeChainElement.

private static void writeChainElement(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol, AnnotationFS aFS) {
    String value = getFeature(aFS, COREFERENCE_TYPE_FEATURE, String.class);
    value = value == null ? NULL_VALUE : escapeValue(value);
    TsvChain chain = aDoc.getChain(aFS);
    aOut.printf("%s[%d]", value, chain.getId());
}
Also used : TsvChain(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvChain)

Example 3 with TsvChain

use of de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvChain in project webanno by webanno.

the class Tsv3XSerializer method writeChainLink.

private static void writeChainLink(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol, AnnotationFS aFS) {
    String value = getFeature(aFS, COREFERENCE_RELATION_FEATURE, String.class);
    value = value == null ? NULL_VALUE : escapeValue(value);
    TsvChain chain = aDoc.getChain(aFS);
    aOut.printf("%s->%d-%d", value, chain.getId(), chain.indexOf(aFS) + 1);
}
Also used : TsvChain(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvChain)

Aggregations

TsvChain (de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvChain)3 TsvColumn (de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvColumn)1 TsvDocument (de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvDocument)1 TsvFormatHeader (de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvFormatHeader)1 TsvSchema (de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvSchema)1 CAS (org.apache.uima.cas.CAS)1 FeatureStructure (org.apache.uima.cas.FeatureStructure)1 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)1