Search in sources :

Example 6 with PossibleValue

use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.

the class ComplexTypeTest method testCountryType.

@Test
public void testCountryType() throws Exception {
    TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription("desc.types.TestTypeSystemDescriptor");
    CAS cas = CasCreationUtils.createCas(tsd, null, null);
    cas.setDocumentText("Asia is the largest continent on Earth. Asia is subdivided into 48 countries, two of them (Russia and Turkey) having part of their land in Europe. The most active place on Earth for tropical cyclone activity lies northeast of the Philippines and south of Japan. The Gobi Desert is in Mongolia and the Arabian Desert stretches across much of the Middle East. The Yangtze River in China is the longest river in the continent. The Himalayas between Nepal and China is the tallest mountain range in the world. Tropical rainforests stretch across much of southern Asia and coniferous and deciduous forests lie farther north.");
    TypeSystem ts = cas.getTypeSystem();
    Type continentType = ts.getType("de.Continent");
    Feature continentName = continentType.getFeatureByBaseName("name");
    AnnotationFS asiaContinent = cas.createAnnotation(continentType, 0, 4);
    asiaContinent.setStringValue(continentName, "Asia");
    cas.addFsToIndexes(asiaContinent);
    Type countryType = ts.getType("de.Country");
    Feature countryName = countryType.getFeatureByBaseName("name");
    AnnotationFS russia = cas.createAnnotation(countryType, 56, 62);
    russia.setStringValue(countryName, "Russian Federation");
    Feature continentFeature = countryType.getFeatureByBaseName("continent");
    russia.setFeatureValue(continentFeature, asiaContinent);
    cas.addFsToIndexes(russia);
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/region.rules"));
    Parse p = parser.Parse();
    ParsedConstraints constraints = p.accept(new ParserVisitor());
    Evaluator constraintsEvaluator = new ValuesGenerator();
    List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(russia, "regionType", constraints);
    List<PossibleValue> exValues = new LinkedList<>();
    exValues.add(new PossibleValue("cold", true));
    assertEquals(possibleValues, exValues);
}
Also used : TypeSystem(org.apache.uima.cas.TypeSystem) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) 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) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) Feature(org.apache.uima.cas.Feature) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CAS(org.apache.uima.cas.CAS) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) Test(org.junit.Test)

Example 7 with PossibleValue

use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.

the class ComplexTypeTest method testProfType.

@Test
public void testProfType() throws Exception {
    TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription("desc.types.TestTypeSystemDescriptor");
    CAS cas = CasCreationUtils.createCas(tsd, null, null);
    cas.setDocumentText("I listen to lectures by Prof. Gurevych sometimes.");
    TypeSystem ts = cas.getTypeSystem();
    Type profType = ts.getType("de.tud.Prof");
    Feature profNameFeature = profType.getFeatureByBaseName("fullName");
    Feature profBossFeature = profType.getFeatureByBaseName("boss");
    AnnotationFS proemel = cas.createAnnotation(profType, 0, 0);
    proemel.setStringValue(profNameFeature, "Hans Juergen Proeml");
    cas.addFsToIndexes(proemel);
    AnnotationFS gurevych = cas.createAnnotation(profType, 24, 38);
    gurevych.setStringValue(profNameFeature, "Iryna Gurevych");
    gurevych.setFeatureValue(profBossFeature, proemel);
    cas.addFsToIndexes(gurevych);
    /*
         * for (String feature : Arrays.asList("fullName", "boss")) { Feature someFeature =
         * gurevych.getType().getFeatureByBaseName(feature); if
         * (someFeature.getRange().isPrimitive()) { String value =
         * gurevych.getFeatureValueAsString(someFeature); System.out.println(value); } else {
         * FeatureStructure value = gurevych.getFeatureValue(someFeature);
         * System.out.printf("%s (%s)%n", value.getFeatureValueAsString(profNameFeature),
         * value.getType()); } }
         */
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/prof.rules"));
    Parse p = parser.Parse();
    ParsedConstraints constraints = p.accept(new ParserVisitor());
    Evaluator constraintsEvaluator = new ValuesGenerator();
    List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(gurevych, "professorName", constraints);
    List<PossibleValue> exValues = new LinkedList<>();
    exValues.add(new PossibleValue("Iryna Gurevych", false));
    assertEquals(possibleValues, exValues);
}
Also used : TypeSystem(org.apache.uima.cas.TypeSystem) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) 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) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) Feature(org.apache.uima.cas.Feature) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CAS(org.apache.uima.cas.CAS) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) Test(org.junit.Test)

Example 8 with PossibleValue

use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.

the class LinkFeatureEditor method autoAddImportantTags.

private void autoAddImportantTags(List<Tag> aTagset, List<PossibleValue> aPossibleValues) {
    if (aTagset == null || aTagset.isEmpty() || aPossibleValues == null || aPossibleValues.isEmpty()) {
        return;
    }
    // Construct a quick index for tags
    Set<String> tagset = new HashSet<>();
    for (Tag t : aTagset) {
        tagset.add(t.getName());
    }
    // Get links list and build role index
    @SuppressWarnings("unchecked") List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) getModelObject().value;
    Set<String> roles = new HashSet<>();
    for (LinkWithRoleModel l : links) {
        roles.add(l.role);
    }
    // Loop over values to see which of the tags are important and add them.
    for (PossibleValue value : aPossibleValues) {
        if (!value.isImportant() || !tagset.contains(value.getValue())) {
            continue;
        }
        // Check if there is already a slot with the given name
        if (roles.contains(value.getValue())) {
            continue;
        }
        // Add empty slot in UI with that name.
        LinkWithRoleModel m = new LinkWithRoleModel();
        m.role = value.getValue();
        // Marking so that can be ignored later.
        m.autoCreated = true;
        links.add(m);
    // NOT arming the slot here!
    }
}
Also used : LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) List(java.util.List) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) HashSet(java.util.HashSet)

Example 9 with PossibleValue

use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.

the class AnnotationDetailEditorPanel method compareSortAndAdd.

/*
     * Compares existing tagset with possible values resulted from rule evaluation Adds only which
     * exist in tagset and is suggested by rules. The remaining values from tagset are added
     * afterwards.
     */
private static List<Tag> compareSortAndAdd(List<PossibleValue> possibleValues, List<Tag> valuesFromTagset, RulesIndicator rulesIndicator) {
    // if no possible values, means didn't satisfy conditions
    if (possibleValues.isEmpty()) {
        rulesIndicator.didntMatchAnyRule();
    }
    List<Tag> returnList = new ArrayList<>();
    // tagset and adding them first in list.
    for (PossibleValue value : possibleValues) {
        for (Tag tag : valuesFromTagset) {
            if (value.getValue().equalsIgnoreCase(tag.getName())) {
                // Matching values found in tagset and shown in dropdown
                rulesIndicator.rulesApplied();
                // HACK BEGIN
                tag.setReordered(true);
                // Avoid duplicate entries
                if (!returnList.contains(tag)) {
                    returnList.add(tag);
                }
            }
        }
    }
    // If no matching tags found
    if (returnList.isEmpty()) {
        rulesIndicator.didntMatchAnyTag();
    }
    return returnList;
}
Also used : ArrayList(java.util.ArrayList) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)

Example 10 with PossibleValue

use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.

the class ConstraintsGeneratorTest method testSimpleFeature.

@Test
public void testSimpleFeature() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/9.rules"));
    Parse p = parser.Parse();
    ParsedConstraints constraints = p.accept(new ParserVisitor());
    JCas jcas = JCasFactory.createJCas();
    jcas.setDocumentText("is");
    Lemma lemma = new Lemma(jcas, 0, 2);
    lemma.setValue("be");
    lemma.addToIndexes();
    Evaluator constraintsEvaluator = new ValuesGenerator();
    List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(lemma, "value", constraints);
    List<PossibleValue> expectedOutput = new LinkedList<>();
    expectedOutput.add(new PossibleValue("be", true));
    assertEquals(expectedOutput, possibleValues);
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) Lemma(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma) ParserVisitor(de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor) ParsedConstraints(de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints) JCas(org.apache.uima.jcas.JCas) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

PossibleValue (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)10 Evaluator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator)8 ValuesGenerator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator)8 ConstraintsGrammar (de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar)7 Parse (de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse)7 ParsedConstraints (de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints)7 ParserVisitor (de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor)7 FileInputStream (java.io.FileInputStream)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 JCas (org.apache.uima.jcas.JCas)5 LinkedList (java.util.LinkedList)4 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)3 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)3 Lemma (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma)3 CAS (org.apache.uima.cas.CAS)3 Type (org.apache.uima.cas.Type)3 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)3 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)2 Feature (org.apache.uima.cas.Feature)2