Search in sources :

Example 26 with FeatureStructure

use of org.apache.uima.cas.FeatureStructure in project webanno by webanno.

the class CopyAnnotationTest method copyLinkToExistingButDiffLinkTest.

@Test
public void copyLinkToExistingButDiffLinkTest() throws Exception {
    JCas mergeCAs = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
    Type type = mergeCAs.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");
    AnnotationFS mergeFs = DiffUtils.makeLinkHostMultiSPanFeatureFS(mergeCAs, 0, 0, feature, "A", DiffUtils.makeLinkFS(mergeCAs, "slot1", 0, 0));
    FeatureStructure copyFS = DiffUtils.makeLinkFS(mergeCAs, "slot2", 0, 0);
    List<FeatureStructure> linkFs = new ArrayList<>();
    linkFs.add(copyFS);
    WebAnnoCasUtil.setLinkFeatureValue(mergeFs, type.getFeatureByBaseName("links"), linkFs);
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
    DiffUtils.makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A", DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(mergeCAs));
    casByUser.put("user2", asList(jcasA));
    List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
    CasDiff2.SpanDiffAdapter adapter = new CasDiff2.SpanDiffAdapter(DiffUtils.HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends CasDiff2.DiffAdapter> diffAdapters = asList(adapter);
    CasDiff2.DiffResult diff = CasDiff2.doDiff(entryTypes, diffAdapters, CasDiff2.LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    assertEquals(0, diff.getDifferingConfigurationSets().size());
    assertEquals(2, diff.getIncompleteConfigurationSets().size());
}
Also used : CasDiff2(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) LinkedHashMap(java.util.LinkedHashMap) FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 27 with FeatureStructure

use of org.apache.uima.cas.FeatureStructure in project webanno by webanno.

the class MergeCasTest method multiLinkWithRoleTargetDifferenceTest.

@Test
public void multiLinkWithRoleTargetDifferenceTest() throws Exception {
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasB, 0, 0, DiffUtils.makeLinkFS(jcasB, "slot1", 10, 10));
    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA));
    casByUser.put("user2", asList(jcasB));
    casByUser.put(CURATION_USER, asList(jcasA));
    List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
    SpanDiffAdapter adapter = new SpanDiffAdapter(DiffUtils.HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends DiffAdapter> diffAdapters = asList(adapter);
    DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    result.print(System.out);
    JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
    Type hostType = mergeCas.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    int numHost = CasUtil.select(mergeCas.getCas(), hostType).size();
    assertEquals(1, numHost);
    for (FeatureStructure host : CasUtil.select(mergeCas.getCas(), hostType)) {
        ArrayFS linkFss = (ArrayFS) WebAnnoCasUtil.getFeatureFS(host, "links");
        assertEquals(0, linkFss.toArray().length);
    }
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.SpanDiffAdapter) JCas(org.apache.uima.jcas.JCas) LinkedHashMap(java.util.LinkedHashMap) FeatureStructure(org.apache.uima.cas.FeatureStructure) Type(org.apache.uima.cas.Type) ArrayFS(org.apache.uima.cas.ArrayFS) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) Test(org.junit.Test)

Example 28 with FeatureStructure

use of org.apache.uima.cas.FeatureStructure in project webanno by webanno.

the class MergeCasTest method multiLinkWithRoleLabelDifferenceTest.

@Test
public void multiLinkWithRoleLabelDifferenceTest() throws Exception {
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasB, 0, 0, DiffUtils.makeLinkFS(jcasB, "slot2", 0, 0));
    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA));
    casByUser.put("user2", asList(jcasB));
    casByUser.put(CURATION_USER, asList(jcasA));
    List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
    SpanDiffAdapter adapter = new SpanDiffAdapter(DiffUtils.HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends DiffAdapter> diffAdapters = asList(adapter);
    DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    result.print(System.out);
    JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
    Type hostType = mergeCas.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    int numHost = CasUtil.select(mergeCas.getCas(), hostType).size();
    assertEquals(1, numHost);
    for (FeatureStructure host : CasUtil.select(mergeCas.getCas(), hostType)) {
        ArrayFS linkFss = (ArrayFS) WebAnnoCasUtil.getFeatureFS(host, "links");
        assertEquals(0, linkFss.toArray().length);
    }
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.SpanDiffAdapter) JCas(org.apache.uima.jcas.JCas) LinkedHashMap(java.util.LinkedHashMap) FeatureStructure(org.apache.uima.cas.FeatureStructure) Type(org.apache.uima.cas.Type) ArrayFS(org.apache.uima.cas.ArrayFS) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) Test(org.junit.Test)

Example 29 with FeatureStructure

use of org.apache.uima.cas.FeatureStructure in project webanno by webanno.

the class SuggestionViewPanel method addSuggestionColor.

/**
 * For each {@link ConfigurationSet}, where there are some differences in users annotation and
 * the curation annotation.
 */
private void addSuggestionColor(Project aProject, Mode aMode, Map<String, JCas> aCasMap, Map<String, Map<VID, AnnotationState>> aSuggestionColors, Collection<ConfigurationSet> aCfgSet, boolean aI, boolean aAgree) {
    for (ConfigurationSet cs : aCfgSet) {
        boolean use = false;
        for (String u : cs.getCasGroupIds()) {
            Map<VID, AnnotationState> colors = aSuggestionColors.get(u);
            if (colors == null) {
                colors = new HashMap<>();
                aSuggestionColors.put(u, colors);
            }
            for (Configuration c : cs.getConfigurations(u)) {
                FeatureStructure fs = c.getFs(u, aCasMap);
                AnnotationLayer layer = annotationService.getLayer(fs.getType().getName(), aProject);
                TypeAdapter typeAdapter = annotationService.getAdapter(layer);
                VID vid;
                // link FS
                if (c.getPosition().getFeature() != null) {
                    int fi = 0;
                    for (AnnotationFeature f : typeAdapter.listFeatures()) {
                        if (f.getName().equals(c.getPosition().getFeature())) {
                            break;
                        }
                        fi++;
                    }
                    vid = new VID(WebAnnoCasUtil.getAddr(fs), fi, c.getAID(u).index);
                } else {
                    vid = new VID(WebAnnoCasUtil.getAddr(fs));
                }
                if (aAgree) {
                    colors.put(vid, AnnotationState.AGREE);
                    continue;
                }
                // automation and correction projects
                if (!aMode.equals(Mode.CURATION) && !aAgree) {
                    if (cs.getCasGroupIds().size() == 2) {
                        colors.put(vid, AnnotationState.DO_NOT_USE);
                    } else {
                        colors.put(vid, AnnotationState.DISAGREE);
                    }
                    continue;
                }
                // this set agree with the curation annotation
                if (c.getCasGroupIds().contains(CURATION_USER)) {
                    use = true;
                } else {
                    use = false;
                }
                // this curation view
                if (u.equals(CURATION_USER)) {
                    continue;
                }
                if (aAgree) {
                    colors.put(vid, AnnotationState.AGREE);
                } else if (use) {
                    colors.put(vid, AnnotationState.USE);
                } else if (aI) {
                    colors.put(vid, AnnotationState.DISAGREE);
                } else if (!cs.getCasGroupIds().contains(CURATION_USER)) {
                    colors.put(vid, AnnotationState.DISAGREE);
                } else {
                    colors.put(vid, AnnotationState.DO_NOT_USE);
                }
            }
        }
    }
}
Also used : Configuration(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.Configuration) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) FeatureStructure(org.apache.uima.cas.FeatureStructure) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationState(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.AnnotationState) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 30 with FeatureStructure

use of org.apache.uima.cas.FeatureStructure in project lucene-solr by apache.

the class UIMAToSolrMapper method map.

/**
   * map features of a certain UIMA type to corresponding Solr fields based on the mapping
   *
   * @param typeName             name of UIMA type to map
   */
void map(String typeName, Map<String, MapField> featureFieldsmapping) throws FieldMappingException {
    try {
        Type type = cas.getTypeSystem().getType(typeName);
        for (FSIterator<FeatureStructure> iterator = cas.getFSIndexRepository().getAllIndexedFS(type); iterator.hasNext(); ) {
            FeatureStructure fs = iterator.next();
            for (String featureName : featureFieldsmapping.keySet()) {
                MapField mapField = featureFieldsmapping.get(featureName);
                String fieldNameFeature = mapField.getFieldNameFeature();
                String fieldNameFeatureValue = fieldNameFeature == null ? null : fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature));
                String fieldName = mapField.getFieldName(fieldNameFeatureValue);
                if (log.isInfoEnabled()) {
                    log.info("mapping {}@{} to {}", new Object[] { typeName, featureName, fieldName });
                }
                String featureValue;
                if (fs instanceof Annotation && "coveredText".equals(featureName)) {
                    featureValue = ((Annotation) fs).getCoveredText();
                } else {
                    featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName));
                }
                if (log.isDebugEnabled()) {
                    log.debug("writing {} in {}", new Object[] { featureValue, fieldName });
                }
                document.addField(fieldName, featureValue);
            }
        }
    } catch (Exception e) {
        throw new FieldMappingException(e);
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) Type(org.apache.uima.cas.Type) Annotation(org.apache.uima.jcas.tcas.Annotation) MapField(org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField)

Aggregations

FeatureStructure (org.apache.uima.cas.FeatureStructure)60 Type (org.apache.uima.cas.Type)38 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)37 ArrayList (java.util.ArrayList)29 JCas (org.apache.uima.jcas.JCas)20 Feature (org.apache.uima.cas.Feature)17 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)16 CAS (org.apache.uima.cas.CAS)16 Test (org.junit.Test)16 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)13 List (java.util.List)12 ArrayFS (org.apache.uima.cas.ArrayFS)8 Arrays.asList (java.util.Arrays.asList)6 LinkedHashMap (java.util.LinkedHashMap)6 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)6 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)5 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)4 LogMessage (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage)4 TsvColumn (de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvColumn)4 Map (java.util.Map)4