Search in sources :

Example 1 with Rule

use of de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule in project webanno by webanno.

the class RuleVisitorTest method test.

@Test
public void test() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/6.rules"));
    Parse p = parser.Parse();
    List<Rule> rules = new ArrayList<>();
    p.accept(new RuleVisitor(), rules);
    for (Rule rule : rules) {
        System.out.printf("%s %n", rule);
    }
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ArrayList(java.util.ArrayList) Rule(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with Rule

use of de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule in project webanno by webanno.

the class ScopeVisitor method visit.

@Override
public void visit(ScopedDeclarations n, List<Scope> argu) {
    String scope = n.f0.toString();
    List<Rule> rules = new ArrayList<>();
    n.accept(new RuleVisitor(), rules);
    argu.add(new Scope(scope, rules));
// super.visit(n, argu);
}
Also used : Scope(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Scope) ArrayList(java.util.ArrayList) Rule(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule)

Example 3 with Rule

use of de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule in project webanno by webanno.

the class RuleVisitor method visit.

@Override
public void visit(RuleDeclaration aN, List<Rule> aArgu) {
    List<Condition> conditions = new ArrayList<>();
    List<Restriction> restrictions = new ArrayList<>();
    // super.visit(aN, aArgu);
    aN.accept(new ConditionVisitor(), conditions);
    aN.accept(new RestrictionVisitor(), restrictions);
    aArgu.add(new Rule(conditions, restrictions));
}
Also used : Condition(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Condition) Restriction(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Restriction) ArrayList(java.util.ArrayList) Rule(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule)

Example 4 with Rule

use of de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule in project webanno by webanno.

the class ConstraintsVerifier method verify.

@Override
public boolean verify(FeatureStructure featureStructure, ParsedConstraints parsedConstraints) {
    boolean isOk = false;
    Type type = featureStructure.getType();
    for (Feature feature : type.getFeatures()) {
        if (feature.getRange().isPrimitive()) {
            String scopeName = featureStructure.getFeatureValueAsString(feature);
            List<Rule> rules = parsedConstraints.getScopeByName(scopeName).getRules();
        // Check if all the feature values are ok according to the
        // rules;
        } else {
        // Here some recursion would be in order
        }
    }
    return isOk;
}
Also used : Type(org.apache.uima.cas.Type) Rule(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule) Feature(org.apache.uima.cas.Feature)

Example 5 with Rule

use of de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule in project webanno by webanno.

the class ValuesGenerator method generatePossibleValues.

@Override
public List<PossibleValue> generatePossibleValues(FeatureStructure aContext, String aFeature, ParsedConstraints parsedConstraints) throws UIMAException {
    imports = parsedConstraints.getImports();
    List<PossibleValue> possibleValues = new ArrayList<>();
    // if(!isThisAffectedByConstraintRules(aContext, aFeature, parsedConstraints)){
    if (!parsedConstraints.areThereRules(aContext.getType().getName(), aFeature)) {
        return possibleValues;
    }
    // String shortTypeName = parsedConstraints.getShortName(aContext.getType().getName());
    // if (shortTypeName == null) {
    // //If no relevant rules are there for a particular type, just return empty list
    // log.error("No import for [" + aContext.getType().getName()
    // + "] - Imports are: [" + parsedConstraints.getImports() + "]");
    // return possibleValues;
    // //            throw new IllegalStateException("No import for [" + aContext.getType().getName()
    // //                    + "] - Imports are: [" + parsedConstraints.getImports() + "]");
    // }
    shortTypeName = parsedConstraints.getShortName(aContext.getType().getName());
    scope = parsedConstraints.getScopeByName(shortTypeName);
    for (Rule rule : scope.getRules()) {
        // Check if conditions apply
        if (!ruleTriggers(aContext, rule)) {
            continue;
        }
        // If all conditions apply, collect the possible values
        for (Restriction res : rule.getRestrictions()) {
            if (aFeature.equals(res.getPath())) {
                PossibleValue pv = new PossibleValue(res.getValue(), res.isFlagImportant());
                possibleValues.add(pv);
            }
        }
    }
    return possibleValues;
}
Also used : Restriction(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Restriction) ArrayList(java.util.ArrayList) Rule(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule)

Aggregations

Rule (de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule)5 ArrayList (java.util.ArrayList)4 Restriction (de.tudarmstadt.ukp.clarin.webanno.constraints.model.Restriction)2 ConstraintsGrammar (de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar)1 Parse (de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse)1 Condition (de.tudarmstadt.ukp.clarin.webanno.constraints.model.Condition)1 Scope (de.tudarmstadt.ukp.clarin.webanno.constraints.model.Scope)1 FileInputStream (java.io.FileInputStream)1 Feature (org.apache.uima.cas.Feature)1 Type (org.apache.uima.cas.Type)1 Test (org.junit.Test)1