我需要在一个规则中比较同一类的两个对象流口水。但是,我怎么知道一个属性属于在主类中创建的对象呢?我需要帮助!
public class CheckerMain {
public static void main(String[] args) {
try {
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "ConflictChecker");
DeonticConcept deoCon1 = new DeonticConcept("forbidden");
DeonticConcept deoCon2 = new DeonticConcept("permission");
ksession.insert(deoCon1);
ksession.insert(deoCon2);
ksession.fireAllRules();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Rules.drl"), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
我想在一个规则中比较对象 deoCon1 和 deoCon2 中实例化的属性 nameConceptDeontic。我怎么能做到这一点?