Search in sources :

Example 1 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar in project webanno by webanno.

the class ConstraintsServiceImpl method loadConstraints.

@Override
public ParsedConstraints loadConstraints(Project aProject) throws IOException, ParseException {
    ParsedConstraints merged = null;
    for (ConstraintSet set : listConstraintSets(aProject)) {
        String script = readConstrainSet(set);
        ConstraintsGrammar parser = new ConstraintsGrammar(new StringReader(script));
        Parse p = parser.Parse();
        ParsedConstraints constraints = p.accept(new ParserVisitor());
        if (merged == null) {
            merged = constraints;
        } else {
            // Merge imports
            for (Entry<String, String> e : constraints.getImports().entrySet()) {
                // constraint file(s).
                if (merged.getImports().containsKey(e.getKey()) && !e.getValue().equalsIgnoreCase(merged.getImports().get(e.getKey()))) {
                    // If detected, notify user with proper message and abort merging
                    String errorMessage = "Conflict detected in imports for key \"" + e.getKey() + "\", conflicting values are \"" + e.getValue() + "\" & \"" + merged.getImports().get(e.getKey()) + "\". Please contact Project Admin for correcting this." + "Constraints feature may not work." + "\nAborting Constraint rules merge!";
                    throw new ParseException(errorMessage);
                }
            }
            merged.getImports().putAll(constraints.getImports());
            // Merge scopes
            for (Scope scope : constraints.getScopes()) {
                Scope target = merged.getScopeByName(scope.getScopeName());
                if (target == null) {
                    // Scope does not exist yet
                    merged.getScopes().add(scope);
                } else {
                    // Scope already exists
                    target.getRules().addAll(scope.getRules());
                }
            }
        }
    }
    return merged;
}
Also used : Scope(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Scope) Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) StringReader(java.io.StringReader) ParserVisitor(de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor) ParsedConstraints(de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints) ParseException(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ParseException) ConstraintSet(de.tudarmstadt.ukp.clarin.webanno.model.ConstraintSet) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar)

Example 2 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar in project webanno by webanno.

the class ConstraintsParserTest method test3.

@Test
public void test3() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/3.rules"));
    Parse p = parser.Parse();
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 3 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar in project webanno by webanno.

the class ConstraintsParserTest method test4.

@Test
public void test4() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/4.rules"));
    Parse p = parser.Parse();
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 4 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar in project webanno by webanno.

the class ConstraintsParserTest method test8.

@Test
public void test8() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/8.rules"));
    Parse p = parser.Parse();
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 5 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar in project webanno by webanno.

the class ConstraintsParserTest method test1.

@Test
public void test1() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/1.rules"));
    Parse p = parser.Parse();
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

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