gpt4 book ai didi

java - JESS异常: expected method name

转载 作者:太空宇宙 更新时间:2023-11-04 10:47:52 25 4
gpt4 key购买 nike

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

Stacktrace

这是代码:

// 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))");

这是 Door 和 Light 两个类:

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和Door中定义的。谢谢。

最佳答案

“call”的第一个参数可以是调用方法的对象,也可以是静态方法的类名称。将 Door 对象绑定(bind)到一个变量(位于 OBJECT 槽中),然后将该变量作为第一个参数传递。

关于java - JESS异常: expected method name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48191378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com