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