gpt4 book ai didi

java - 流口水:不止一条规则被触发,我想打印结论(然后是部分),这可能吗?如果不是你有什么建议?

转载 作者:行者123 更新时间:2023-12-01 19:07:53 25 4
gpt4 key购买 nike

我正在尝试使用drools制作一个智能辅导系统,该系统的目的是根据每个学生的评估测试为他提供个性化的练习。完成测试后,系统会获取评估分数,并据此打印出适合的练习列表。

<小时/>

规则分为两个目的,一是选择学生级别。另一个用于根据学生的水平确定学习计划中包含哪些练习。

问题是每个级别都包含不同的练习,并且会触发多个规则。我希望程序打印与学生水平相匹配的练习列表。

package com.binod.DroolsDemo;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import org.drools.compiler.compiler.DroolsParserException;
import org.drools.compiler.compiler.PackageBuilder;
import org.drools.core.RuleBase;
import org.drools.core.RuleBaseFactory;
import org.drools.core.WorkingMemory;

public class DemoTest {

public static void main(String[] args) throws DroolsParserException, IOException {
DemoTest client = new DemoTest();
client.execteRule();
}

public void execteRule() throws DroolsParserException, IOException{
PackageBuilder builder = new PackageBuilder();
String ruleFile = "/offers.drl";
InputStream resourceAsStream = getClass().getResourceAsStream(ruleFile);

Reader ruleReader = new InputStreamReader(resourceAsStream);
builder.addPackageFromDrl(ruleReader);
org.drools.core.rule.Package rulePackage = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(rulePackage);

WorkingMemory workingMemory = ruleBase.newStatefulSession();

AssessmentLevel assessemntLevel = new AssessmentLevel();
assessemntLevel.setAssessment("Null");
workingMemory.insert(assessemntLevel);
workingMemory.fireAllRules();

System.out.println("The level for this student assessment "+assessemntLevel.getAssessment()+" is "+assessemntLevel.getLevel()+" And the excercises include "+assessemntLevel.getPersonalizedexercises());

}
}
package com.binod.DroolsDemo;

public class AssessmentLevel {

private String assessment;
private String level;
private String personalizedexercises;

public String getAssessment() {
return assessment;
}
public void setAssessment(String assessment) {
this.assessment = assessment;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public String getPersonalizedexercises() {
return personalizedexercises;
}
public void setPersonalizedexercises(String personalizedexercises) {
this.personalizedexercises = personalizedexercises;
}

}

我更新的规则文件

import com.binod.DroolsDemo.AssessmentLevel

rule "Offer for A1"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.setLevel("A1");
end
rule "Offer for A2"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.setLevel("A2");
end
rule "Offer for B1"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.setLevel("B1");
end
rule "Offer for B2"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.setLevel("B2");
end
rule "Offer for C1 "
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.setLevel("C1");
end
rule "Offer for C2"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.setLevel("C2");
end
rule "Offer for recommend"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30] AND [31-35]")
then
offerObject.setLevel("Advanced");
end
rule "Personalized Exercises Intro to Computers and Programming"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.setPersonalizedexercises("Intro Computers and Programming");
end
rule "Personalized Exercises Logic"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.setPersonalizedexercises("Logic");
end
rule "Personalized Exercises Flowcharts and Algorithms"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.setPersonalizedexercises("Flowcharts and Algorithms");
end
rule "Personalized Exercises Pseudo Code"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.setPersonalizedexercises("Pseudo Code");
end
rule "Personalized Exercises Syntax"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.setPersonalizedexercises("Syntax");
end
rule "Personalized Exercises Data Structure"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.setPersonalizedexercises("Data Structure");
end
rule "Personalized Exercises Variables "
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.setPersonalizedexercises("Variables");
end
rule "Personalized Exercises Data Types"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.setPersonalizedexercises("Data Types");
end
rule "Personalized Exercises Numbers"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.setPersonalizedexercises("Numbers");
end
rule "Personalized Exercises Casting"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.setPersonalizedexercises("Casting");
end
rule "Personalized Exercises Strings"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.setPersonalizedexercises("Strings");
end
rule "Personalized Exercises Boolean"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.setPersonalizedexercises("Boolean");
end
rule "Personalized Exercises Operators"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.setPersonalizedexercises("Operators");
end
rule "Personalized Exercises Lists"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.setPersonalizedexercises("Lists");
end
rule "Personalized Exercises If Else"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.setPersonalizedexercises("If Else");
end
rule "Personalized Exercises While Loops"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.setPersonalizedexercises("While Loops");
end
rule "Personalized Exercises Functions"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.setPersonalizedexercises("Functions");
end
rule "Personalized Exercises Arrays"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.setPersonalizedexercises("Arrays");
end
rule "Personalized Exercises Classes/Objects"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.setPersonalizedexercises("Classes/Objects");
end
rule "Personalized Exercises Dates"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.setPersonalizedexercises("Dates");
end
rule "Personalized Exercises Modules"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.setPersonalizedexercises("Modules");
end
rule "Personalized Exercises Try Accept"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.setPersonalizedexercises("Try Accept");
end
rule "Personalized Exercises User Input"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.setPersonalizedexercises(" User Input");
end
rule "Personalized Exercises String Formating "
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.setPersonalizedexercises("String Formating ");
end
rule "Personalized Exercises Database Basics "
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.setPersonalizedexercises("Database Basics ");
end
rule "Personalized Exercises SQL Basics"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.setPersonalizedexercises("SQL Basics");
end
rule "Personalized Exercises Intro to Object Oriented Programming"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.setPersonalizedexercises("Intro to Object Oriented Programming");
end
rule "Personalized Exercises Information Systems"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.setPersonalizedexercises("Intro to Information Systems");
end
rule "Personalized Exercises Recommend new courses"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30] AND [31-35]")
then
offerObject.setPersonalizedexercises("Brief about advanced courses");
end


最佳答案

根据您的问题,您希望根据某些标准为学生分配多个练习。尝试执行以下代码:

更新的评估级别:

import java.util.ArrayList;
import java.util.List;

public class AssessmentLevel {

private String assessment;
private String level;
private List<String> personalizedexercises = new ArrayList<>();

public String getAssessment() {
return assessment;
}

public void setAssessment(String assessment) {
this.assessment = assessment;
}

public String getLevel() {
return level;
}

public void setLevel(String level) {
this.level = level;
}

public List<String> getPersonalizedexercises() {
return personalizedexercises;
}

public void setPersonalizedexercises(List<String> personalizedexercises) {
this.personalizedexercises = personalizedexercises;
}

}

更新的规则文件:

rule "Offer for A1"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.setLevel("A1");
end
rule "Offer for A2"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.setLevel("A2");
end
rule "Offer for B1"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.setLevel("B1");
end
rule "Offer for B2"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.setLevel("B2");
end
rule "Offer for C1 "
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.setLevel("C1");
end
rule "Offer for C2"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.setLevel("C2");
end
rule "Offer for recommend"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30] AND [31-35]")
then
offerObject.setLevel("Advanced");
end
rule "Personalized Exercises Intro to Computers and Programming"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.getPersonalizedexercises().add("Intro Computers and Programming");
end
rule "Personalized Exercises Logic"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.getPersonalizedexercises().add("Logic");
end
rule "Personalized Exercises Flowcharts and Algorithms"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.getPersonalizedexercises().add("Flowcharts and Algorithms");
end
rule "Personalized Exercises Pseudo Code"
when
offerObject: AssessmentLevel(assessment=="Null")
then
offerObject.getPersonalizedexercises().add("Pseudo Code");
end
rule "Personalized Exercises Syntax"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.getPersonalizedexercises().add("Syntax");
end
rule "Personalized Exercises Data Structure"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.getPersonalizedexercises().add("Data Structure");
end
rule "Personalized Exercises Variables "
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.getPersonalizedexercises().add("Variables");
end
rule "Personalized Exercises Data Types"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.getPersonalizedexercises().add("Data Types");
end
rule "Personalized Exercises Numbers"
when
offerObject: AssessmentLevel(assessment=="[1-10]")
then
offerObject.getPersonalizedexercises().add("Numbers");
end
rule "Personalized Exercises Casting"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.getPersonalizedexercises().add("Casting");
end
rule "Personalized Exercises Strings"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.getPersonalizedexercises().add("Strings");
end
rule "Personalized Exercises Boolean"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.getPersonalizedexercises().add("Boolean");
end
rule "Personalized Exercises Operators"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.getPersonalizedexercises().add("Operators");
end
rule "Personalized Exercises Lists"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15]")
then
offerObject.getPersonalizedexercises().add("Lists");
end
rule "Personalized Exercises If Else"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.getPersonalizedexercises().add("If Else");
end
rule "Personalized Exercises While Loops"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.getPersonalizedexercises().add("While Loops");
end
rule "Personalized Exercises Functions"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.getPersonalizedexercises().add("Functions");
end
rule "Personalized Exercises Arrays"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20]")
then
offerObject.getPersonalizedexercises().add("Arrays");
end
rule "Personalized Exercises Classes/Objects"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.getPersonalizedexercises().add("Classes/Objects");
end
rule "Personalized Exercises Dates"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.getPersonalizedexercises().add("Dates");
end
rule "Personalized Exercises Modules"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.getPersonalizedexercises().add("Modules");
end
rule "Personalized Exercises Try Accept"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25]")
then
offerObject.getPersonalizedexercises().add("Try Accept");
end
rule "Personalized Exercises User Input"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.getPersonalizedexercises().add(" User Input");
end
rule "Personalized Exercises String Formating "
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.getPersonalizedexercises().add("String Formating ");
end
rule "Personalized Exercises Database Basics "
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.getPersonalizedexercises().add("Database Basics ");
end
rule "Personalized Exercises SQL Basics"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.getPersonalizedexercises().add("SQL Basics");
end
rule "Personalized Exercises Intro to Object Oriented Programming"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.getPersonalizedexercises().add("Intro to Object Oriented Programming");
end
rule "Personalized Exercises Information Systems"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30]")
then
offerObject.getPersonalizedexercises().add("Intro to Information Systems");
end
rule "Personalized Exercises Recommend new courses"
when
offerObject: AssessmentLevel(assessment=="[1-10] AND [11-15] AND [16-20] AND [21-25] AND [26-30] AND [31-35]")
then
offerObject.getPersonalizedexercises().add("Brief about advanced courses");
end

关于java - 流口水:不止一条规则被触发,我想打印结论(然后是部分),这可能吗?如果不是你有什么建议?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59514593/

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