public void runRules(String[] rules, java.lang.Object[] facts) { KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); for (int i = 0; i < rules.Length; i++) { String ruleFile = rules[i]; Console.WriteLine("Loading file: " + ruleFile); ruleFile = Path.GetFullPath(Path.Combine("rules", ruleFile)); kbuilder.add(ResourceFactory.newFileResource(ruleFile), ResourceType.DRL); } java.util.Collection pkgs = kbuilder.getKnowledgePackages(); kbase.addKnowledgePackages(pkgs); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); for (int i = 0; i < facts.Length; i++) { java.lang.Object fact = facts[i]; //Console.WriteLine("Inserting fact: " + fact); ksession.insert(fact); } ksession.fireAllRules(); }
private List <T> GetObjects <T>(TheiaClassLoader classLoader, StatefulKnowledgeSession kSession, List <Type> types, List <T> objects) { var hash = new HashSet <T>(objects); List <T> list = new List <T>(); foreach (var type in types) { Class javaClass = Class.forName($"cli.Theia.{type.Name}", false, classLoader); foreach (var newObject in kSession.getObjects(new ClassObjectFilter(javaClass)).toArray()) { if (!hash.Contains((T)newObject)) { list.Add((T)newObject); } } } return(list); }