Search in sources :

Example 1 with Restriction

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

the class RestrictionVisitorTest 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<Restriction> restrictions = new ArrayList<>();
    p.accept(new RestrictionVisitor(), restrictions);
    for (Restriction res : restrictions) {
        System.out.printf("%s %n", res);
    }
}
Also used : Restriction(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Restriction) Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ArrayList(java.util.ArrayList) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with Restriction

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

the class RestrictionVisitor method visit.

@Override
public void visit(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Restriction aN, List<Restriction> aArgu) {
    path = null;
    value = QuoteUtil.unquote(aN.f2.tokenImage);
    flagImportant = false;
    super.visit(aN, aArgu);
    aArgu.add(new Restriction(path, value, flagImportant));
}
Also used : Restriction(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Restriction)

Example 3 with Restriction

use of de.tudarmstadt.ukp.clarin.webanno.constraints.model.Restriction 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 Restriction

use of de.tudarmstadt.ukp.clarin.webanno.constraints.model.Restriction 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

Restriction (de.tudarmstadt.ukp.clarin.webanno.constraints.model.Restriction)4 ArrayList (java.util.ArrayList)3 Rule (de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule)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 FileInputStream (java.io.FileInputStream)1 Test (org.junit.Test)1