JESS 异常:预期的方法名称

JESS Exception: expected method name

我使用 Jess 和 Java,我想在 Jess 规则中调用一个 Java 函数,但是当我启动我的代码时,我收到以下消息:

这是代码:

// Create a Jess rule engine
    ENGINE.reset();

    // Load the rules and the templates

    //TEMPLATES
    ENGINE.eval("(deftemplate Light (declare (from-class ro.domoticbot.data.Light)))");
    ENGINE.eval("(deftemplate Door (declare (from-class ro.domoticbot.data.Door)))");

    //RULES
    ENGINE.eval("(defrule switch-light \"rule to switch light state\" (Light {lightOn == FALSE}) => "
            + "(call flip)(printout t \"the lamp is on\" crlf))");

    ENGINE.eval("(defrule open-door \"rule to open a door\" (Door {open == FALSE}) => "
            + "(call flip)(printout t \"the door is open\" crlf))");

这是两个 类 门和灯:

public class Door implements Programmable, Serializable{

private static final long serialVersionUID = 1L;
private boolean open = false;
private final Map<Integer, List<Timeslot>> timeslots = new HashMap<>();
private final String name;

public Door(String name) {
    this.name = Objects.requireNonNull(name);
}

/**
 * Change the state of the door (open / close)
 * Return the new state
 */
@Override
public void flip() {
    this.open = !this.open;
}

public boolean getOpen() {
    return open;
}


public class Light implements Programmable, Serializable {

private static final long serialVersionUID = 1L;
private boolean lightOn = false;
private final Map<Integer, List<Timeslot>> timeslots = new HashMap<>();
private final String name;

public Light(String name) {
    this.name = Objects.requireNonNull(name);
}

/**
 * Change the state of the light (light on/off).
 */
@Override
public void flip() {
    this.lightOn = !this.lightOn;
}

public boolean getLightOn() {
    return lightOn;
}

我想在规则中调用 flip() 函数,但此方法已在 类 Light and Door 中定义。 谢谢。

“call”的第一个参数要么是调用方法的对象,要么是静态方法的 class 名称。将 Door 对象绑定到一个变量(它在 OBJECT 槽中)然后将该变量作为第一个参数传递。