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);
}
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);
}
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));
}
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);
}
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"));
}
Aggregations