use of org.drools.verifier.components.Pattern in project drools by kiegroup.
the class PatternSolverTest method testAddAndOrOr.
/**
* <pre>
* and
* / \
* or or
* / \ / \
* descr descr2 descr3 descr4
* </pre>
*
* result:<br>
* descr && descr3<br>
* or<br>
* descr && descr4<br>
* or<br>
* descr2 && descr3<br>
* or<br>
* descr2 && descr4
*/
@Test
public void testAddAndOrOr() {
Pattern pattern = VerifierComponentMockFactory.createPattern1();
LiteralRestriction literalRestriction = LiteralRestriction.createRestriction(pattern, "");
LiteralRestriction literalRestriction2 = LiteralRestriction.createRestriction(pattern, "");
LiteralRestriction literalRestriction3 = LiteralRestriction.createRestriction(pattern, "");
LiteralRestriction literalRestriction4 = LiteralRestriction.createRestriction(pattern, "");
PatternSolver solver = new PatternSolver(pattern);
solver.addOperator(OperatorDescrType.AND);
solver.addOperator(OperatorDescrType.OR);
solver.add(literalRestriction);
solver.add(literalRestriction2);
solver.end();
solver.addOperator(OperatorDescrType.OR);
solver.add(literalRestriction3);
solver.add(literalRestriction4);
solver.end();
solver.end();
List<Set<VerifierComponent>> list = solver.getPossibilityLists();
assertEquals(4, list.size());
assertEquals(2, list.get(0).size());
assertTrue(list.get(0).contains(literalRestriction));
assertTrue(list.get(0).contains(literalRestriction3));
assertEquals(2, list.get(1).size());
assertTrue(list.get(1).contains(literalRestriction));
assertTrue(list.get(1).contains(literalRestriction4));
assertEquals(2, list.get(2).size());
assertTrue(list.get(2).contains(literalRestriction2));
assertTrue(list.get(2).contains(literalRestriction3));
assertEquals(2, list.get(3).size());
assertTrue(list.get(3).contains(literalRestriction2));
assertTrue(list.get(3).contains(literalRestriction4));
}
use of org.drools.verifier.components.Pattern in project drools by kiegroup.
the class PatternSolverTest method testAddOrAndAnd.
/**
* <pre>
* or
* / \
* and and
* / \ / \
* descr descr2 descr3 descr4
* </pre>
*
* result:<br>
* descr && descr2<br>
* or<br>
* descr3 && descr4
*/
@Test
public void testAddOrAndAnd() {
Pattern pattern = VerifierComponentMockFactory.createPattern1();
LiteralRestriction literalRestriction = LiteralRestriction.createRestriction(pattern, "");
LiteralRestriction literalRestriction2 = LiteralRestriction.createRestriction(pattern, "");
LiteralRestriction literalRestriction3 = LiteralRestriction.createRestriction(pattern, "");
LiteralRestriction literalRestriction4 = LiteralRestriction.createRestriction(pattern, "");
PatternSolver solver = new PatternSolver(pattern);
solver.addOperator(OperatorDescrType.OR);
solver.addOperator(OperatorDescrType.AND);
solver.add(literalRestriction);
solver.add(literalRestriction2);
solver.end();
solver.addOperator(OperatorDescrType.AND);
solver.add(literalRestriction3);
solver.add(literalRestriction4);
solver.end();
solver.end();
List<Set<VerifierComponent>> list = solver.getPossibilityLists();
assertEquals(2, list.size());
assertEquals(2, list.get(0).size());
assertTrue(list.get(0).contains(literalRestriction));
assertTrue(list.get(0).contains(literalRestriction2));
assertEquals(2, list.get(1).size());
assertTrue(list.get(1).contains(literalRestriction3));
assertTrue(list.get(1).contains(literalRestriction4));
}
use of org.drools.verifier.components.Pattern in project drools by kiegroup.
the class PatternSolverTest method testAddAndOr.
/**
* <pre>
* and
* / \
* descr or
* / \
* descr2 descr3
* </pre>
*
* result:<br>
* descr && descr2 <br>
* or<br>
* descr && descr3
*/
@Test
public void testAddAndOr() {
Pattern pattern = VerifierComponentMockFactory.createPattern1();
LiteralRestriction literalRestriction = LiteralRestriction.createRestriction(pattern, "");
LiteralRestriction literalRestriction2 = LiteralRestriction.createRestriction(pattern, "");
LiteralRestriction literalRestriction3 = LiteralRestriction.createRestriction(pattern, "");
PatternSolver solver = new PatternSolver(pattern);
solver.addOperator(OperatorDescrType.AND);
solver.add(literalRestriction);
solver.addOperator(OperatorDescrType.OR);
solver.add(literalRestriction2);
solver.add(literalRestriction3);
solver.end();
solver.end();
List<Set<VerifierComponent>> list = solver.getPossibilityLists();
assertEquals(2, list.size());
assertEquals(2, list.get(0).size());
assertTrue(list.get(0).contains(literalRestriction));
assertTrue(list.get(0).contains(literalRestriction2));
assertEquals(2, list.get(1).size());
assertTrue(list.get(1).contains(literalRestriction));
assertTrue(list.get(1).contains(literalRestriction3));
}
use of org.drools.verifier.components.Pattern in project drools by kiegroup.
the class NestedPatternsTest method runVisitor.
@Test
public void runVisitor() throws Exception {
VerifierData data = VerifierReportFactory.newVerifierData();
PackageDescrVisitor visitor = new PackageDescrVisitor(data, Collections.EMPTY_LIST);
assertNotNull(data);
Reader drlReader = new InputStreamReader(getClass().getResourceAsStream("NestedPatterns.drl"));
PackageDescr packageDescr = new DrlParser(LanguageLevelOption.DRL5).parse(drlReader);
assertNotNull(packageDescr);
visitor.visitPackageDescr(packageDescr);
Collection<VerifierComponent> all = data.getAll();
int patternCount = 0;
for (VerifierComponent verifierComponent : all) {
if (verifierComponent.getVerifierComponentType().equals(VerifierComponentType.PATTERN)) {
patternCount++;
}
}
assertEquals(4, patternCount);
Collection<Pattern> patterns = data.getAll(VerifierComponentType.PATTERN);
// for ( Pattern pattern : patterns ) {
// System.out.println( pattern.getPath() + " " + pattern );
// }
assertNotNull(patterns);
assertEquals(4, patterns.size());
Collection<Restriction> restrictions = data.getAll(VerifierComponentType.RESTRICTION);
// for ( Restriction restriction : restrictions ) {
// System.out.println( restriction.getPath() + " " + restriction );
// }
assertNotNull(restrictions);
assertEquals(3, restrictions.size());
}
use of org.drools.verifier.components.Pattern in project drools by kiegroup.
the class PatternDescrVisitor method visitPatternDescr.
private Pattern visitPatternDescr(PatternDescr descr, VerifierComponent parent, int orderNumber) throws UnknownDescriptionException {
objectType = data.getObjectTypeByFullName(descr.getObjectType());
if (objectType == null) {
Import objectImport = data.getImportByName(descr.getObjectType());
if (objectImport != null) {
objectType = ObjectTypeFactory.createObjectType(descr, objectImport);
} else {
objectType = ObjectTypeFactory.createObjectType(descr, descr.getObjectType());
}
data.add(objectType);
}
pattern = new Pattern(descr, rule);
if (parent != null) {
pattern.setParentPath(parent.getPath());
pattern.setParentType(parent.getVerifierComponentType());
}
pattern.setObjectTypePath(objectType.getPath());
pattern.setName(objectType.getName());
pattern.setPatternNot(solvers.getRuleSolver().isChildNot());
pattern.setPatternExists(solvers.getRuleSolver().isExists());
pattern.setPatternForall(solvers.getRuleSolver().isForall());
pattern.setOrderNumber(orderNumber);
if (descr.getIdentifier() != null) {
PatternVariable patternVariable = new PatternVariable(rule);
patternVariable.setName(descr.getIdentifier());
patternVariable.setParentPath(pattern.getPath());
patternVariable.setParentType(pattern.getVerifierComponentType());
data.add(patternVariable);
}
// visit source.
if (descr.getSource() != null) {
visit(descr.getSource());
} else {
if (workingMemory == null) {
workingMemory = new WorkingMemory();
data.add(workingMemory);
}
pattern.setSourcePath(workingMemory.getPath());
pattern.setSourceType(workingMemory.getVerifierComponentType());
}
solvers.startPatternSolver(pattern);
visit(descr.getConstraint());
solvers.endPatternSolver();
data.add(pattern);
return pattern;
}
Aggregations