use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class BratRenderer method buildEntityTypes.
/**
* Generates brat type definitions from the WebAnno layer definitions.
*
* @param aAnnotationLayers
* the layers
* @param aAnnotationService
* the annotation service
* @return the brat type definitions
*/
public static Set<EntityType> buildEntityTypes(List<AnnotationLayer> aAnnotationLayers, AnnotationSchemaService aAnnotationService) {
// Sort layers
List<AnnotationLayer> layers = new ArrayList<>(aAnnotationLayers);
layers.sort(Comparator.comparing(AnnotationLayer::getName));
// Now build the actual configuration
Set<EntityType> entityTypes = new LinkedHashSet<>();
for (AnnotationLayer layer : layers) {
EntityType entityType = configureEntityType(layer);
List<RelationType> arcs = new ArrayList<>();
// For link features, we also need to configure the arcs, even though there is no arc
// layer here.
boolean hasLinkFeatures = false;
for (AnnotationFeature f : aAnnotationService.listAnnotationFeature(layer)) {
if (!LinkMode.NONE.equals(f.getLinkMode())) {
hasLinkFeatures = true;
break;
}
}
if (hasLinkFeatures) {
String bratTypeName = getBratTypeName(layer);
arcs.add(new RelationType(layer.getName(), layer.getUiName(), bratTypeName, bratTypeName, null, "triangle,5", "3,3"));
}
// Styles for the remaining relation and chain layers
for (AnnotationLayer attachingLayer : getAttachingLayers(layer, layers, aAnnotationService)) {
arcs.add(configureRelationType(layer, attachingLayer));
}
entityType.setArcs(arcs);
entityTypes.add(entityType);
}
return entityTypes;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class ImportServiceImpl method importProject.
@Override
public Project importProject(File aProjectFile, boolean aGenerateUsers) throws Exception {
Project importedProject = new Project();
ZipFile zip = new ZipFile(aProjectFile);
InputStream projectInputStream = null;
for (Enumeration<? extends ZipEntry> zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) zipEnumerate.nextElement();
if (entry.toString().replace("/", "").startsWith(ImportUtil.EXPORTED_PROJECT) && entry.toString().replace("/", "").endsWith(".json")) {
projectInputStream = zip.getInputStream(entry);
break;
}
}
// Load the project model from the JSON file
String text = IOUtils.toString(projectInputStream, "UTF-8");
de.tudarmstadt.ukp.clarin.webanno.export.model.Project importedProjectSetting = JSONUtil.getJsonConverter().getObjectMapper().readValue(text, de.tudarmstadt.ukp.clarin.webanno.export.model.Project.class);
// Import the project itself
importedProject = ImportUtil.createProject(importedProjectSetting, projectService);
// Import additional project things
projectService.onProjectImport(zip, importedProjectSetting, importedProject);
// Import missing users
if (aGenerateUsers) {
ImportUtil.createMissingUsers(importedProjectSetting, userRepository);
}
applicationEventPublisher.publishEvent(new ProjectImportEvent(this, zip, importedProjectSetting, importedProject));
// Import layers
Map<String, AnnotationFeature> featuresMap = ImportUtil.createLayer(importedProject, importedProjectSetting, userRepository, annotationService);
/*
* for (TagSet tagset : importedProjectSetting.getTagSets()) {
* ImportUtil.createTagset(importedProject, tagset, projectRepository, annotationService); }
*/
// Import source document
ImportUtil.createSourceDocument(importedProjectSetting, importedProject, documentService);
// Import Training document
if (automationService != null) {
ImportUtil.createTrainingDocument(importedProjectSetting, importedProject, automationService, featuresMap);
}
// Import source document content
ImportUtil.createSourceDocumentContent(zip, importedProject, documentService);
// Import training document content
if (automationService != null) {
ImportUtil.createTrainingDocumentContent(zip, importedProject, automationService);
}
// Import automation settings
if (automationService != null) {
ImportUtil.createMiraTemplate(importedProjectSetting, automationService, featuresMap);
}
// Import annotation document content
ImportUtil.createAnnotationDocument(importedProjectSetting, importedProject, documentService);
// Import annotation document content
ImportUtil.createAnnotationDocumentContent(zip, importedProject, documentService);
// Import curation document content
ImportUtil.createCurationDocumentContent(zip, importedProject, documentService);
return importedProject;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class ImportUtil method exportLayerDetails.
public static de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exportLayerDetails(Map<AnnotationLayer, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer> aLayerToExLayer, Map<AnnotationFeature, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> aFeatureToExFeature, AnnotationLayer aLayer, AnnotationSchemaService aAnnotationService) {
de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exLayer = new de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer();
exLayer.setAllowStacking(aLayer.isAllowStacking());
exLayer.setBuiltIn(aLayer.isBuiltIn());
exLayer.setReadonly(aLayer.isReadonly());
exLayer.setCrossSentence(aLayer.isCrossSentence());
exLayer.setDescription(aLayer.getDescription());
exLayer.setEnabled(aLayer.isEnabled());
exLayer.setLockToTokenOffset(aLayer.isLockToTokenOffset());
exLayer.setMultipleTokens(aLayer.isMultipleTokens());
exLayer.setLinkedListBehavior(aLayer.isLinkedListBehavior());
exLayer.setName(aLayer.getName());
exLayer.setProjectName(aLayer.getProject().getName());
exLayer.setType(aLayer.getType());
exLayer.setUiName(aLayer.getUiName());
if (aLayerToExLayer != null) {
aLayerToExLayer.put(aLayer, exLayer);
}
List<de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> exFeatures = new ArrayList<>();
for (AnnotationFeature feature : aAnnotationService.listAnnotationFeature(aLayer)) {
de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature exFeature = new de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature();
exFeature.setDescription(feature.getDescription());
exFeature.setEnabled(feature.isEnabled());
exFeature.setRemember(feature.isRemember());
exFeature.setRequired(feature.isRequired());
exFeature.setHideUnconstraintFeature(feature.isHideUnconstraintFeature());
exFeature.setName(feature.getName());
exFeature.setProjectName(feature.getProject().getName());
exFeature.setType(feature.getType());
exFeature.setUiName(feature.getUiName());
exFeature.setVisible(feature.isVisible());
exFeature.setMultiValueMode(feature.getMultiValueMode());
exFeature.setLinkMode(feature.getLinkMode());
exFeature.setLinkTypeName(feature.getLinkTypeName());
exFeature.setLinkTypeRoleFeatureName(feature.getLinkTypeRoleFeatureName());
exFeature.setLinkTypeTargetFeatureName(feature.getLinkTypeTargetFeatureName());
if (feature.getTagset() != null) {
TagSet tagSet = feature.getTagset();
ExportedTagSet exTagSet = new ExportedTagSet();
exTagSet.setDescription(tagSet.getDescription());
exTagSet.setLanguage(tagSet.getLanguage());
exTagSet.setName(tagSet.getName());
exTagSet.setCreateTag(tagSet.isCreateTag());
List<ExportedTag> exportedTags = new ArrayList<>();
for (Tag tag : aAnnotationService.listTags(tagSet)) {
ExportedTag exTag = new ExportedTag();
exTag.setDescription(tag.getDescription());
exTag.setName(tag.getName());
exportedTags.add(exTag);
}
exTagSet.setTags(exportedTags);
exFeature.setTagSet(exTagSet);
}
exFeatures.add(exFeature);
if (aFeatureToExFeature != null) {
aFeatureToExFeature.put(feature, exFeature);
}
}
exLayer.setFeatures(exFeatures);
return exLayer;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class ImportUtil method createMiraTemplate.
public static void createMiraTemplate(de.tudarmstadt.ukp.clarin.webanno.export.model.Project aImportedProjectSetting, AutomationService aRepository, Map<String, AnnotationFeature> aFeatureMaps) {
for (MiraTemplate exTemplate : aImportedProjectSetting.getMiraTemplates()) {
de.tudarmstadt.ukp.clarin.webanno.automation.model.MiraTemplate template = new de.tudarmstadt.ukp.clarin.webanno.automation.model.MiraTemplate();
template.setAnnotateAndRepeat(exTemplate.isAnnotateAndPredict());
template.setAutomationStarted(false);
template.setCurrentLayer(exTemplate.isCurrentLayer());
template.setResult("---");
template.setTrainFeature(aFeatureMaps.get(exTemplate.getTrainFeature().getName()));
Set<AnnotationFeature> otherFeatures = new HashSet<>();
if (exTemplate.getOtherFeatures() != null) {
for (de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature other : exTemplate.getOtherFeatures()) {
otherFeatures.add(aFeatureMaps.get(other.getName()));
}
template.setOtherFeatures(otherFeatures);
}
aRepository.createTemplate(template);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class LegacyProjectInitializer method createDepLayer.
private void createDepLayer(Project aProject, TagSet aTagset) throws IOException {
// Dependency Layer
AnnotationLayer depLayer = new AnnotationLayer(Dependency.class.getName(), "Dependency", RELATION_TYPE, aProject, true);
AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), aProject);
List<AnnotationFeature> tokenFeatures = annotationSchemaService.listAnnotationFeature(tokenLayer);
AnnotationFeature tokenPosFeature = null;
for (AnnotationFeature feature : tokenFeatures) {
if (feature.getName().equals("pos")) {
tokenPosFeature = feature;
break;
}
}
depLayer.setAttachType(tokenLayer);
depLayer.setAttachFeature(tokenPosFeature);
annotationSchemaService.createLayer(depLayer);
annotationSchemaService.createFeature(new AnnotationFeature(aProject, depLayer, "DependencyType", "Relation", CAS.TYPE_NAME_STRING, "Dependency relation", aTagset));
String[] flavors = { DependencyFlavor.BASIC, DependencyFlavor.ENHANCED };
String[] flavorDesc = { DependencyFlavor.BASIC, DependencyFlavor.ENHANCED };
TagSet flavorsTagset = annotationSchemaService.createTagSet("Dependency flavors", "Dependency flavors", "mul", flavors, flavorDesc, aProject);
annotationSchemaService.createFeature(new AnnotationFeature(aProject, depLayer, "flavor", "Flavor", CAS.TYPE_NAME_STRING, "Dependency relation", flavorsTagset));
}
Aggregations