以下是dsl的一些简单示例。让我们在WHEN块中说出真实的是" city ==" NY"",有没有办法知道,然后"然后"阻止,哪种情况属实?
rule "First Promotion"
when
m : Promotion( city == "NY" || products == "SCHERP_S" || assignedProduct == "SCHERP_XL" )
then
**//Here I have to know what was true in WHEN block. For example city value is NY.**
end
谢谢你!
答案 0 :(得分:1)
技术上不是因为你使用了||,而是可以做多个规则
rule "First Promotion_city"
when
m : Promotion( city == "NY")
then
end
rule "First Promotion_products"
when
m : Promotion( products == "SCHERP_S")
then
end
rule "First Promotion_assigned"
when
m : Promotion( assignedProduct == "SCHERP_XL")
then
end
答案 1 :(得分:1)
简单地拆分规则会产生令人不快的副作用,即要求条件的乘法(或使用规则扩展)和后果的乘法,以及代码重复的所有缺点。
更好的解决方案是使用真值推理为更加重要的值创建合适的表示。
让我们有一个
class Reason { Promotion promo; String field; String value; Public( Promotion promo, String field, String value ){...} //... }
这可以用于使用如下规则来记录析取的原因:
rule "First Promotion_city" when m : Promotion( $city: city == "NY" || "LA" ) then insertLogical( new Reason( m, "city", $city ) ); end
我添加了LA以显示可以使用一个规则处理多个值。
实际规则变为
rule "First Promotion" when m : Promotion( ) r: Reason( promo == m ) then //... access r for details end
对于多个值,析取可能为真,因此您可能会插入多个Reason事实。我不能就此提出建议,因为我不知道“整体情况”。
显然,RHS的区别需要逻辑来决定什么是真的。但在Q中,没有任何迹象表明“必须知道什么是真的”。当然,获取原始事实是直截了当的可能性。但是,将. sysuse auto, clear
(1978 Automobile Data)
. d
Contains data from C:\Program Files\Stata10\ado\base/a/auto.dta
obs: 74 1978 Automobile Data
vars: 12 13 Apr 2007 17:45
size: 3,478 (99.9% of memory free) (_dta has notes)
--------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
--------------------------------------------------------------------------------------
make str18 %-18s Make and Model
price int %8.0gc Price
mpg int %8.0g Mileage (mpg)
rep78 int %8.0g Repair Record 1978
headroom float %6.1f Headroom (in.)
trunk int %8.0g Trunk space (cu. ft.)
weight int %8.0gc Weight (lbs.)
length int %8.0g Length (in.)
turn int %8.0g Turn Circle (ft.)
displacement int %8.0g Displacement (cu. in.)
gear_ratio float %6.2f Gear Ratio
foreign byte %8.0g origin Car type
--------------------------------------------------------------------------------------
Sorted by: foreign
. ds, has(varlabel Mile*)
mpg
. findname , varlabeltext(Mile*)
mpg
. keep `r(varlist)'
. d
Contains data from C:\Program Files\Stata10\ado\base/a/auto.dta
obs: 74 1978 Automobile Data
vars: 1 13 Apr 2007 17:45
size: 444 (99.9% of memory free) (_dta has notes)
--------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
--------------------------------------------------------------------------------------
mpg int %8.0g Mileage (mpg)
--------------------------------------------------------------------------------------
Sorted by:
Note: dataset has changed since last saved
之类的值作为区别,可以方便地从地图等中选择数据。您可以随意使用。