Search in sources :

Example 1 with ConfigurationSet

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet in project webanno by webanno.

the class AgreementUtils method configurationSetsWithItemsToCsv.

private static void configurationSetsWithItemsToCsv(CSVPrinter aOut, AgreementResult aAgreement, List<ConfigurationSet> aSets) throws IOException {
    List<String> headers = new ArrayList<>(asList("Type", "Collection", "Document", "Layer", "Feature", "Position"));
    headers.addAll(aAgreement.getCasGroupIds());
    aOut.printRecord(headers);
    int i = 0;
    for (ICodingAnnotationItem item : aAgreement.getStudy().getItems()) {
        Position pos = aSets.get(i).getPosition();
        List<String> values = new ArrayList<>();
        values.add(pos.getClass().getSimpleName());
        values.add(pos.getCollectionId());
        values.add(pos.getDocumentId());
        values.add(pos.getType());
        values.add(aAgreement.getFeature());
        values.add(aSets.get(i).getPosition().toMinimalString());
        for (IAnnotationUnit unit : item.getUnits()) {
            values.add(String.valueOf(unit.getCategory()));
        }
        aOut.printRecord(values);
        i++;
    }
}
Also used : ArcPosition(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ArcPosition) Position(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.Position) IAnnotationUnit(de.tudarmstadt.ukp.dkpro.statistics.agreement.IAnnotationUnit) ArrayList(java.util.ArrayList) ICodingAnnotationItem(de.tudarmstadt.ukp.dkpro.statistics.agreement.coding.ICodingAnnotationItem)

Example 2 with ConfigurationSet

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet in project webanno by webanno.

the class AgreementUtils method dumpAgreementConfigurationSets.

private static void dumpAgreementConfigurationSets(PrintStream aOut, AgreementResult aAgreement, List<ConfigurationSet> aSets) {
    for (ConfigurationSet cfgSet : aSets) {
        StringBuilder sb = new StringBuilder();
        sb.append(cfgSet.getPosition());
        for (Configuration cfg : cfgSet.getConfigurations()) {
            if (sb.length() > 0) {
                sb.append(" \t");
            }
            sb.append(cfg.toString());
        }
        aOut.println(sb);
    }
}
Also used : ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet) Configuration(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.Configuration)

Example 3 with ConfigurationSet

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet 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 4 with ConfigurationSet

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet in project webanno by webanno.

the class MergeCas method reMergeCas.

/**
 * Using {@code DiffResult}, determine the annotations to be deleted from the randomly generated
 * MergeCase. The initial Merge CAs is stored under a name {@code CurationPanel#CURATION_USER}.
 * <p>
 * Any similar annotations stacked in a {@code CasDiff2.Position} will be assumed a difference
 * <p>
 * Any two annotation with different value will be assumed a difference
 * <p>
 * Any non stacked empty/null annotations are assumed agreement
 * <p>
 * Any non stacked annotations with similar values for each of the features are assumed
 * agreement
 * <p>
 * Any two link mode / slotable annotations which agree on the base features are assumed
 * agreement
 *
 * @param aDiff
 *            the {@code CasDiff2.DiffResult}
 * @param aJCases
 *            a map of{@code JCas}s for each users and the random merge
 * @return the actual merge {@code JCas}
 */
public static JCas reMergeCas(DiffResult aDiff, Map<String, JCas> aJCases) {
    Set<FeatureStructure> slotFeaturesToReset = new HashSet<>();
    Set<FeatureStructure> annotationsToDelete = new HashSet<>();
    Set<String> users = aJCases.keySet();
    for (Position position : aDiff.getPositions()) {
        Map<String, List<FeatureStructure>> annosPerUser = new HashMap<>();
        ConfigurationSet cfgs = aDiff.getConfigurtionSet(position);
        if (cfgs.getConfigurations(WebAnnoConst.CURATION_USER).isEmpty()) {
            // annotations
            continue;
        }
        AnnotationFS mergeAnno = (AnnotationFS) cfgs.getConfigurations(WebAnnoConst.CURATION_USER).get(0).getFs(WebAnnoConst.CURATION_USER, aJCases);
        // Get Annotations per user in this position
        getAllAnnosOnPosition(aJCases, annosPerUser, users, mergeAnno);
        for (FeatureStructure mergeFs : annosPerUser.get(WebAnnoConst.CURATION_USER)) {
            // incomplete annotations
            if (aJCases.size() != annosPerUser.size()) {
                annotationsToDelete.add(mergeFs);
            } else // agreed and not stacked
            if (isAgree(mergeFs, annosPerUser)) {
                Type t = mergeFs.getType();
                Feature sourceFeat = t.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
                Feature targetFeat = t.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
                // Is this a relation?
                if (sourceFeat != null && targetFeat != null) {
                    AnnotationFS source = (AnnotationFS) mergeFs.getFeatureValue(sourceFeat);
                    AnnotationFS target = (AnnotationFS) mergeFs.getFeatureValue(targetFeat);
                    // all span anno on this source positions
                    Map<String, List<FeatureStructure>> sourceAnnosPerUser = new HashMap<>();
                    // all span anno on this target positions
                    Map<String, List<FeatureStructure>> targetAnnosPerUser = new HashMap<>();
                    getAllAnnosOnPosition(aJCases, sourceAnnosPerUser, users, source);
                    getAllAnnosOnPosition(aJCases, targetAnnosPerUser, users, target);
                    if (isAgree(source, sourceAnnosPerUser) && isAgree(target, targetAnnosPerUser)) {
                        slotFeaturesToReset.add(mergeFs);
                    } else {
                        annotationsToDelete.add(mergeFs);
                    }
                } else {
                    slotFeaturesToReset.add(mergeFs);
                }
            } else // disagree or stacked annotations
            {
                annotationsToDelete.add(mergeFs);
            }
        // remove dangling rels
        // setDanglingRelToDel(aJCases.get(CurationPanel.CURATION_USER),
        // mergeFs, annotationsToDelete);
        }
    }
    // remove annotations that do not agree or are a stacked ones
    for (FeatureStructure fs : annotationsToDelete) {
        if (!slotFeaturesToReset.contains(fs)) {
            JCas mergeCas = aJCases.get(WebAnnoConst.CURATION_USER);
            // Check if this difference is on POS, STEM and LEMMA (so remove from the token too)
            Type type = fs.getType();
            int fsBegin = ((AnnotationFS) fs).getBegin();
            int fsEnd = ((AnnotationFS) fs).getEnd();
            if (type.getName().equals(POS.class.getName())) {
                Token t = JCasUtil.selectCovered(mergeCas, Token.class, fsBegin, fsEnd).get(0);
                t.setPos(null);
            }
            if (type.getName().equals(Stem.class.getName())) {
                Token t = JCasUtil.selectCovered(mergeCas, Token.class, fsBegin, fsEnd).get(0);
                t.setStem(null);
            }
            if (type.getName().equals(Lemma.class.getName())) {
                Token t = JCasUtil.selectCovered(mergeCas, Token.class, fsBegin, fsEnd).get(0);
                t.setLemma(null);
            }
            if (type.getName().equals(MorphologicalFeatures.class.getName())) {
                Token t = JCasUtil.selectCovered(mergeCas, Token.class, fsBegin, fsEnd).get(0);
                t.setMorph(null);
            }
            mergeCas.removeFsFromIndexes(fs);
        }
    }
    // if slot bearing annotation, clean
    for (FeatureStructure baseFs : slotFeaturesToReset) {
        for (Feature roleFeature : baseFs.getType().getFeatures()) {
            if (isLinkMode(baseFs, roleFeature)) {
                // FeatureStructure roleFs = baseFs.getFeatureValue(f);
                ArrayFS roleFss = (ArrayFS) WebAnnoCasUtil.getFeatureFS(baseFs, roleFeature.getShortName());
                if (roleFss == null) {
                    continue;
                }
                Map<String, ArrayFS> roleAnnosPerUser = new HashMap<>();
                setAllRoleAnnosOnPosition(aJCases, roleAnnosPerUser, users, baseFs, roleFeature);
                List<FeatureStructure> linkFSes = new LinkedList<>(Arrays.asList(roleFss.toArray()));
                for (FeatureStructure roleFs : roleFss.toArray()) {
                    if (isRoleAgree(roleFs, roleAnnosPerUser)) {
                        for (Feature targetFeature : roleFs.getType().getFeatures()) {
                            if (isBasicFeature(targetFeature)) {
                                continue;
                            }
                            if (!targetFeature.getShortName().equals("target")) {
                                continue;
                            }
                            AnnotationFS targetFs = (AnnotationFS) roleFs.getFeatureValue(targetFeature);
                            if (targetFs == null) {
                                continue;
                            }
                            Map<String, List<FeatureStructure>> targetAnnosPerUser = new HashMap<>();
                            getAllAnnosOnPosition(aJCases, targetAnnosPerUser, users, targetFs);
                            // do not agree on targets
                            if (!isAgree(targetFs, targetAnnosPerUser)) {
                                linkFSes.remove(roleFs);
                            }
                        }
                    } else // do not agree on some role features
                    {
                        linkFSes.remove(roleFs);
                    }
                }
                ArrayFS array = baseFs.getCAS().createArrayFS(linkFSes.size());
                array.copyFromArray(linkFSes.toArray(new FeatureStructure[linkFSes.size()]), 0, 0, linkFSes.size());
                baseFs.setFeatureValue(roleFeature, array);
            }
        }
    }
    return aJCases.get(WebAnnoConst.CURATION_USER);
}
Also used : HashMap(java.util.HashMap) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Feature(org.apache.uima.cas.Feature) WebAnnoCasUtil.setFeature(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Stem(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Stem) FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Lemma(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma) LinkedList(java.util.LinkedList) List(java.util.List) HashSet(java.util.HashSet) MorphologicalFeatures(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.morph.MorphologicalFeatures) Position(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.Position) LinkedList(java.util.LinkedList) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet) Type(org.apache.uima.cas.Type) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) ArrayFS(org.apache.uima.cas.ArrayFS) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ConfigurationSet

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet in project webanno by webanno.

the class SuggestionViewPanel method calcColors.

private Map<String, Map<VID, AnnotationState>> calcColors(AnnotatorState state, SourceListView aCurationSegment, JCas annotatorCas, Map<String, JCas> jCases) {
    // get differing feature structures
    List<Type> entryTypes = SuggestionBuilder.getEntryTypes(annotatorCas, state.getAnnotationLayers(), annotationService);
    Map<String, Map<VID, AnnotationState>> annoStates = new HashMap<>();
    DiffResult diff;
    if (state.getMode().equals(Mode.CURATION)) {
        diff = CasDiff2.doDiffSingle(annotationService, state.getProject(), entryTypes, LinkCompareBehavior.LINK_ROLE_AS_LABEL, jCases, aCurationSegment.getCurationBegin(), aCurationSegment.getCurationEnd());
    } else {
        diff = CasDiff2.doDiffSingle(annotationService, state.getProject(), entryTypes, LinkCompareBehavior.LINK_ROLE_AS_LABEL, jCases, aCurationSegment.getBegin(), aCurationSegment.getEnd());
    }
    Collection<ConfigurationSet> d = diff.getDifferingConfigurationSets().values();
    Collection<ConfigurationSet> i = diff.getIncompleteConfigurationSets().values();
    for (ConfigurationSet cfgSet : d) {
        if (i.contains(cfgSet)) {
            i.remove(cfgSet);
        }
    }
    addSuggestionColor(state.getProject(), state.getMode(), jCases, annoStates, d, false, false);
    addSuggestionColor(state.getProject(), state.getMode(), jCases, annoStates, i, true, false);
    List<ConfigurationSet> all = new ArrayList<>();
    all.addAll(diff.getConfigurationSets());
    all.removeAll(d);
    all.removeAll(i);
    addSuggestionColor(state.getProject(), state.getMode(), jCases, annoStates, all, false, true);
    return annoStates;
}
Also used : ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet) Type(org.apache.uima.cas.Type) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ConfigurationSet (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet)6 Configuration (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.Configuration)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult)3 Position (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.Position)3 HashMap (java.util.HashMap)3 FeatureStructure (org.apache.uima.cas.FeatureStructure)3 Type (org.apache.uima.cas.Type)3 JCas (org.apache.uima.jcas.JCas)3 ArcPosition (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ArcPosition)2 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)2 IAnnotationUnit (de.tudarmstadt.ukp.dkpro.statistics.agreement.IAnnotationUnit)2 ICodingAnnotationItem (de.tudarmstadt.ukp.dkpro.statistics.agreement.coding.ICodingAnnotationItem)2 List (java.util.List)2 ArrayFS (org.apache.uima.cas.ArrayFS)2 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)2 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)1 WebAnnoCasUtil.getFeature (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getFeature)1