de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS Java Examples

The following examples show how to use de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CasMergeTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void simpleCopyToSameExistingAnnoTest()
    throws Exception
{
    CAS jcas = createJCas().getCas();
    Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
    AnnotationFS clickedFs = createPOSAnno(jcas, "NN", 0, 0);

    CAS mergeCas = createJCas().getCas();
    AnnotationFS existingFs = mergeCas.createAnnotation(type, 0, 0);
    Feature posValue = type.getFeatureByBaseName("PosValue");
    existingFs.setStringValue(posValue, "NN");
    mergeCas.addFsToIndexes(existingFs);

    Assertions.assertThatExceptionOfType(AnnotationException.class)
            .isThrownBy(() -> sut.mergeSpanAnnotation(null, null, posLayer, mergeCas, 
                    clickedFs, false))
            .withMessageContaining("annotation already exists");
}
 
Example #2
Source File: LegacyProjectInitializer.java    From webanno with Apache License 2.0 6 votes vote down vote up
private void createPOSLayer(Project aProject, TagSet aPosTagset)
    throws IOException
{
    AnnotationLayer tokenLayer = annotationSchemaService.findLayer(aProject,
            Token.class.getName());
    
    AnnotationLayer posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE,
            aProject, true, SINGLE_TOKEN, NO_OVERLAP);
    
    AnnotationFeature tokenPosFeature = new AnnotationFeature(aProject, tokenLayer, "pos",
            "pos", POS.class.getName());
    annotationSchemaService.createFeature(tokenPosFeature);
    
    posLayer.setAttachType(tokenLayer);
    posLayer.setAttachFeature(tokenPosFeature);
    annotationSchemaService.createLayer(posLayer);

    annotationSchemaService.createFeature(new AnnotationFeature(aProject, posLayer, "PosValue",
            "PosValue", CAS.TYPE_NAME_STRING, "Part-of-speech tag", aPosTagset));
}
 
Example #3
Source File: CasDiffTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
    public void singleNoDifferencesTest()
        throws Exception
    {
        Map<String, List<CAS>> casByUser = load(
                "casdiff/singleSpanNoDifference/data.conll",
                "casdiff/singleSpanNoDifference/data.conll");

        List<? extends DiffAdapter> diffAdapters = asList(new SpanDiffAdapter(POS.class.getName(),
                "PosValue"));

        CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
        DiffResult result = diff.toResult();

        // result.print(System.out);
        
        assertEquals(1, result.size());
        assertEquals(0, result.getDifferingConfigurationSets().size());
        assertEquals(0, result.getIncompleteConfigurationSets().size());
        
        // Todo: Agreement has moved to separate project - should create agreement test there
//        CodingAgreementResult agreement = getCohenKappaAgreement(diff, entryTypes.get(0),
//                "PosValue", casByUser);
//        assertEquals(NaN, agreement.getAgreement(), 0.000001d);
//        assertEquals(0, agreement.getIncompleteSetsByPosition().size());
    }
 
Example #4
Source File: CasDiffTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
    public void spanLabelLabelTest()
        throws Exception
    {
        Map<String, List<CAS>> casByUser = load(
                "casdiff/spanLabel/user1.conll",
                "casdiff/spanLabel/user2.conll");

        List<? extends DiffAdapter> diffAdapters = asList(new SpanDiffAdapter(POS.class.getName(),
                "PosValue"));

        CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
        DiffResult result = diff.toResult();
        
        // result.print(System.out);
        
        assertEquals(26, result.size());
        assertEquals(1, result.getDifferingConfigurationSets().size());
        assertEquals(0, result.getIncompleteConfigurationSets().size());
        
        // Todo: Agreement has moved to separate project - should create agreement test there
//        CodingAgreementResult agreement = getCohenKappaAgreement(diff, entryTypes.get(0),
//                "PosValue", casByUser);
//        assertEquals(0.958730d, agreement.getAgreement(), 0.000001d);
//        assertEquals(0, agreement.getIncompleteSetsByPosition().size());
    }
 
Example #5
Source File: DL4JSequenceRecommenderTest.java    From inception with Apache License 2.0 6 votes vote down vote up
@Test
public void thatPosPredictionWorks() throws Exception
{
    DL4JSequenceRecommender sut = new DL4JSequenceRecommender(buildPosRecommender(), traits,
            cache);
    JCas cas = loadPosDevelopmentData();
    
    sut.train(context, asList(cas.getCas()));

    addScoreFeature(cas.getCas(), POS.class, "PosValue");
    sut.predict(context, cas.getCas());

    List<POS> predictions = getPredictions(cas.getCas(), POS.class);
    assertThat(predictions).as("Predictions have been written to CAS")
        .isNotEmpty();
    
    // check how many labels are not padding labels
    long numWithLabel = predictions.stream()
            .filter(p -> !p.getPosValue().equals(DL4JSequenceRecommender.NO_LABEL)).count();
    System.out.printf("Predicted %d labels not no_label out of %d.%n", numWithLabel,
            predictions.size());
    
    assertThat(predictions).as("There are predictions other than *No_Label*")
        .anyMatch(l -> !l.getPosValue().equals(DL4JSequenceRecommender.NO_LABEL));
}
 
Example #6
Source File: LappsGridRecommenderConformityTest.java    From inception with Apache License 2.0 6 votes vote down vote up
@Test
@Parameters(method = "getPosServices")
public void testPosConformity(LappsGridService aService) throws Exception
{
    CAS cas = loadData();
    
    predict(aService.getUrl(), cas);

    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(JCasUtil.select(cas.getJCas(), Token.class))
            .as("Prediction should contain Tokens")
            .isNotEmpty();
    softly.assertThat(JCasUtil.select(cas.getJCas(), POS.class))
            .as("Prediction should contain POS tags")
            .isNotEmpty();

    softly.assertAll();
}
 
Example #7
Source File: CasMergeTest.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Test
public void simpleCopyToDiffExistingAnnoWithNoStackingTest()
    throws Exception
{
    CAS jcas = createJCas().getCas();
    Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
    AnnotationFS clickedFs = createPOSAnno(jcas, "NN", 0, 0);

    CAS mergeCAs = createJCas().getCas();
    AnnotationFS existingFs = mergeCAs.createAnnotation(type, 0, 0);
    Feature posValue = type.getFeatureByBaseName("PosValue");
    existingFs.setStringValue(posValue, "NE");
    mergeCAs.addFsToIndexes(existingFs);

    sut.mergeSpanAnnotation(null, null, posLayer, mergeCAs, clickedFs, false);

    assertEquals(1, CasUtil.selectCovered(mergeCAs, type, 0, 0).size());
}
 
Example #8
Source File: OpenNlpPosRecommenderTest.java    From inception with Apache License 2.0 6 votes vote down vote up
@Test
public void thatPredictionWorks() throws Exception
{
    OpenNlpPosRecommender sut = new OpenNlpPosRecommender(recommender, traits);
    List<CAS> casList = loadDevelopmentData();
    
    CAS cas = casList.get(0);
    try (CasStorageSession session = CasStorageSession.open()) {
        session.add("testCas", EXCLUSIVE_WRITE_ACCESS, cas);
        RecommenderTestHelper.addScoreFeature(cas, POS.class, "PosValue");
    }

    sut.train(context, asList(cas));

    sut.predict(context, cas);

    List<POS> predictions = RecommenderTestHelper.getPredictions(cas, POS.class);

    assertThat(predictions).as("Predictions have been written to CAS")
        .isNotEmpty();
}
 
Example #9
Source File: WeblichtRecommenderFactoryImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
@Override
public boolean accepts(AnnotationLayer aLayer, AnnotationFeature aFeature)
{
    if (Lemma.class.getName().equals(aLayer.getName())) {
        if ("value".equals(aFeature.getName())) {
            return true;
        }
    }

    if (POS.class.getName().equals(aLayer.getName())) {
        if ("PosValue".equals(aFeature.getName())) {
            return true;
        }
        if ("coarseValue".equals(aFeature.getName())) {
            return true;
        }
    }

    if (NamedEntity.class.getName().equals(aLayer.getName())) {
        if ("value".equals(aFeature.getName())) {
            return true;
        }
    }
    
    return false;
}
 
Example #10
Source File: Tcf2DKPro.java    From inception with Apache License 2.0 6 votes vote down vote up
public void convertPos(JCas aJCas, TextCorpus aCorpusData, Map<String, Token> aTokens)
{
    if (aCorpusData.getPosTagsLayer() == null) {
        return;
    }
    for (int i = 0; i < aCorpusData.getPosTagsLayer().size(); i++) {
        eu.clarin.weblicht.wlfxb.tc.api.Token[] posTokens = aCorpusData.getPosTagsLayer()
                .getTokens(aCorpusData.getPosTagsLayer().getTag(i));
        String value = aCorpusData.getPosTagsLayer().getTag(i).getString();

        POS outPos = new POS(aJCas);

        outPos.setBegin(aTokens.get(posTokens[0].getID()).getBegin());
        outPos.setEnd(aTokens.get(posTokens[0].getID()).getEnd());
        outPos.setPosValue(value);
        POSUtils.assignCoarseValue(outPos);
        outPos.addToIndexes();

        // Set the POS to the token
        aTokens.get(posTokens[0].getID()).setPos(outPos);
    }
}
 
Example #11
Source File: RelationAdapterTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void thatRelationCrossSentenceBehaviorOnValidateGeneratesErrors() throws Exception
{
    TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class);
    builder.buildTokens(jcas, "This is a test .\nThis is sentence two .");

    for (Token t : select(jcas, Token.class)) {
        POS pos = new POS(jcas, t.getBegin(), t.getEnd());
        t.setPos(pos);
        pos.addToIndexes();
    }

    RelationAdapter sut = new RelationAdapter(layerSupportRegistry, featureSupportRegistry,
        null, depLayer, FEAT_REL_TARGET, FEAT_REL_SOURCE,
        () -> asList(dependencyLayerGovernor, dependencyLayerDependent), behaviors);

    List<POS> posAnnotations = new ArrayList<>(select(jcas, POS.class));

    POS source = posAnnotations.get(0);
    POS target = posAnnotations.get(posAnnotations.size() - 1);

    depLayer.setCrossSentence(true);
    sut.add(document, username, source, target, jcas.getCas());
    
    depLayer.setCrossSentence(false);
    assertThat(sut.validate(jcas.getCas()))
            .extracting(Pair::getLeft)
            .usingElementComparatorIgnoringFields("source", "message")
            .containsExactly(LogMessage.error(null, ""));
}
 
Example #12
Source File: CasMergeTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * If one annotator has provided an annotation at a given position and the other annotator did
 * not (i.e. the annotations are incomplete), then this should be detected as a disagreement. 
 */
@Test
public void thatIncompleteAnnotationIsNotMerged()
    throws Exception
{
    JCas user1 = JCasFactory.createText("word");
    token(user1, 0, 4, "X");
    
    JCas user2 = JCasFactory.createText("word");
    token(user2, 0, 4, null);
    
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(user1.getCas()));
    casByUser.put("user2", asList(user2.getCas()));
    
    JCas curatorCas = createText(casByUser.values().stream()
            .flatMap(Collection::stream).findFirst().get().getDocumentText());
    
    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser)
            .toResult();

    sut.reMergeCas(result, document, null, curatorCas.getCas(), getSingleCasByUser(casByUser));

    assertThat(result.getDifferingConfigurationSets()).isEmpty();
    assertThat(result.getIncompleteConfigurationSets().values())
            .extracting(set -> set.getPosition())
            .usingFieldByFieldElementComparator()
            .containsExactly(new SpanPosition(null, null, 0, POS.class.getName(), 0, 4, "word",
                    null, null, -1, -1, null, null));
    
    assertThat(select(curatorCas, POS.class)).isEmpty();
}
 
Example #13
Source File: RelationAdapterTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void thatCreatingRelationWorks() throws Exception
{
    TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class);
    builder.buildTokens(jcas, "This is a test .\nThis is sentence two .");

    for (Token t : select(jcas, Token.class)) {
        POS pos = new POS(jcas, t.getBegin(), t.getEnd());
        t.setPos(pos);
        pos.addToIndexes();
    }

    RelationAdapter sut = new RelationAdapter(layerSupportRegistry, featureSupportRegistry,
        null, depLayer, FEAT_REL_TARGET, FEAT_REL_SOURCE,
        () -> asList(dependencyLayerGovernor, dependencyLayerDependent), behaviors);

    List<POS> posAnnotations = new ArrayList<>(select(jcas, POS.class));
    List<Token> tokens = new ArrayList<>(select(jcas, Token.class));

    POS source = posAnnotations.get(0);
    POS target = posAnnotations.get(1);

    AnnotationFS dep1 = sut.add(document, username, source, target, jcas.getCas());
    
    assertThat(FSUtil.getFeature(dep1, FEAT_REL_SOURCE, Token.class)).isEqualTo(tokens.get(0));
    assertThat(FSUtil.getFeature(dep1, FEAT_REL_TARGET, Token.class)).isEqualTo(tokens.get(1));
}
 
Example #14
Source File: SymbolicRulesTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleSymbolicRules()
    throws Exception
{
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream(
            "src/test/resources/rules/symbolic1.rules"));
    Parse p = parser.Parse();

    ParsedConstraints constraints = p.accept(new ParserVisitor());

    JCas jcas = JCasFactory.createJCas();

    CollectionReader reader = createReader(Conll2006Reader.class,
            Conll2006Reader.PARAM_SOURCE_LOCATION, "src/test/resources/text/1.conll");
    
    reader.getNext(jcas.getCas());

    POS pos = new POS(jcas, 8, 9);
    pos.setPosValue("pronoun");
    pos.addToIndexes();
    
    Evaluator constraintsEvaluator = new ValuesGenerator();

    Lemma lemma = select(jcas, Lemma.class).iterator().next();
    
    List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(lemma,
            "value", constraints);

    List<PossibleValue> expectedOutput = new ArrayList<>();
    expectedOutput.add(new PossibleValue("good", true));

    assertEquals(expectedOutput, possibleValues);
}
 
Example #15
Source File: SymbolicRulesTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleSymbolicRules2()
    throws Exception
{
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream(
            "src/test/resources/rules/symbolic2.rules"));
    Parse p = parser.Parse();

    ParsedConstraints constraints = p.accept(new ParserVisitor());

    JCas jcas = JCasFactory.createJCas();

    CollectionReader reader = createReader(Conll2006Reader.class,
            Conll2006Reader.PARAM_SOURCE_LOCATION, "src/test/resources/text/1.conll");
    
    reader.getNext(jcas.getCas());

    POS pos = new POS(jcas, 8, 9);
    pos.setPosValue("pronoun");
    pos.addToIndexes();
    
    Evaluator constraintsEvaluator = new ValuesGenerator();

    Lemma lemma = select(jcas, Lemma.class).iterator().next();
    
    List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(lemma,
            "value", constraints);

    List<PossibleValue> expectedOutput = new ArrayList<>();
    expectedOutput.add(new PossibleValue("good", true));

    assertEquals(expectedOutput, possibleValues);
}
 
Example #16
Source File: RelationAdapterTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void thatRelationCrossSentenceBehaviorOnCreateThrowsException() throws Exception
{
    depLayer.setCrossSentence(false);
    
    TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class);
    builder.buildTokens(jcas, "This is a test .\nThis is sentence two .");

    for (Token t : select(jcas, Token.class)) {
        POS pos = new POS(jcas, t.getBegin(), t.getEnd());
        t.setPos(pos);
        pos.addToIndexes();
    }

    RelationAdapter sut = new RelationAdapter(layerSupportRegistry, featureSupportRegistry,
        null, depLayer, FEAT_REL_TARGET, FEAT_REL_SOURCE,
        () -> asList(dependencyLayerGovernor, dependencyLayerDependent), behaviors);

    List<POS> posAnnotations = new ArrayList<>(select(jcas, POS.class));

    POS source = posAnnotations.get(0);
    POS target = posAnnotations.get(posAnnotations.size() - 1);

    assertThatExceptionOfType(MultipleSentenceCoveredException.class)
            .isThrownBy(() -> sut.add(document, username, source, target, jcas.getCas()))
            .withMessageContaining("multiple sentences");
}
 
Example #17
Source File: RelationAdapterTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void thatRelationAttachmentBehaviorOnCreateWorks() throws Exception
{
    TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class);
    builder.buildTokens(jcas, "This is a test .");

    for (Token t : select(jcas, Token.class)) {
        POS pos = new POS(jcas, t.getBegin(), t.getEnd());
        t.setPos(pos);
        pos.addToIndexes();
    }

    RelationAdapter sut = new RelationAdapter(layerSupportRegistry, featureSupportRegistry,
        null, depLayer, FEAT_REL_TARGET, FEAT_REL_SOURCE,
        () -> asList(dependencyLayerGovernor, dependencyLayerDependent), behaviors);

    List<POS> posAnnotations = new ArrayList<>(select(jcas, POS.class));
    List<Token> tokens = new ArrayList<>(select(jcas, Token.class));

    POS source = posAnnotations.get(0);
    POS target = posAnnotations.get(1);

    AnnotationFS dep = sut.add(document, username, source, target, jcas.getCas());

    assertThat(FSUtil.getFeature(dep, FEAT_REL_SOURCE, Token.class)).isEqualTo(tokens.get(0));
    assertThat(FSUtil.getFeature(dep, FEAT_REL_TARGET, Token.class)).isEqualTo(tokens.get(1));
}
 
Example #18
Source File: TeiReaderTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
 @Ignore("No TEI yet to opensource ")
public void testTeiReader()
    throws Exception
{
    CollectionReaderDescription reader = createReaderDescription(TeiReader.class,
            TeiReader.PARAM_LANGUAGE, "en", TeiReader.PARAM_SOURCE_LOCATION,
            "classpath:/local/", TeiReader.PARAM_PATTERNS, new String[] { "[+]*.xml" });

    String firstSentence = "70 I DAG.";

    for (JCas jcas : new JCasIterable(reader)) {
        DocumentMetaData meta = DocumentMetaData.get(jcas);
        String text = jcas.getDocumentText();
        System.out.printf("%s - %d%n", meta.getDocumentId(), text.length());
        System.out.println(jcas.getDocumentLanguage());

        assertEquals(2235, JCasUtil.select(jcas, Token.class).size());
        assertEquals(745, JCasUtil.select(jcas, POS.class).size());
        assertEquals(745, JCasUtil.select(jcas, Lemma.class).size());
        assertEquals(0, JCasUtil.select(jcas, NamedEntity.class).size());
        assertEquals(30, JCasUtil.select(jcas, Sentence.class).size());

        assertEquals(firstSentence, JCasUtil.select(jcas, Sentence.class).iterator().next()
                .getCoveredText());
    }

}
 
Example #19
Source File: RelationRendererTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void thatRelationCrossSentenceBehaviorOnRenderGeneratesErrors() throws Exception
{
    TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class);
    builder.buildTokens(jcas, "This is a test .\nThis is sentence two .");

    for (Token t : select(jcas, Token.class)) {
        POS pos = new POS(jcas, t.getBegin(), t.getEnd());
        t.setPos(pos);
        pos.addToIndexes();
    }

    RelationAdapter adapter = new RelationAdapter(layerSupportRegistry, featureSupportRegistry,
        null, depLayer, FEAT_REL_TARGET, FEAT_REL_SOURCE,
        () -> asList(dependencyLayerGovernor, dependencyLayerDependent), behaviors);

    List<POS> posAnnotations = new ArrayList<>(select(jcas, POS.class));

    POS source = posAnnotations.get(0);
    POS target = posAnnotations.get(posAnnotations.size() - 1);

    depLayer.setCrossSentence(true);
    AnnotationFS dep = adapter.add(document, username, source, target, jcas.getCas());
    
    depLayer.setCrossSentence(false);
    RelationRenderer sut = new RelationRenderer(adapter, layerSupportRegistry,
            featureSupportRegistry, asList(new RelationCrossSentenceBehavior()));
    
    VDocument vdoc = new VDocument();
    sut.render(jcas.getCas(), asList(), vdoc, 0, jcas.getDocumentText().length());
    
    assertThat(vdoc.comments())
            .usingFieldByFieldElementComparator()
            .contains(new VComment(dep, ERROR, 
                    "Crossing sentence boundaries is not permitted."));
}
 
Example #20
Source File: CasDiffTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
    public void noDifferencesPosDependencyTest()
        throws Exception
    {
        Map<String, List<CAS>> casByUser = load(
                "casdiff/noDifferences/data.conll",
                "casdiff/noDifferences/data.conll");

        List<? extends DiffAdapter> diffAdapters = asList(POS_DIFF_ADAPTER,
                DEPENDENCY_DIFF_ADAPTER);

        CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
        DiffResult result = diff.toResult();

        // result.print(System.out);
        
        assertEquals(52, result.size());
        assertEquals(26, result.size(POS.class.getName()));
        assertEquals(26, result.size(Dependency.class.getName()));
        assertEquals(0, result.getDifferingConfigurationSets().size());
        assertEquals(0, result.getIncompleteConfigurationSets().size());

        // Todo: Agreement has moved to separate project - should create agreement test there
//        CodingAgreementResult agreement = AgreementUtils.getCohenKappaAgreement(diff,
//                entryTypes.get(0), "PosValue", casByUser);
//        assertEquals(1.0d, agreement.getAgreement(), 0.000001d);
//        assertEquals(0, agreement.getIncompleteSetsByPosition().size());
    }
 
Example #21
Source File: DictionaryMatchAnnotator.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private void addPosDictionaryMatch(JCas jCas, List<POS> currentPosSequence) {
    for (POS pos : currentPosSequence) {
        PosDictionaryMatch match = new PosDictionaryMatch(jCas,
                pos.getBegin(), pos.getEnd());
        match.addToIndexes();
        logger.trace("Pos match added for tag: " + pos.getPosValue() +
                " from sequence: " + posSequenceToString(currentPosSequence) +
                " for tokens: " + currentPosSequence.stream()
                .map(Annotation::getCoveredText)
                .collect(Collectors.joining(" ")));
    }

}
 
Example #22
Source File: CasMergeTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * If one annotator has provided an annotation at a given position and the other annotator did
 * not (i.e. the annotations are incomplete), then this should be detected as a disagreement. 
 */
@Test
public void thatIncompleteAnnotationIsMerged()
    throws Exception
{
    JCas user1 = JCasFactory.createText("word");
    token(user1, 0, 4, "X");
    
    JCas user2 = JCasFactory.createText("word");
    token(user2, 0, 4, null);
    
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(user1.getCas()));
    casByUser.put("user2", asList(user2.getCas()));
    
    JCas curatorCas = createText(casByUser.values().stream()
            .flatMap(Collection::stream).findFirst().get().getDocumentText());
    
    DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();

    sut.setMergeIncompleteAnnotations(true);
    sut.reMergeCas(result, document, null, curatorCas.getCas(), getSingleCasByUser(casByUser));

    assertThat(result.getDifferingConfigurationSets()).isEmpty();
    assertThat(result.getIncompleteConfigurationSets().values())
            .extracting(set -> set.getPosition())
            .usingFieldByFieldElementComparator()
            .containsExactly(new SpanPosition(null, null, 0, POS.class.getName(), 0, 4, "word",
                    null, null, -1, -1, null, null));
    
    assertThat(select(curatorCas, POS.class)).hasSize(1);
}
 
Example #23
Source File: CasMergeTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
private AnnotationFS createPOSAnno(CAS aCas, String aValue, int aBegin, int aEnd)
{
    Type type = aCas.getTypeSystem().getType(POS.class.getTypeName());
    
    AnnotationFS clickedFs = aCas.createAnnotation(type, aBegin, aEnd);
    Feature posValue = type.getFeatureByBaseName("PosValue");
    clickedFs.setStringValue(posValue, aValue);
    aCas.addFsToIndexes(clickedFs);
    return clickedFs;
}
 
Example #24
Source File: AgreementMeasureTestSuite_ImplBase.java    From webanno with Apache License 2.0 5 votes vote down vote up
public <R extends Serializable, T extends DefaultAgreementTraits> R 
        singleNoDifferencesWithAdditionalCasTest(
                AggreementMeasureSupport<T, R, ICodingAnnotationStudy> aSupport)
    throws Exception
{
    AnnotationLayer layer = new AnnotationLayer(POS.class.getName(),
            POS.class.getSimpleName(), SPAN_TYPE, project, false, SINGLE_TOKEN, NO_OVERLAP);
    layer.setId(1l);
    layers.add(layer);

    AnnotationFeature feature = new AnnotationFeature(project, layer, "PosValue", "PosValue",
            CAS.TYPE_NAME_STRING);
    feature.setId(1l);
    features.add(feature);
    
    T traits = aSupport.createTraits();
    
    JCas user1 = JCasFactory.createJCas();
    user1.setDocumentText("test");

    JCas user2 = JCasFactory.createJCas();
    user2.setDocumentText("test");
    
    JCas user3 = JCasFactory.createJCas();
    user3.setDocumentText("test");
    POS pos3 = new POS(user3, 0, 4);
    pos3.setPosValue("test");
    pos3.addToIndexes();
    
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(user1.getCas()));
    casByUser.put("user2", asList(user2.getCas()));
    casByUser.put("user3", asList(user3.getCas()));
    
    AggreementMeasure<R> measure = aSupport.createMeasure(feature, traits);
    
    return measure.getAgreement(casByUser);
}
 
Example #25
Source File: AgreementMeasureTestSuite_ImplBase.java    From webanno with Apache License 2.0 5 votes vote down vote up
public <R extends Serializable, T extends DefaultAgreementTraits> R twoWithoutLabelTest(
        AggreementMeasureSupport<T, R, ICodingAnnotationStudy> aSupport, T aTraits)
    throws Exception
{
    AnnotationLayer layer = new AnnotationLayer(POS.class.getName(),
            POS.class.getSimpleName(), SPAN_TYPE, project, false, SINGLE_TOKEN, NO_OVERLAP);
    layer.setId(1l);
    layers.add(layer);

    AnnotationFeature feature = new AnnotationFeature(project, layer, "PosValue", "PosValue",
            CAS.TYPE_NAME_STRING);
    feature.setId(1l);
    features.add(feature);
    
    JCas user1 = JCasFactory.createJCas();
    user1.setDocumentText("test");
    new POS(user1, 0, 1).addToIndexes();
    new POS(user1, 1, 2).addToIndexes();
    POS p1 = new POS(user1, 3, 4);
    p1.setPosValue("A");
    p1.addToIndexes();

    JCas user2 = JCasFactory.createJCas();
    user2.setDocumentText("test");
    new POS(user2, 0, 1).addToIndexes();
    new POS(user2, 2, 3).addToIndexes();
    POS p2 = new POS(user2, 3, 4);
    p2.setPosValue("B");
    p2.addToIndexes();
    
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(user1.getCas()));
    casByUser.put("user2", asList(user2.getCas()));
    
    AggreementMeasure<R> measure = aSupport.createMeasure(feature, aTraits);
    
    return measure.getAgreement(casByUser);
}
 
Example #26
Source File: TwoPairedKappaTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoUserSameAnnotation()
    throws Exception
{
    Map<User, List<SourceDocument>> userDocs = new HashMap<>();
    userDocs.put(user1, asList(document));
    userDocs.put(user2, asList(document));
    
    Map<User, CAS> userCases = new HashMap<>();
    userCases.put(user1, kappatestCas);
    userCases.put(user2, kappatestCas);
    
    Map<SourceDocument, Map<User, CAS>> documentJCases = new HashMap<>();
    documentJCases.put(document, userCases);
    
    // Check against new impl
    CasDiff diff = doDiff(asList(POS_DIFF_ADAPTER), LINK_TARGET_AS_LABEL, convert(userCases));
    DiffResult result = diff.toResult();
    AgreementResult agreement = getCohenKappaAgreement(diff, POS.class.getName(),
            "PosValue", convert(userCases));
    
    // Asserts
    System.out.printf("Agreement: %s%n", agreement.toString());
    result.print(System.out);
    
    assertEquals(1.0d, agreement.getAgreement(), 0.000001);
    assertEquals(9, result.size());
    assertEquals(0, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
}
 
Example #27
Source File: TwoPairedKappaTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoUserDiffSpanAnnotation()
    throws Exception
{
    Map<User, List<SourceDocument>> userDocs = new HashMap<>();
    userDocs.put(user1, asList(document));
    userDocs.put(user2, asList(document));
    
    Map<User, CAS> userCases = new HashMap<>();
    userCases.put(user1, kappatestCas);
    userCases.put(user2, kappaspandiff);

    Map<SourceDocument, Map<User, CAS>> documentJCases = new HashMap<>();
    documentJCases.put(document, userCases);
    
    // Check against new impl
    CasDiff diff = doDiff(asList(POS_DIFF_ADAPTER), LINK_TARGET_AS_LABEL, convert(userCases));
    DiffResult result = diff.toResult();
    AgreementResult agreement = getCohenKappaAgreement(diff, POS.class.getName(),
            "PosValue", convert(userCases));
    
    // Asserts
    System.out.printf("Agreement: %s%n", agreement.toString());
    result.print(System.out);
    
    assertEquals(0.86153d, agreement.getAgreement(), 0.00001d);
    assertEquals(9, result.size());
    assertEquals(1, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
}
 
Example #28
Source File: BratRenderer.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * Scan through the layers once to remember which layers attach to which layers.
 */
private static List<AnnotationLayer> getAttachingLayers(AnnotationLayer aTarget,
        List<AnnotationLayer> aLayers, AnnotationSchemaService aAnnotationService)
{
    List<AnnotationLayer> attachingLayers = new ArrayList<>();

    // Chains always attach to themselves
    if (CHAIN_TYPE.equals(aTarget.getType())) {
        attachingLayers.add(aTarget);
    }

    // FIXME This is a hack! Actually we should check the type of the attachFeature when
    // determine which layers attach to with other layers. Currently we only use attachType,
    // but do not follow attachFeature if it is set.
    if (aTarget.isBuiltIn() && aTarget.getName().equals(POS.class.getName())) {
        attachingLayers.add(aAnnotationService.findLayer(aTarget.getProject(),
                Dependency.class.getName()));
    }

    // Custom layers
    for (AnnotationLayer l : aLayers) {
        if (aTarget.equals(l.getAttachType())) {
            attachingLayers.add(l);
        }
    }

    return attachingLayers;
}
 
Example #29
Source File: DKPro2Tcf.java    From inception with Apache License 2.0 5 votes vote down vote up
public void writePosTags(JCas aJCas, TextCorpus aTextCorpus,
        Map<Integer, eu.clarin.weblicht.wlfxb.tc.api.Token> aTokensBeginPositionMap)
{
    if (!JCasUtil.exists(aJCas, POS.class)) {
        // Do nothing if there are no part-of-speech tags in the CAS
        log.debug("Layer [{}]: empty", TextCorpusLayerTag.POSTAGS.getXmlName());
        return;
    }

    // Tokens layer must already exist
    TokensLayer tokensLayer = aTextCorpus.getTokensLayer();
    
    // create POS tag annotation layer
    String posTagSet = "STTS";
    for (TagsetDescription tagSet : select(aJCas, TagsetDescription.class)) {
        if (tagSet.getLayer().equals(POS.class.getName())) {
            posTagSet = tagSet.getName();
            break;
        }
    }
    
    PosTagsLayer posLayer = aTextCorpus.createPosTagsLayer(posTagSet);
    
    log.debug("Layer [{}]: created", TextCorpusLayerTag.POSTAGS.getXmlName());
    
    int j = 0;
    for (Token coveredToken : select(aJCas, Token.class)) {
        POS pos = coveredToken.getPos();

        if (pos != null && posLayer != null ) {
            String posValue = coveredToken.getPos().getPosValue();
            posLayer.addTag(posValue, tokensLayer.getToken(j));
        }

        j++;
    }
}
 
Example #30
Source File: OpenNlpPosRecommenderTest.java    From inception with Apache License 2.0 5 votes vote down vote up
private static Recommender buildRecommender()
{
    AnnotationLayer layer = new AnnotationLayer();
    layer.setName(POS.class.getName());

    AnnotationFeature feature = new AnnotationFeature();
    feature.setName("PosValue");
    
    Recommender recommender = new Recommender();
    recommender.setLayer(layer);
    recommender.setFeature(feature);
    recommender.setMaxRecommendations(3);

    return recommender;
}