有没有办法从文本文件中读取数据并将其转换为drl文件?

时间:2017-04-28 07:48:38

标签: java drools

这是我的文字档案。

Success
product
If the price of the product is greater than 100 and quantity less than 2 and category is "grocery" 
Then display the discount is 100  

我读取了这些行并将它们分配给变量,但我们如何将其更改为drl文件。

import java.io.*;
import java.util.*; 
public class Read {
  public static void main(String[] args) throws Exception {
    File file=new File("demo.txt");
    Scanner s=new Scanner(file);
    while(s.hasNextLine()) { 
     String rule = s.nextLine();
     String object = s.nextLine();
     String condition=s.nextLine();
     String consequence=s.nextLine();
     Product p=new Product();
     p.setRule(rule);
     p.setObject(object);
     p.setCondition(condition);
     p.setConsequence(consequence);
     s.close();
    }
  }
}

1 个答案:

答案 0 :(得分:0)

不,不是你想要的方式。

您可以查看域特定语言(DSL)以及如何在Drools中使用它。

但如果仅仅是一到十条这样的规则,那么只需用DRL编写它们就会更好。

<div className="row-wrap">
    <span>Mon</span>
    <input name="1_min" onChange={this.handleAdvancePrice} type="text" />
    <input name="1_max" onChange={this.handleAdvancePrice} type="text" />
</div>
<div className="row-wrap">
    <span>Tue</span>
    <input name="2_min" onChange={this.handleAdvancePrice} type="text" />
    <input name="2_max" onChange={this.handleAdvancePrice} type="text" />
</div>

<button onClick={this.showStates}></button>

..
..

handleAdvancePrice = (e) => {

    let dow = e.target.name.split('_')[0],
    type = e.target.name.split('_')[1],
    value = +(e.target.value);

    console.log(dow, type) // it print correctly

    this.setState = ({
        [`advancePrice_${dow}_${type}`]: value
    })
}

showStates = () => {
    console.log(this.state) //error this.setState is not a function, caused by handleAdvancePrice
}

(注意:Java程序没有多大意义。)