我正在使用 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 以便模式匹配可以在内存中即时发生。
寻找有关如何实现这一目标的指示。