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