首页 > 解决方案 > 如何更新列表状态,以便 Rete 拾取其中添加的对象以重新评估规则

问题描述

我正在使用 IBM 8.9.2,我们有一个场景,我需要根据列表 Y 中的值创建列表 X,同时对这些值进行分组。
例如,假设我有一个城市列表,并且每个City对象(在cityList列表中)都有一个属性 - 国家。现在我想反转关系并创建一个国家列表,该列表由具有包含城市列表的国家对象组成。

我的规则是

definitions
    set 'cities' to all cities in cityList;
    set 'a city' to a city in 'cities'
    set 'countries' to all countries in countryList;
    set 'a country' to a country in 'countries'

if 
    the country code of 'a city' is the country code of 'a country'
then
     add 'a city' to the contained cities of 'a country' ; (** Assume B2X/XOM has method for adding the city to the country list)
else
      create country for 'a city' and add it to countryList ; (** Assume appropriate B2X/XOM)

将国家添加到 countryList 不会更新其对象状态,因此不会在为 cityList 的第一个城市运行规则后将其重新引入议程以重新评估规则。
因此,结果是一个国家列表,其中为每个城市创建了一个新的 Country 对象,而不是计划的分组。
我的目标是在内存中插入 cityList 和 countryList 并打开 Rete 以便模式匹配可以在内存中即时发生。

寻找有关如何实现这一目标的指示。

标签: ibm-odmrete

解决方案


我会写两个单独的规则。一个将每个城市的国家添加到国家列表中。另一个将每个城市添加到相应的国家。两种 BOM 的“添加”方法都应选中“更新对象状态”。注意:我在 ODM 不允许的规则中添加了注释。

第一条规则

definitions
    set 'the city' to a city in cityList ;

if 
    the country code of 'the city' is not one of the country codes of countryList // Assume BOM method exists
then
     add the country code of 'the city' to the country codes of countryList ; // Assume BOM method exists

第二条规则

definitions
    set 'the city' to a city in cityList ;
    set 'the country' to a country in countryList 
        where the country code of this country is the country code of 'the city';

if 
    'the city' is not one of the cities of 'the country' // Requires City.equals method
then
     add 'the city' to the cities of 'the country' ; // Assume BOM method exists

推荐阅读