use of de.tudarmstadt.ukp.clarin.webanno.constraints.model.Scope 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;
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.model.Scope 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.Scope in project webanno by webanno.
the class ScopeVisitorTest 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<Scope> scopes = new ArrayList<>();
p.accept(new ScopeVisitor(), scopes);
for (Scope scope : scopes) {
System.out.printf("%s %n", scope);
}
}
Aggregations