Search in sources :

Example 11 with POS

use of de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS in project webanno by webanno.

the class SymbolicRulesTest method testSimpleSymbolicRules.

@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);
}
Also used : CollectionReader(org.apache.uima.collection.CollectionReader) Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ParserVisitor(de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor) ArrayList(java.util.ArrayList) ParsedConstraints(de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints) JCas(org.apache.uima.jcas.JCas) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) FileInputStream(java.io.FileInputStream) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) Lemma(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) Test(org.junit.Test)

Example 12 with POS

use of de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS in project webanno by webanno.

the class ConstraintsGeneratorTest method testSimplePath.

@Test
public void testSimplePath() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/10.rules"));
    Parse p = parser.Parse();
    ParsedConstraints constraints = p.accept(new ParserVisitor());
    JCas jcas = JCasFactory.createJCas();
    jcas.setDocumentText("The sun.");
    // Add token annotations
    Token t_the = new Token(jcas, 0, 3);
    t_the.addToIndexes();
    Token t_sun = new Token(jcas, 0, 3);
    t_sun.addToIndexes();
    // Add POS annotations and link them to the tokens
    POS p_the = new POS(jcas, t_the.getBegin(), t_the.getEnd());
    p_the.setPosValue("DET");
    p_the.addToIndexes();
    t_the.setPos(p_the);
    POS p_sun = new POS(jcas, t_sun.getBegin(), t_sun.getEnd());
    p_sun.setPosValue("NN");
    p_sun.addToIndexes();
    t_sun.setPos(p_sun);
    // Add dependency annotations
    Dependency dep_the_sun = new Dependency(jcas);
    dep_the_sun.setGovernor(t_sun);
    dep_the_sun.setDependent(t_the);
    dep_the_sun.setDependencyType("det");
    dep_the_sun.setBegin(dep_the_sun.getGovernor().getBegin());
    dep_the_sun.setEnd(dep_the_sun.getGovernor().getEnd());
    dep_the_sun.addToIndexes();
    Evaluator constraintsEvaluator = new ValuesGenerator();
    List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(dep_the_sun, "DependencyType", constraints);
    List<PossibleValue> expectedOutput = new LinkedList<>();
    expectedOutput.add(new PossibleValue("det", false));
    assertEquals(expectedOutput, possibleValues);
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ParserVisitor(de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor) ParsedConstraints(de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) Dependency(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) Test(org.junit.Test)

Example 13 with POS

use of de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS in project webanno by webanno.

the class WebAnnoTsv3WriterTestBase method testTokenAttachedAnnotationsWithValues.

@Test
public void testTokenAttachedAnnotationsWithValues() throws Exception {
    JCas jcas = makeJCasOneSentence();
    List<Token> tokens = new ArrayList<>(select(jcas, Token.class));
    Token t1 = tokens.get(0);
    Lemma l1 = new Lemma(jcas, t1.getBegin(), t1.getEnd());
    l1.setValue("lemma1");
    l1.addToIndexes();
    t1.setLemma(l1);
    MorphologicalFeatures m1 = new MorphologicalFeatures(jcas, t1.getBegin(), t1.getEnd());
    m1.setValue("morph");
    m1.setTense("tense1");
    m1.addToIndexes();
    t1.setMorph(m1);
    POS p1 = new POS(jcas, t1.getBegin(), t1.getEnd());
    p1.setPosValue("pos1");
    p1.addToIndexes();
    t1.setPos(p1);
    Stem s1 = new Stem(jcas, t1.getBegin(), t1.getEnd());
    s1.setValue("stem1");
    s1.addToIndexes();
    t1.setStem(s1);
    writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(MorphologicalFeatures.class, POS.class, Lemma.class, Stem.class));
}
Also used : MorphologicalFeatures(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.morph.MorphologicalFeatures) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) Lemma(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Stem(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Stem) Test(org.junit.Test)

Example 14 with POS

use of de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS in project webanno by webanno.

the class CopyAnnotationTest method simpleCopyRelationToStackedTargetsTest.

@Test
public void simpleCopyRelationToStackedTargetsTest() throws Exception {
    JCas jcas = JCasFactory.createJCas();
    Type type = jcas.getTypeSystem().getType(Dependency.class.getTypeName());
    Type posType = jcas.getTypeSystem().getType(POS.class.getTypeName());
    AnnotationFS originClickedToken = createTokenAnno(jcas, 0, 0);
    AnnotationFS targetClickedToken = createTokenAnno(jcas, 1, 1);
    AnnotationFS originClicked = createPOSAnno(jcas, posType, "NN", 0, 0);
    AnnotationFS targetClicked = createPOSAnno(jcas, posType, "NN", 1, 1);
    jcas.addFsToIndexes(originClicked);
    jcas.addFsToIndexes(targetClicked);
    originClickedToken.setFeatureValue(originClickedToken.getType().getFeatureByBaseName("pos"), originClicked);
    targetClickedToken.setFeatureValue(targetClickedToken.getType().getFeatureByBaseName("pos"), targetClicked);
    Feature sourceFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
    Feature targetFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
    AnnotationFS clickedFs = jcas.getCas().createAnnotation(type, 0, 1);
    clickedFs.setFeatureValue(sourceFeature, originClickedToken);
    clickedFs.setFeatureValue(targetFeature, targetClickedToken);
    jcas.addFsToIndexes(clickedFs);
    JCas mergeCAs = JCasFactory.createJCas();
    AnnotationFS origin = createPOSAnno(mergeCAs, posType, "NN", 0, 0);
    AnnotationFS target = createPOSAnno(mergeCAs, posType, "NN", 1, 1);
    mergeCAs.addFsToIndexes(origin);
    mergeCAs.addFsToIndexes(target);
    AnnotationFS originToken = createTokenAnno(mergeCAs, 0, 0);
    AnnotationFS targetToken = createTokenAnno(mergeCAs, 1, 1);
    originToken.setFeatureValue(originToken.getType().getFeatureByBaseName("pos"), origin);
    targetToken.setFeatureValue(targetToken.getType().getFeatureByBaseName("pos"), target);
    mergeCAs.addFsToIndexes(originToken);
    mergeCAs.addFsToIndexes(targetToken);
    AnnotationFS origin2 = createPOSAnno(mergeCAs, posType, "NN", 0, 0);
    AnnotationFS target2 = createPOSAnno(mergeCAs, posType, "NN", 1, 1);
    mergeCAs.addFsToIndexes(origin2);
    mergeCAs.addFsToIndexes(target2);
    AnnotationFS originToken2 = createTokenAnno(mergeCAs, 0, 0);
    AnnotationFS targetToken2 = createTokenAnno(mergeCAs, 1, 1);
    originToken2.setFeatureValue(originToken.getType().getFeatureByBaseName("pos"), origin2);
    targetToken2.setFeatureValue(targetToken.getType().getFeatureByBaseName("pos"), target2);
    mergeCAs.addFsToIndexes(originToken2);
    mergeCAs.addFsToIndexes(targetToken2);
    exception.expect(AnnotationException.class);
    MergeCas.addRelationArcAnnotation(mergeCAs, clickedFs, true, false, originToken, targetToken);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) JCas(org.apache.uima.jcas.JCas) Dependency(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Test(org.junit.Test)

Example 15 with POS

use of de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS in project dkpro-tc by dkpro.

the class TcAnnotatorTest method testAnnotator.

@Test
public void testAnnotator() throws UIMAException {
    JCas aJCas = JCasFactory.createJCas();
    aJCas.setDocumentText("This article attempts to provide a general introduction to atheism.");
    AnalysisEngine segmenter = AnalysisEngineFactory.createEngine(BreakIteratorSegmenter.class);
    segmenter.process(aJCas);
    String[] converter = new String[] { ConversionAnnotator.class.getName(), ConversionAnnotator.PARAM_SUFFIX, "-X" };
    AnalysisEngine tcAnno = AnalysisEngineFactory.createEngine(TcAnnotator.class, TcAnnotator.PARAM_NAME_SEQUENCE_ANNOTATION, Sentence.class.getName(), TcAnnotator.PARAM_NAME_UNIT_ANNOTATION, Token.class.getName(), TcAnnotator.PARAM_TC_MODEL_LOCATION, "src/test/resources/TcAnnotatorTestModelDummy", TcAnnotator.PARAM_CONVERTION_ANNOTATOR, converter, TcAnnotator.PARAM_RETAIN_TARGETS, false);
    tcAnno.process(aJCas);
    assertEquals(0, JCasUtil.select(aJCas, TextClassificationTarget.class).size());
    assertEquals(11, JCasUtil.select(aJCas, POS.class).size());
    assertTrue(new ArrayList<POS>(JCasUtil.select(aJCas, POS.class)).get(0).getPosValue().endsWith("-X"));
}
Also used : POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine) Test(org.junit.Test)

Aggregations

POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)35 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)21 ArrayList (java.util.ArrayList)15 JCas (org.apache.uima.jcas.JCas)14 Test (org.junit.Test)12 Lemma (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma)11 Dependency (de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency)9 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)8 List (java.util.List)8 Type (org.apache.uima.cas.Type)8 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)7 MorphologicalFeatures (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.morph.MorphologicalFeatures)7 LinkedHashMap (java.util.LinkedHashMap)7 Feature (org.apache.uima.cas.Feature)7 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)7 Stem (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Stem)5 HashMap (java.util.HashMap)5 Evaluator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator)3 PossibleValue (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)3 ValuesGenerator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator)3