Search in sources :

Example 11 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class FixAttachFeature330 method doMigration.

private void doMigration() {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("migrationRoot");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = null;
    try {
        status = txManager.getTransaction(def);
        for (Project project : projectService.listProjects()) {
            try {
                AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), project);
                // Set attach-feature of Dependency layer to Token.pos if necessary
                fix(project, Dependency.class, RELATION_TYPE, tokenLayer, "pos");
                // Set attach-feature of POS layer to Token.pos if necessary
                fix(project, POS.class, SPAN_TYPE, tokenLayer, "pos");
                // Set attach-feature of Lemma layer to Token.lemma if necessary
                fix(project, Lemma.class, SPAN_TYPE, tokenLayer, "lemma");
                // Set attach-feature of MorphologicalFeatures layer to Token.morph if necessary
                fix(project, MorphologicalFeatures.class, SPAN_TYPE, tokenLayer, "morph");
            } catch (NoResultException e) {
                // This only happens if a project is not fully set up. Every project
                // should have a Token layer. However, it is not the responsibility of this
                // migration to enforce this, so we just ignore it.
                log.warn("Project {} does not seem to include a Token layer!", project);
            }
        }
        txManager.commit(status);
    } finally {
        if (status != null && !status.isCompleted()) {
            txManager.rollback(status);
        }
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionStatus(org.springframework.transaction.TransactionStatus) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) NoResultException(javax.persistence.NoResultException) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 12 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class FixAttachFeature330 method fix.

private void fix(Project aProject, Class<? extends TOP> aLayer, String aLayerType, AnnotationLayer aTokenLayer, String aFeature) {
    if (annotationSchemaService.existsLayer(aLayer.getName(), aLayerType, aProject)) {
        AnnotationLayer layer = annotationSchemaService.getLayer(aLayer.getName(), aProject);
        if (layer.getAttachFeature() == null) {
            layer.setAttachFeature(annotationSchemaService.getFeature(aFeature, aTokenLayer));
            log.info("DATABASE UPGRADE PERFORMED: Fixed attach-feature of layer " + "[{}] ({}) in project [{}] ({})", layer.getUiName(), layer.getId(), aProject.getName(), aProject.getId());
        }
    }
}
Also used : AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 13 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class ChunkLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer chunkLayer = new AnnotationLayer(Chunk.class.getName(), "Chunk", SPAN_TYPE, aProject, true);
    chunkLayer.setAllowStacking(false);
    chunkLayer.setMultipleTokens(true);
    chunkLayer.setLockToTokenOffset(false);
    annotationSchemaService.createLayer(chunkLayer);
    AnnotationFeature chunkValueFeature = new AnnotationFeature();
    chunkValueFeature.setDescription("Chunk tag");
    chunkValueFeature.setName("chunkValue");
    chunkValueFeature.setType(CAS.TYPE_NAME_STRING);
    chunkValueFeature.setProject(aProject);
    chunkValueFeature.setUiName("Tag");
    chunkValueFeature.setLayer(chunkLayer);
    annotationSchemaService.createFeature(chunkValueFeature);
}
Also used : AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Chunk(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.chunk.Chunk) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 14 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class LemmaLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), aProject);
    AnnotationFeature tokenLemmaFeature = new AnnotationFeature(aProject, tokenLayer, "lemma", "lemma", Lemma.class.getName());
    annotationSchemaService.createFeature(tokenLemmaFeature);
    AnnotationLayer lemmaLayer = new AnnotationLayer(Lemma.class.getName(), "Lemma", SPAN_TYPE, aProject, true);
    lemmaLayer.setAttachType(tokenLayer);
    lemmaLayer.setAttachFeature(tokenLemmaFeature);
    annotationSchemaService.createLayer(lemmaLayer);
    AnnotationFeature lemmaFeature = new AnnotationFeature();
    lemmaFeature.setDescription("lemma Annotation");
    lemmaFeature.setName("value");
    lemmaFeature.setType(CAS.TYPE_NAME_STRING);
    lemmaFeature.setProject(aProject);
    lemmaFeature.setUiName("Lemma");
    lemmaFeature.setLayer(lemmaLayer);
    annotationSchemaService.createFeature(lemmaFeature);
}
Also used : Lemma(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 15 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class CasToBratJsonTest method testGenerateBratJsonGetCollection.

/**
 * generate BRAT JSON for the collection informations
 *
 * @throws IOException
 *             if an I/O error occurs.
 */
@Test
public void testGenerateBratJsonGetCollection() throws IOException {
    MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
    String jsonFilePath = "target/test-output/output_cas_to_json_collection.json";
    GetCollectionInformationResponse collectionInformation = new GetCollectionInformationResponse();
    List<AnnotationLayer> layerList = new ArrayList<>();
    AnnotationLayer layer = new AnnotationLayer();
    layer.setId(1l);
    layer.setDescription("span annoattion");
    layer.setName("pos");
    layer.setType(WebAnnoConst.SPAN_TYPE);
    TagSet tagset = new TagSet();
    tagset.setId(1l);
    tagset.setDescription("pos");
    tagset.setLanguage("de");
    tagset.setName("STTS");
    Tag tag = new Tag();
    tag.setId(1l);
    tag.setDescription("noun");
    tag.setName("NN");
    tag.setTagSet(tagset);
    layerList.add(layer);
    collectionInformation.addCollection("/Collection1/");
    collectionInformation.addCollection("/Collection2/");
    collectionInformation.addCollection("/Collection3/");
    collectionInformation.addDocument("/Collection1/doc1");
    collectionInformation.addDocument("/Collection2/doc1");
    collectionInformation.addDocument("/Collection3/doc1");
    collectionInformation.addDocument("/Collection1/doc2");
    collectionInformation.addDocument("/Collection2/doc2");
    collectionInformation.addDocument("/Collection3/doc2");
    collectionInformation.setSearchConfig(new ArrayList<>());
    List<String> tagSetNames = new ArrayList<>();
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.POS);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.DEPENDENCY);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.NAMEDENTITY);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.COREFERENCE);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.COREFRELTYPE);
    JSONUtil.generatePrettyJson(jsonConverter, collectionInformation, new File(jsonFilePath));
    assertThat(linesOf(new File("src/test/resources/output_cas_to_json_collection_expected.json"), "UTF-8")).isEqualTo(linesOf(new File(jsonFilePath), "UTF-8"));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) ArrayList(java.util.ArrayList) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) GetCollectionInformationResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.GetCollectionInformationResponse) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) File(java.io.File) Test(org.junit.Test)

Aggregations

AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)67 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)35 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 ArrayList (java.util.ArrayList)14 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)13 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 LogMessage (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage)8 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)7 Type (org.apache.uima.cas.Type)7 JCas (org.apache.uima.jcas.JCas)6 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)5 FeatureStructure (org.apache.uima.cas.FeatureStructure)5 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)5 Test (org.junit.Test)5 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)4 HashMap (java.util.HashMap)4 TypeSystemDescriptionFactory.createTypeSystemDescription (org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription)4 SoftAssertions (org.assertj.core.api.SoftAssertions)4 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)3