Search in sources :

Example 41 with AnnotationLayer

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

the class NamedEntityLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    TagSet nerTagSet = JsonImportUtil.importTagSetFromJson(aProject, new ClassPathResource("/tagsets/de-ne-webanno.json").getInputStream(), annotationSchemaService);
    AnnotationLayer neLayer = new AnnotationLayer(NamedEntity.class.getName(), "Named entity", SPAN_TYPE, aProject, true);
    neLayer.setAllowStacking(true);
    neLayer.setMultipleTokens(true);
    neLayer.setLockToTokenOffset(false);
    annotationSchemaService.createLayer(neLayer);
    annotationSchemaService.createFeature(new AnnotationFeature(aProject, neLayer, "value", "value", CAS.TYPE_NAME_STRING, "Named entity type", nerTagSet));
}
Also used : NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ClassPathResource(org.springframework.core.io.ClassPathResource) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 42 with AnnotationLayer

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

the class SemPredArgLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer semArgLayer = new AnnotationLayer(SemArg.class.getName(), "SemArg", SPAN_TYPE, aProject, true);
    semArgLayer.setAllowStacking(true);
    semArgLayer.setCrossSentence(false);
    semArgLayer.setLockToTokenOffset(false);
    semArgLayer.setMultipleTokens(true);
    annotationSchemaService.createLayer(semArgLayer);
    AnnotationLayer semPredLayer = new AnnotationLayer(SemPred.class.getName(), "SemPred", SPAN_TYPE, aProject, true);
    semPredLayer.setAllowStacking(true);
    semPredLayer.setCrossSentence(false);
    semPredLayer.setLockToTokenOffset(false);
    semPredLayer.setMultipleTokens(true);
    annotationSchemaService.createFeature(new AnnotationFeature(aProject, semPredLayer, "category", "category", CAS.TYPE_NAME_STRING, "Category of the semantic predicate, e.g. the frame identifier.", null));
    AnnotationFeature semPredArgumentsFeature = new AnnotationFeature();
    semPredArgumentsFeature.setName("arguments");
    semPredArgumentsFeature.setUiName("arguments");
    semPredArgumentsFeature.setDescription("Arguments of the semantic predicate");
    semPredArgumentsFeature.setType(SemArg.class.getName());
    semPredArgumentsFeature.setProject(aProject);
    semPredArgumentsFeature.setTagset(null);
    semPredArgumentsFeature.setMode(MultiValueMode.ARRAY);
    semPredArgumentsFeature.setLinkMode(LinkMode.WITH_ROLE);
    semPredArgumentsFeature.setLinkTypeName(SemArgLink.class.getName());
    semPredArgumentsFeature.setLinkTypeRoleFeatureName("role");
    semPredArgumentsFeature.setLinkTypeTargetFeatureName("target");
    semPredArgumentsFeature.setLayer(semPredLayer);
    annotationSchemaService.createFeature(semPredArgumentsFeature);
    annotationSchemaService.createLayer(semPredLayer);
}
Also used : SemPred(de.tudarmstadt.ukp.dkpro.core.api.semantics.type.SemPred) SemArgLink(de.tudarmstadt.ukp.dkpro.core.api.semantics.type.SemArgLink) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) SemArg(de.tudarmstadt.ukp.dkpro.core.api.semantics.type.SemArg) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 43 with AnnotationLayer

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

the class SurfaceFormLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer surfaceFormLayer = new AnnotationLayer(SurfaceForm.class.getName(), "Surface form", SPAN_TYPE, aProject, true);
    surfaceFormLayer.setAllowStacking(false);
    // The surface form must be locked to tokens for CoNLL-U writer to work properly
    surfaceFormLayer.setLockToTokenOffset(false);
    surfaceFormLayer.setMultipleTokens(true);
    annotationSchemaService.createLayer(surfaceFormLayer);
    AnnotationFeature surfaceFormValueFeature = new AnnotationFeature();
    surfaceFormValueFeature.setDescription("Original surface text");
    surfaceFormValueFeature.setName("value");
    surfaceFormValueFeature.setType(CAS.TYPE_NAME_STRING);
    surfaceFormValueFeature.setProject(aProject);
    surfaceFormValueFeature.setUiName("Form");
    surfaceFormValueFeature.setLayer(surfaceFormLayer);
    annotationSchemaService.createFeature(surfaceFormValueFeature);
}
Also used : SurfaceForm(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.SurfaceForm) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 44 with AnnotationLayer

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

the class TokenLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer tokenLayer = new AnnotationLayer(Token.class.getName(), "Token", SPAN_TYPE, aProject, true);
    annotationSchemaService.createLayer(tokenLayer);
}
Also used : Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 45 with AnnotationLayer

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

the class PreferencesUtil method loadPreferences.

/**
 * Set annotation preferences of users for a given project such as window size, annotation
 * layers,... reading from the file system.
 *
 * @param aUsername
 *            The {@link User} for whom we need to read the preference (preferences are stored
 *            per user)
 * @param aRepositoryService the repository service.
 * @param aAnnotationService the annotation service.
 * @param aBModel
 *            The {@link AnnotatorState} that will be populated with preferences from the
 *            file
 * @param aMode the mode.
 * @throws BeansException hum?
 * @throws IOException hum?
 */
public static void loadPreferences(String aUsername, SettingsService aSettingsService, ProjectService aRepositoryService, AnnotationSchemaService aAnnotationService, AnnotatorState aBModel, Mode aMode) throws BeansException, IOException {
    AnnotationPreference preference = new AnnotationPreference();
    BeanWrapper wrapper = new BeanWrapperImpl(preference);
    // get annotation preference from file system
    try {
        Properties props = aRepositoryService.loadUserSettings(aUsername, aBModel.getProject());
        for (Entry<Object, Object> entry : props.entrySet()) {
            String property = entry.getKey().toString();
            int index = property.indexOf(".");
            String propertyName = property.substring(index + 1);
            String mode = property.substring(0, index);
            if (wrapper.isWritableProperty(propertyName) && mode.equals(aMode.getName())) {
                if (AnnotationPreference.class.getDeclaredField(propertyName).getGenericType() instanceof ParameterizedType) {
                    if (entry.getValue().toString().startsWith("[")) {
                        // its a list
                        List<String> value = Arrays.asList(StringUtils.replaceChars(entry.getValue().toString(), "[]", "").split(","));
                        if (!value.get(0).equals("")) {
                            wrapper.setPropertyValue(propertyName, value);
                        }
                    } else if (entry.getValue().toString().startsWith("{")) {
                        // its a map
                        String s = StringUtils.replaceChars(entry.getValue().toString(), "{}", "");
                        Map<String, String> value = Arrays.stream(s.split(",")).map(x -> x.split("=")).collect(Collectors.toMap(x -> x[0], x -> x[1]));
                        wrapper.setPropertyValue(propertyName, value);
                    }
                } else {
                    wrapper.setPropertyValue(propertyName, entry.getValue());
                }
            }
        }
        // set layers according to preferences
        List<AnnotationLayer> enabledLayers = aAnnotationService.listAnnotationLayer(aBModel.getProject()).stream().filter(// only allow enabled layers
        l -> l.isEnabled()).collect(Collectors.toList());
        List<Long> hiddenLayerIds = preference.getHiddenAnnotationLayerIds();
        enabledLayers = enabledLayers.stream().filter(l -> !hiddenLayerIds.contains(l.getId())).collect(Collectors.toList());
        aBModel.setAnnotationLayers(enabledLayers);
        // Get color preferences for each layer, init with legacy if not found
        Map<Long, ColoringStrategyType> colorPerLayer = preference.getColorPerLayer();
        for (AnnotationLayer layer : aAnnotationService.listAnnotationLayer(aBModel.getProject())) {
            if (!colorPerLayer.containsKey(layer.getId())) {
                colorPerLayer.put(layer.getId(), ColoringStrategyType.LEGACY);
            }
        }
    }// no preference found
     catch (Exception e) {
        // If no layer preferences are defined,
        // then just assume all enabled layers are preferred
        List<AnnotationLayer> enabledLayers = aAnnotationService.listAnnotationLayer(aBModel.getProject()).stream().filter(// only allow enabled layers
        l -> l.isEnabled()).collect(Collectors.toList());
        aBModel.setAnnotationLayers(enabledLayers);
        preference.setWindowSize(aSettingsService.getNumberOfSentences());
        // add default coloring strategy
        Map<Long, ColoringStrategyType> colorPerLayer = new HashMap<>();
        for (AnnotationLayer layer : aBModel.getAnnotationLayers()) {
            colorPerLayer.put(layer.getId(), ColoringStrategy.getBestInitialStrategy(aAnnotationService, layer, preference));
        }
        preference.setColorPerLayer(colorPerLayer);
    }
    aBModel.setPreferences(preference);
}
Also used : Arrays(java.util.Arrays) Properties(java.util.Properties) ProjectService(de.tudarmstadt.ukp.clarin.webanno.api.ProjectService) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) BeanWrapper(org.springframework.beans.BeanWrapper) IOException(java.io.IOException) HashMap(java.util.HashMap) BeansException(org.springframework.beans.BeansException) ColoringStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy) Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) SettingsService(de.tudarmstadt.ukp.clarin.webanno.api.SettingsService) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) List(java.util.List) ParameterizedType(java.lang.reflect.ParameterizedType) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Map(java.util.Map) Entry(java.util.Map.Entry) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) ColoringStrategyType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy.ColoringStrategyType) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Properties(java.util.Properties) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) ParameterizedType(java.lang.reflect.ParameterizedType) BeanWrapper(org.springframework.beans.BeanWrapper) List(java.util.List) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) HashMap(java.util.HashMap) Map(java.util.Map) ColoringStrategyType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy.ColoringStrategyType)

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