logicfactorysupport.java
来自「Mandarax是一个规则引擎的纯Java实现。它支持多类型的事实和基于反映的规」· Java 代码 · 共 879 行 · 第 1/3 页
JAVA
879 行
* @param obj3 an object
* @param obj4 an object
*/
public Fact fact(Predicate predicate, Object obj1, Object obj2,Object obj3, Object obj4) {
Class[] structure = predicate.getStructure ();
if(structure.length != 4) {
throw new IllegalArgumentException (
"Not the right number of terms for this predicate, the number is 4, but must be "
+ structure.length);
}
Term[] terms = { toTerm (obj1, structure[0]),
toTerm (obj2, structure[1]),
toTerm (obj3, structure[2]),
toTerm (obj4, structure[3]) };
return lfactory.createFact (predicate, terms);
}
/**
* Create a prerequisite.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param objs objects (will be interpreted as terms)
*/
public Prerequisite prereq(Predicate predicate, Object[] objs) {
return prereq(predicate,objs,false);
}
/**
* Create a prerequisite with one term.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param obj an object
*/
public Prerequisite prereq(Predicate predicate, Object obj) {
return prereq(predicate,obj,false);
}
/**
* Create a prerequisite with two terms.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param obj1 an object
* @param obj2 an object
*/
public Prerequisite prereq(Predicate predicate, Object obj1, Object obj2) {
return prereq(predicate,obj1,obj2,false);
}
/**
* Create a prerequisite with three terms.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param obj1 an object
* @param obj2 an object
* @param obj3 an object
*/
public Prerequisite prereq(Predicate predicate, Object obj1, Object obj2, Object obj3) {
return prereq(predicate,obj1,obj2,obj3,false);
}
/**
* Create a prerequisite with four terms.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param obj1 an object
* @param obj2 an object
* @param obj3 an object
* @param obj4 an object
*/
public Prerequisite prereq(Predicate predicate, Object obj1, Object obj2,Object obj3, Object obj4) {
return prereq(predicate,obj1,obj2,obj3,obj4,false);
}
///
/**
* Create a prerequisite.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param objs objects (will be interpreted as terms)
* @param negatedAF whether the prerequisite is negated (using negation as failure)
*/
public Prerequisite prereq(Predicate predicate, Object[] objs,boolean negatedAF) {
Class[] structure = predicate.getStructure ();
if(structure.length != objs.length) {
throw new IllegalArgumentException (
"Not the right number of terms for this predicate, the number is "
+ objs.length + ", but must be " + structure.length);
}
Term[] terms = new Term[structure.length];
for(int i = 0; i < structure.length; i++) {
terms[i] = toTerm (objs[i], structure[i]);
}
return lfactory.createPrerequisite (predicate, terms,negatedAF);
}
/**
* Create a prerequisite with one term.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param obj an object
* @param negatedAF whether the prerequisite is negated (using negation as failure)
*/
public Prerequisite prereq(Predicate predicate, Object obj,boolean negatedAF) {
Class[] structure = predicate.getStructure ();
if(structure.length != 1) {
throw new IllegalArgumentException (
"Not the right number of terms for this predicate, the number is 1, but must be "
+ structure.length);
}
Term[] terms = { toTerm (obj, structure[0]) };
return lfactory.createPrerequisite (predicate, terms,negatedAF);
}
/**
* Create a prerequisite with two terms.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param obj1 an object
* @param obj2 an object
* @param negatedAF whether the prerequisite is negated (using negation as failure)
*/
public Prerequisite prereq(Predicate predicate, Object obj1, Object obj2,boolean negatedAF) {
Class[] structure = predicate.getStructure ();
if(structure.length != 2) {
throw new IllegalArgumentException (
"Not the right number of terms for this predicate, the number is 2, but must be "
+ structure.length);
}
Term[] terms = { toTerm (obj1, structure[0]),
toTerm (obj2, structure[1]) };
return lfactory.createPrerequisite (predicate, terms,negatedAF);
}
/**
* Create a prerequisite with three terms.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param obj1 an object
* @param obj2 an object
* @param obj3 an object
* @param negatedAF whether the prerequisite is negated (using negation as failure)
*/
public Prerequisite prereq(Predicate predicate, Object obj1, Object obj2, Object obj3,boolean negatedAF) {
Class[] structure = predicate.getStructure ();
if(structure.length != 3) {
throw new IllegalArgumentException (
"Not the right number of terms for this predicate, the number is 3, but must be "
+ structure.length);
}
Term[] terms = { toTerm (obj1, structure[0]),
toTerm (obj2, structure[1]),
toTerm (obj3, structure[2]) };
return lfactory.createPrerequisite (predicate, terms,negatedAF);
}
/**
* Create a prerequisite with four terms.
* See <code>toTerm</code> how the object is converted to a term.
* @return the prerequisite created
* @param predicate the predicate
* @param obj1 an object
* @param obj2 an object
* @param obj3 an object
* @param obj4 an object
* @param negatedAF whether the prerequisite is negated (using negation as failure)
*/
public Prerequisite prereq(Predicate predicate, Object obj1, Object obj2,Object obj3, Object obj4,boolean negatedAF) {
Class[] structure = predicate.getStructure ();
if(structure.length != 4) {
throw new IllegalArgumentException (
"Not the right number of terms for this predicate, the number is 4, but must be "
+ structure.length);
}
Term[] terms = { toTerm (obj1, structure[0]),
toTerm (obj2, structure[1]),
toTerm (obj3, structure[2]),
toTerm (obj4, structure[3]) };
return lfactory.createPrerequisite (predicate, terms,negatedAF);
}
/**
* Create a rule with two prerequisites.
* The prerequisites are connected by OR.
* @return the rule created
* @param prerequisite1 a prerequisite
* @param prerequisite2 a prerequisite
* @param conclusion the concusion of the rule
* @deprecated use Prerequisite instead of Fact to build rules
*/
public Rule orRule(Fact prerequisite1, Fact prerequisite2,Fact conclusion) {
Vector body = new Vector ();
body.add (fact2prereq(prerequisite1));
body.add (fact2prereq(prerequisite2));
return lfactory.createRule (body, conclusion, true);
}
/**
* Create a rule with three prerequisites.
* The prerequisites are connected by OR.
* @return the rule created
* @param prerequisite1 a prerequisite
* @param prerequisite2 a prerequisite
* @param prerequisite3 a prerequisite
* @param conclusion the concusion of the rule
* @deprecated use Prerequisite instead of Fact to build rules
*/
public Rule orRule(Fact prerequisite1, Fact prerequisite2,Fact prerequisite3, Fact conclusion) {
Vector body = new Vector ();
body.add (fact2prereq(prerequisite1));
body.add (fact2prereq(prerequisite2));
body.add (fact2prereq(prerequisite3));
return lfactory.createRule (body, conclusion, true);
}
/**
* Create a rule with four prerequisites.
* The prerequisites are connected by OR.
* @return the rule created
* @param prerequisite1 a prerequisite
* @param prerequisite2 a prerequisite
* @param prerequisite3 a prerequisite
* @param prerequisite4 a prerequisite
* @param conclusion the concusion of the rule
* @deprecated use Prerequisite instead of Fact to build rules
*/
public Rule orRule(Fact prerequisite1, Fact prerequisite2,Fact prerequisite3, Fact prerequisite4,Fact conclusion) {
Vector body = new Vector ();
body.add (fact2prereq(prerequisite1));
body.add (fact2prereq(prerequisite2));
body.add (fact2prereq(prerequisite3));
body.add (fact2prereq(prerequisite4));
return lfactory.createRule (body, conclusion, true);
}
/**
* Create a rule.
* @return the rule created
* @param body the prerequisites of the rule
* @param conclusion the concusion of the rule
*/
public Rule rule(List body, Fact conclusion) {
return lfactory.createRule (body, conclusion);
}
/**
* Create a rule with no prerequisites.
* @return the rule created
* @param conclusion the concusion of the rule
*/
public Rule rule(Fact conclusion) {
Vector body = new Vector ();
return lfactory.createRule (body, conclusion);
}
/**
* Create a rule with one prerequisite.
* @return the rule created
* @param prerequisite a prerequisite
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?