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);
}
}
}
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());
}
}
}
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);
}
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);
}
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"));
}
Aggregations