如何更新列表状态,以便 Rete 拾取其中添加的对象以进行规则重新评估

How to update state of list so that Rete picks up the objects added therein for rules re-evaluation

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

我的规则是

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,以便模式匹配可以在内存中即时发生。

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

我会写两个单独的规则。 一个是将每个城市的国家添加到国家列表中。 另一个将每个城市添加到适当的国家。 两种 BOM 'add' 方法都应该 'Update object state' 检查。 注意:我已经在 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