Inference taking forever, any suggestions?

Thanks to the update of typdeDB, I can use utf-8 as the variable name. Below is a complicated schema and related inserted data. When doing inference, it taks forever. After waiting for 15 mins, the studio is still runnnig and I can’t get the final answer. When checking the usage of CPU, it’s around 20%. Some unusual part of the below case is that, it used a lot of rules to define the dynamic relationships. I’m not sure whether or not it’s the reason of the slow inference.

My question is:

  1. For your experience, how long could it take to do inference for complicated case? A hour?
  2. What should I do to accelerate the process? Changing the schema structure?

schema:

define

ID sub attribute, value string;

x sub attribute, value long, owns ID;
y sub attribute, value long, owns ID;
z sub attribute, value long, owns ID;

人名 sub attribute, value string, owns ID;
性别 sub attribute, value string, owns ID, regex "^(男|女)$";
命主 sub entity, owns ID, owns 人名, owns 性别;

五行 sub attribute, value string, owns ID, regex "^(木|火|土|金|水)$";
阴阳 sub attribute, value string, owns ID, regex "^(阴|阳)$";
生旺 sub attribute, value string, owns ID, regex "^(沐|冠|禄|旺|衰|病|死|墓|绝|胎|养|长)$";

干 sub attribute, value string, owns ID, regex "^(甲|乙|丙|丁|戊|己|庚|辛|壬|癸)$", owns 五行, owns 阴阳;

支 sub attribute, value string, owns ID, regex "^(子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥)$", owns 五行, owns 阴阳;

气 sub attribute, value string, owns ID, regex "^(本|中|余)$";

藏干 sub attribute, value string, owns ID, regex "^(甲|乙|丙|丁|戊|己|庚|辛|壬|癸)$", owns 五行, owns 阴阳, owns 气;

十神 sub attribute, value string, owns ID, regex "^(劫|比|伤|食|财|才|官|杀|印|枭)$";

藏干十神 sub attribute, value string, owns ID, regex "^(劫|比|伤|食|财|才|官|杀|印|枭)$", owns 气;

柱位 sub entity, owns ID, owns x, owns y, owns z;

天干 sub 柱位, owns 干, owns 十神,
    plays 两两相邻:相邻,
    plays 三连相邻:相邻;

地支 sub 柱位, owns 支, owns 生旺, owns 藏干, owns 藏干十神,
    plays 两两相邻:相邻,
    plays 三连相邻:相邻;

年干 sub 天干;
月干 sub 天干;
日主 sub 天干;
时干 sub 天干;
年支 sub 地支;
月令 sub 地支;
日支 sub 地支;
时支 sub 地支;

### 位置关系
两两相邻 sub relation, owns ID, relates 相邻;
三连相邻 sub relation, owns ID, relates 相邻;

天干五合 sub 两两相邻,
    relates 甲己五合土,
    relates 乙庚五合金,
    relates 丙辛五合水,
    relates 丁壬五合木,
    relates 戊癸五合火;

天干四冲 sub 两两相邻,
    relates 甲庚四冲,
    relates 乙辛四冲,
    relates 壬丙四冲,
    relates 癸丁四冲;

地支半三合 sub 两两相邻,
    relates 申子半三合水,
    relates 子辰半三合水,
    relates 亥卯半三合木,
    relates 卯未半三合木,
    relates 寅午半三合火,
    relates 午戌半三合火,
    relates 巳酉半三合金,
    relates 酉丑半三合金;

地支六合 sub 两两相邻,
    relates 巳申六合水,
    relates 寅亥六合木,
    relates 卯戌六合火,
    relates 午未六合土,
    relates 午未六合火,
    relates 子丑六合土,
    relates 辰酉六合金;

地支拱合 sub 两两相邻,
    relates 申辰拱合水,
    relates 亥未拱合木,
    relates 寅戌拱合火,
    relates 巳丑拱合金;

地支自刑 sub 两两相邻,
    relates 午午自刑,
    relates 酉酉自刑,
    relates 辰辰自刑,
    relates 亥亥自刑;

地支六冲 sub 两两相邻,
    relates 寅申六冲,
    relates 巳亥六冲,
    relates 辰戌六冲,
    relates 子午六冲,
    relates 丑未六冲,
    relates 卯酉六冲;

地支六害 sub 两两相邻,
    relates 寅巳六害,
    relates 申亥六害,
    relates 酉戌六害,
    relates 子未六害,
    relates 丑午六害,
    relates 卯辰六害;

地支六破 sub 两两相邻,
    relates 子酉六破,
    relates 寅亥六破,
    relates 卯午六破,
    relates 辰丑六破,
    relates 巳申六破,
    relates 未戌六破;

地支三刑 sub 三连相邻,
    relates 子卯三刑,
    relates 丑未戌三刑,
    relates 寅巳申三刑;

地支三会 sub 三连相邻,
    relates 亥子丑三会水,
    relates 寅卯辰三会木,
    relates 巳午未三会火,
    relates 申酉戌三会金,
    relates 寅午戌三合火,
    relates 申子辰三合水,
    relates 亥卯未三合木,
    relates 巳酉丑三合金;

#===============================================
#天干五合 
甲己五合土 sub 天干五合;
乙庚五合金 sub 天干五合;
丙辛五合水 sub 天干五合;
丁壬五合木 sub 天干五合;
戊癸五合火 sub 天干五合;

#天干四冲  
甲庚四冲 sub 天干四冲;
乙辛四冲 sub 天干四冲;
壬丙四冲 sub 天干四冲;
癸丁四冲 sub 天干四冲;

#地支半三合  
申子半三合水 sub 地支半三合;
子辰半三合水 sub 地支半三合;
亥卯半三合木 sub 地支半三合;
卯未半三合木 sub 地支半三合;
寅午半三合火 sub 地支半三合;
午戌半三合火 sub 地支半三合;
巳酉半三合金 sub 地支半三合;
酉丑半三合金 sub 地支半三合;

#地支六合  
巳申六合水 sub 地支六合;
寅亥六合木 sub 地支六合;
卯戌六合火 sub 地支六合;
午未六合土 sub 地支六合;
午未六合火 sub 地支六合;
子丑六合土 sub 地支六合;
辰酉六合金 sub 地支六合;

#地支拱合 
申辰拱合水 sub 地支拱合;
亥未拱合木 sub 地支拱合;
寅戌拱合火 sub 地支拱合;
巳丑拱合金 sub 地支拱合;

#地支自刑  
午午自刑 sub 地支自刑;
酉酉自刑 sub 地支自刑;
辰辰自刑 sub 地支自刑;
亥亥自刑 sub 地支自刑;

#地支六冲  
寅申六冲 sub 地支六冲;
巳亥六冲 sub 地支六冲;
辰戌六冲 sub 地支六冲;
子午六冲 sub 地支六冲;
丑未六冲 sub 地支六冲;
卯酉六冲 sub 地支六冲;

#地支六害 
寅巳六害 sub 地支六害;
申亥六害 sub 地支六害;
酉戌六害 sub 地支六害;
子未六害 sub 地支六害;
丑午六害 sub 地支六害;
卯辰六害 sub 地支六害;

#地支六破  
子酉六破 sub 地支六破;
寅亥六破 sub 地支六破;
卯午六破 sub 地支六破;
辰丑六破 sub 地支六破;
巳申六破 sub 地支六破;
未戌六破 sub 地支六破;

#地支三刑 
子卯三刑   sub 地支三刑;
丑未戌三刑 sub 地支三刑;
寅巳申三刑 sub 地支三刑;

#地支三会  
亥子丑三会水 sub 地支三会;
寅卯辰三会木 sub 地支三会;
巳午未三会火 sub 地支三会;
申酉戌三会金 sub 地支三会;
寅午戌三合火 sub 地支三会;
申子辰三合水 sub 地支三会;
亥卯未三合木 sub 地支三会;
巳酉丑三合金 sub 地支三会;


### 两两相邻
rule 是天干两两相邻01: when {
    $z1 isa 天干, has x $x1;
    $z2 isa 天干, has x $x2;
    $x1 = 0; $x2 = 1;
} then {
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
};
rule 是天干两两相邻12: when {
    $z1 isa 天干, has x $x1;
    $z2 isa 天干, has x $x2;
    $x1 = 1; $x2 = 2;
} then {
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
};
rule 是天干两两相邻23: when {
    $z1 isa 天干, has x $x1;
    $z2 isa 天干, has x $x2;
    $x1 = 2; $x2 = 3;
} then {
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
};

rule 是地支两两相邻01: when {
    $z1 isa 地支, has x $x1;
    $z2 isa 地支, has x $x2;
    $x1 = 0; $x2 = 1;
} then {
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
};
rule 是地支两两相邻12: when {
    $z1 isa 地支, has x $x1;
    $z2 isa 地支, has x $x2;
    $x1 = 1; $x2 = 2;
} then {
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
};
rule 是地支两两相邻23: when {
    $z1 isa 地支, has x $x1;
    $z2 isa 地支, has x $x2;
    $x1 = 2; $x2 = 3;
} then {
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
};

### 三连相邻
rule 是天干三连相邻012: when {
    $z1 isa 天干, has x $x1;
    $z2 isa 天干, has x $x2;
    $z3 isa 天干, has x $x3;
    $x1 = 0; $x2 = 1; $x3 = 2;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
};
rule 是天干三连相邻123: when {
    $z1 isa 天干, has x $x1;
    $z2 isa 天干, has x $x2;
    $z3 isa 天干, has x $x3;
    $x1 = 1; $x2 = 2; $x3 = 3;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
};

rule 是地支三连相邻012: when {
    $z1 isa 地支, has x $x1;
    $z2 isa 地支, has x $x2;
    $z3 isa 地支, has x $x3;
    $x1 = 0; $x2 = 1; $x3 = 2;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
};
rule 是地支三连相邻123: when {
    $z1 isa 地支, has x $x1;
    $z2 isa 地支, has x $x2;
    $z3 isa 地支, has x $x3;
    $x1 = 1; $x2 = 2; $x3 = 3;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
};

##==============================================   刑冲合害规则  ====================================================================

### 天干五合
rule 是甲己五合土: when {
    $z1 isa 天干, has 干 $a1;    
    $a1 like "(甲|己)";
    $z2 isa 天干, has 干 $a2;    
    $a2 like "(甲|己)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 甲己五合土;
};

rule 是乙庚五合金: when {
    $z1 isa 天干, has 干 $a1; $a1 like "(乙|庚)";
    $z2 isa 天干, has 干 $a2; $a2 like "(乙|庚)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 乙庚五合金;
};

rule 是丙辛五合水: when {
    $z1 isa 天干, has 干 $a1; $a1 like "(丙|辛)";
    $z2 isa 天干, has 干 $a2; $a2 like "(丙|辛)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 丙辛五合水;
};

rule 是丁壬五合木: when {
    $z1 isa 天干, has 干 $a1; $a1 like "(丁|壬)";
    $z2 isa 天干, has 干 $a2; $a2 like "(丁|壬)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 丁壬五合木;
};

rule 是戊癸五合火: when {
    $z1 isa 天干, has 干 $a1; $a1 like "(戊|癸)";
    $z2 isa 天干, has 干 $a2; $a2 like "(戊|癸)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 戊癸五合火;
};

### 天干四冲
rule 是甲庚四冲: when {
    $z1 isa 天干, has 干 $a1; $a1 like "(甲|庚)";
    $z2 isa 天干, has 干 $a2; $a2 like "(甲|庚)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 甲庚四冲;
};

rule 是乙辛四冲: when {
    $z1 isa 天干, has 干 $a1; $a1 like "(乙|辛)";
    $z2 isa 天干, has 干 $a2; $a2 like "(乙|辛)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 乙辛四冲;
};

rule 是壬丙四冲: when {
    $z1 isa 天干, has 干 $a1; $a1 like "(壬|丙)";
    $z2 isa 天干, has 干 $a2; $a2 like "(壬|丙)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 壬丙四冲;
};

rule 是癸丁四冲: when {
    $z1 isa 天干, has 干 $a1; $a1 like "(癸|丁)";
    $z2 isa 天干, has 干 $a2; $a2 like "(癸|丁)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 癸丁四冲;
};



### 地支半三合
rule 是申子半三合水: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(申|子)";
    $z2 isa 地支, has 支 $a2; $a2 like "(申|子)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 申子半三合水;
};

rule 是子辰半三合水: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(子|辰)";
    $z2 isa 地支, has 支 $a2; $a2 like "(子|辰)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 子辰半三合水;
};

rule 是亥卯半三合木: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(亥|卯)";
    $z2 isa 地支, has 支 $a2; $a2 like "(亥|卯)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 亥卯半三合木;
};

rule 是卯未半三合木: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(卯|未)";
    $z2 isa 地支, has 支 $a2; $a2 like "(卯|未)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 卯未半三合木;
};

rule 是寅午半三合火: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(寅|午)";
    $z2 isa 地支, has 支 $a2; $a2 like "(寅|午)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 寅午半三合火;
};

rule 是午戌半三合火: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(午|戌)";
    $z2 isa 地支, has 支 $a2; $a2 like "(午|戌)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 午戌半三合火;
};

rule 是巳酉半三合金: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(巳|酉)";
    $z2 isa 地支, has 支 $a2; $a2 like "(巳|酉)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 巳酉半三合金;
};

rule 是酉丑半三合金: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(酉|丑)";
    $z2 isa 地支, has 支 $a2; $a2 like "(酉|丑)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 酉丑半三合金;
};

### 地支六合
rule 是巳申六合水: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(巳|申)";
    $z2 isa 地支, has 支 $a2; $a2 like "(巳|申)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 巳申六合水;
};

rule 是寅亥六合木: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(寅|亥)";
    $z2 isa 地支, has 支 $a2; $a2 like "(寅|亥)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 寅亥六合木;
};

rule 是卯戌六合火: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(卯|戌)";
    $z2 isa 地支, has 支 $a2; $a2 like "(卯|戌)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 卯戌六合火;
};

rule 是午未六合土: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(午|未)";
    $z2 isa 地支, has 支 $a2; $a2 like "(午|未)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 午未六合土;
};

rule 是午未六合火: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(午|未)";
    $z2 isa 地支, has 支 $a2; $a2 like "(午|未)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 午未六合火;
};

rule 是子丑六合土: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(子|丑)";
    $z2 isa 地支, has 支 $a2; $a2 like "(子|丑)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 子丑六合土;
};

rule 是辰酉六合金: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(辰|酉)";
    $z2 isa 地支, has 支 $a2; $a2 like "(辰|酉)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 辰酉六合金;
};

### 地支拱合
rule 是申辰拱合水: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(申|辰)";
    $z2 isa 地支, has 支 $a2; $a2 like "(申|辰)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 申辰拱合水;
};

rule 是亥未拱合木: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(亥|未)";
    $z2 isa 地支, has 支 $a2; $a2 like "(亥|未)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 亥未拱合木;
};

rule 是寅戌拱合火: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(寅|戌)";
    $z2 isa 地支, has 支 $a2; $a2 like "(寅|戌)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 寅戌拱合火;
};

rule 是巳丑拱合金: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(巳|丑)";
    $z2 isa 地支, has 支 $a2; $a2 like "(巳|丑)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 巳丑拱合金;
};

### 地支自刑
rule 是午午自刑: when {
    $z1 isa 地支, has 支 $a1; $a1 "午";
    $z2 isa 地支, has 支 $a2; $a2 "午";
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 午午自刑;
};

rule 是酉酉自刑: when {
    $z1 isa 地支, has 支 $a1; $a1 "酉";
    $z2 isa 地支, has 支 $a2; $a2 "酉";
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 酉酉自刑;
};

rule 是辰辰自刑: when {
    $z1 isa 地支, has 支 $a1; $a1 "辰";
    $z2 isa 地支, has 支 $a2; $a2 "辰";
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 辰辰自刑;
};

rule 是亥亥自刑: when {
    $z1 isa 地支, has 支 $a1; $a1 "亥";
    $z2 isa 地支, has 支 $a2; $a2 "亥";
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 亥亥自刑;
};

### 地支六冲
rule 是寅申六冲: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(寅|申)";
    $z2 isa 地支, has 支 $a2; $a2 like "(寅|申)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 寅申六冲;
};

rule 是巳亥六冲: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(巳|亥)";
    $z2 isa 地支, has 支 $a2; $a2 like "(巳|亥)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 巳亥六冲;
};

rule 是辰戌六冲: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(辰|戌)";
    $z2 isa 地支, has 支 $a2; $a2 like "(辰|戌)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 辰戌六冲;
};

rule 是子午六冲: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(子|午)";
    $z2 isa 地支, has 支 $a2; $a2 like "(子|午)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 子午六冲;
};

rule 是丑未六冲: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(丑|未)";
    $z2 isa 地支, has 支 $a2; $a2 like "(丑|未)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 丑未六冲;
};

rule 是卯酉六冲: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(卯|酉)";
    $z2 isa 地支, has 支 $a2; $a2 like "(卯|酉)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 卯酉六冲;
};

### 地支六害
rule 是寅巳六害: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(寅|巳)";
    $z2 isa 地支, has 支 $a2; $a2 like "(寅|巳)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 寅巳六害;
};

rule 是申亥六害: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(申|亥)";
    $z2 isa 地支, has 支 $a2; $a2 like "(申|亥)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 申亥六害;
};

rule 是酉戌六害: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(酉|戌)";
    $z2 isa 地支, has 支 $a2; $a2 like "(酉|戌)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 酉戌六害;
};

rule 是子未六害: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(子|未)";
    $z2 isa 地支, has 支 $a2; $a2 like "(子|未)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 子未六害;
};

rule 是丑午六害: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(丑|午)";
    $z2 isa 地支, has 支 $a2; $a2 like "(丑|午)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 丑午六害;
};

rule 是卯辰六害: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(卯|辰)";
    $z2 isa 地支, has 支 $a2; $a2 like "(卯|辰)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 卯辰六害;
};

### 地支六破
rule 是子酉六破: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(子|酉)";
    $z2 isa 地支, has 支 $a2; $a2 like "(子|酉)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 子酉六破;
};

rule 是寅亥六破: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(寅|亥)";
    $z2 isa 地支, has 支 $a2; $a2 like "(寅|亥)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 寅亥六破;
};

rule 是卯午六破: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(卯|午)";
    $z2 isa 地支, has 支 $a2; $a2 like "(卯|午)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 卯午六破;
};

rule 是辰丑六破: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(辰|丑)";
    $z2 isa 地支, has 支 $a2; $a2 like "(辰|丑)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 辰丑六破;
};

rule 是巳申六破: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(巳|申)";
    $z2 isa 地支, has 支 $a2; $a2 like "(巳|申)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 巳申六破;
};

rule 是未戌六破: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(未|戌)";
    $z2 isa 地支, has 支 $a2; $a2 like "(未|戌)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 未戌六破;
};



### 地支三刑
rule 是子卯三刑: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(子|卯)";
    $z2 isa 地支, has 支 $a2; $a2 like "(子|卯)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 子卯三刑;
};

rule 是丑未戌三刑: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(丑|未|戌)";
    $z2 isa 地支, has 支 $a2; $a2 like "(丑|未|戌)";
    $z3 isa 地支, has 支 $a3; $a1 like "(丑|未|戌)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 丑未戌三刑;
};

rule 是寅巳申三刑: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(寅|巳|申)";
    $z2 isa 地支, has 支 $a2; $a2 like "(寅|巳|申)";
    $z3 isa 地支, has 支 $a3; $a3 like "(寅|巳|申)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 寅巳申三刑;
};

#### 地支三会
rule 是亥子丑三会水: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(亥|子|丑)";
    $z2 isa 地支, has 支 $a2; $a2 like "(亥|子|丑)";
    $z3 isa 地支, has 支 $a3; $a3 like "(亥|子|丑)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 亥子丑三会水;
};

rule 是寅卯辰三会木: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(寅|卯|辰)";
    $z2 isa 地支, has 支 $a2; $a2 like "(寅|卯|辰)";
    $z3 isa 地支, has 支 $a3; $a3 like "(寅|卯|辰)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 寅卯辰三会木;
};

rule 是巳午未三会火: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(巳|午|未)";
    $z2 isa 地支, has 支 $a2; $a2 like "(巳|午|未)";
    $z3 isa 地支, has 支 $a3; $a3 like "(巳|午|未)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 巳午未三会火;
};

rule 是申酉戌三会金: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(申|酉|戌)";
    $z2 isa 地支, has 支 $a2; $a2 like "(申|酉|戌)";
    $z3 isa 地支, has 支 $a3; $a3 like "(申|酉|戌)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 申酉戌三会金;
};

### 地支三合
rule 是寅午戌三合火: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(寅|午|戌)";
    $z2 isa 地支, has 支 $a2; $a2 like "(寅|午|戌)";
    $z3 isa 地支, has 支 $a3; $a3 like "(寅|午|戌)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 寅午戌三合火;
};

rule 是申子辰三合水: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(申|子|辰)";
    $z2 isa 地支, has 支 $a2; $a2 like "(申|子|辰)";
    $z3 isa 地支, has 支 $a3; $a3 like "(申|子|辰)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 申子辰三合水;
};

rule 是亥卯未三合木: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(亥|卯|未)";
    $z2 isa 地支, has 支 $a2; $a2 like "(亥|卯|未)";
    $z3 isa 地支, has 支 $a3; $a3 like "(亥|卯|未)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 亥卯未三合木;
};

rule 是巳酉丑三合金: when {
    $z1 isa 地支, has 支 $a1; $a1 like "(巳|酉|丑)";
    $z2 isa 地支, has 支 $a2; $a2 like "(巳|酉|丑)";
    $z3 isa 地支, has 支 $a3; $a3 like "(巳|酉|丑)";
    $a1 != $a2; $a2 != $a3; $a1 != $a3;
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 三连相邻;
} then {
    (相邻: $z1, 相邻: $z2, 相邻: $z3) isa 巳酉丑三合金;
};

data:

insert $v1 isa ID; $v1 "sz"; $v2 isa 人名; $v2 "宋先生"; $v2 has ID "sz"; $v3 isa 性别; $v3 "男"; $v3 has ID "sz"; $e isa 命主, has ID $v1, has 人名 $v2, has 性别 $v3;

insert  $yy isa 阴阳; $yy "阴"; $yy has ID "sz"; 
        $wx isa 五行; $wx "金"; $wx has ID "sz"; 
        $g isa 干; $g "辛"; $g has ID "sz", has 阴阳 $yy, has 五行 $wx; 
        $x isa x; $x 0; $x has ID "sz"; 
        $y isa y; $y 0; $y has ID "sz"; 
        $z isa z; $z 0; $z has ID "sz"; 
        $ss isa 十神; $ss "财"; $ss has ID "sz"; 
        $e isa 年干, has ID "sz", has 干 $g, has x $x, has y $y, has z $z, has 十神 $ss;
        
insert $yy isa 阴阳; $yy "阳"; $yy has ID "sz"; $wx isa 五行; $wx "水"; $wx has ID "sz"; $g isa 干; $g "壬"; $g has ID "sz", has 阴阳 $yy, has 五行 $wx; $x isa x; $x 1; $x has ID "sz"; $y isa y; $y 0; $y has ID "sz"; $z isa z; $z 0; $z has ID "sz"; $ss isa 十神; $ss "杀"; $ss has ID "sz"; $e isa 月干, has ID "sz", has 干 $g, has x $x, has y $y, has z $z, has 十神 $ss;
insert $yy isa 阴阳; $yy "阳"; $yy has ID "sz"; $wx isa 五行; $wx "火"; $wx has ID "sz"; $g isa 干; $g "丙"; $g has ID "sz", has 阴阳 $yy, has 五行 $wx; $x isa x; $x 2; $x has ID "sz"; $y isa y; $y 0; $y has ID "sz"; $z isa z; $z 0; $z has ID "sz"; $ss isa 十神; $ss "比"; $ss has ID "sz"; $e isa 日主, has ID "sz", has 干 $g, has x $x, has y $y, has z $z, has 十神 $ss;
insert $yy isa 阴阳; $yy "阳"; $yy has ID "sz"; $wx isa 五行; $wx "火"; $wx has ID "sz"; $g isa 干; $g "丙"; $g has ID "sz", has 阴阳 $yy, has 五行 $wx; $x isa x; $x 3; $x has ID "sz"; $y isa y; $y 0; $y has ID "sz"; $z isa z; $z 0; $z has ID "sz"; $ss isa 十神; $ss "比"; $ss has ID "sz"; $e isa 时干, has ID "sz", has 干 $g, has x $x, has y $y, has z $z, has 十神 $ss;

insert $yy isa 阴阳; $yy "阴"; $yy has ID "sz"; $wx isa 五行; $wx "金"; $wx has ID "sz"; $zhi isa 支; $zhi "酉"; $zhi has ID "sz", has 阴阳 $yy, has 五行 $wx; 
$x isa x; $x 0; $x has ID "sz"; $y isa y; $y 1; $y has ID "sz"; $z isa z; $z 0; $z has ID "sz"; $sw isa 生旺; $sw "死"; $sw has ID "sz"; 
$yy isa 阴阳; $yy "阴"; $yy has ID "sz"; $wx isa 五行; $wx "金"; $wx has ID "sz"; $cg isa 藏干; $cg "辛"; $cg has ID "sz", has 阴阳 $yy, has 五行 $wx; 
$q isa 气; $q "本"; $q has ID "sz"; $cgss isa 藏干十神; $cgss "比"; $cgss has ID "sz", has 气 $q;
$e isa 年支, has ID "sz", has 支 $zhi, has x $x, has y $y, has z $z, has 生旺 $sw, has 藏干 $cg, has 藏干十神 $cgss;


insert $yy isa 阴阳; $yy "阳"; $yy has ID "sz"; $wx isa 五行; $wx "土"; $wx has ID "sz"; $zhi isa 支; $zhi "辰"; $zhi has ID "sz", has 阴阳 $yy, has 五行 $wx; 
$x isa x; $x 1; $x has ID "sz"; $y isa y; $y 1; $y has ID "sz"; $z isa z; $z 0; $z has ID "sz"; $sw isa 生旺; $sw "冠"; $sw has ID "sz"; 
$yy1 isa 阴阳; $yy1 "阳"; $yy1 has ID "sz"; $wx1 isa 五行; $wx1 "土"; $wx1 has ID "sz"; $cg1 isa 藏干; $cg1 "戊"; $cg1 has ID "sz", has 阴阳 $yy1, has 五行 $wx1; 
$q1 isa 气; $q1 "本"; $q1 has ID "sz"; $cgss1 isa 藏干十神; $cgss1 "食"; $cgss1 has ID "sz", has 气 $q1;
$yy2 isa 阴阳; $yy2 "阴"; $yy2 has ID "sz"; $wx2 isa 五行; $wx2 "木"; $wx2 has ID "sz"; $cg2 isa 藏干; $cg2 "乙"; $cg2 has ID "sz", has 阴阳 $yy2, has 五行 $wx2; 
$q2 isa 气; $q2 "中"; $q2 has ID "sz"; $cgss2 isa 藏干十神; $cgss2 "印"; $cgss2 has ID "sz", has 气 $q2;
$yy3 isa 阴阳; $yy3 "阴"; $yy3 has ID "sz"; $wx3 isa 五行; $wx3 "水"; $wx3 has ID "sz"; $cg3 isa 藏干; $cg3 "癸"; $cg3 has ID "sz", has 阴阳 $yy3, has 五行 $wx3; 
$q3 isa 气; $q3 "余"; $q3 has ID "sz"; $cgss3 isa 藏干十神; $cgss3 "官"; $cgss3 has ID "sz", has 气 $q3;
$e isa 月令, has ID "sz", has 支 $zhi, has x $x, has y $y, has z $z, has 生旺 $sw, has 藏干 $cg1, has 藏干十神 $cgss1, has 藏干 $cg2, has 藏干十神 $cgss2, has 藏干 $cg3, has 藏干十神 $cgss3;

insert $yy isa 阴阳; $yy "阳"; $yy has ID "sz"; $wx isa 五行; $wx "土"; $wx has ID "sz"; $zhi isa 支; $zhi "辰"; $zhi has ID "sz", has 阴阳 $yy, has 五行 $wx; 
$x isa x; $x 2; $x has ID "sz"; $y isa y; $y 1; $y has ID "sz"; $z isa z; $z 0; $z has ID "sz"; $sw isa 生旺; $sw "冠"; $sw has ID "sz"; 
$yy1 isa 阴阳; $yy1 "阳"; $yy1 has ID "sz"; $wx1 isa 五行; $wx1 "土"; $wx1 has ID "sz"; $cg1 isa 藏干; $cg1 "戊"; $cg1 has ID "sz", has 阴阳 $yy1, has 五行 $wx1; 
$q1 isa 气; $q1 "本"; $q1 has ID "sz"; $cgss1 isa 藏干十神; $cgss1 "食"; $cgss1 has ID "sz", has 气 $q1;
$yy2 isa 阴阳; $yy2 "阴"; $yy2 has ID "sz"; $wx2 isa 五行; $wx2 "木"; $wx2 has ID "sz"; $cg2 isa 藏干; $cg2 "乙"; $cg2 has ID "sz", has 阴阳 $yy2, has 五行 $wx2; 
$q2 isa 气; $q2 "中"; $q2 has ID "sz"; $cgss2 isa 藏干十神; $cgss2 "印"; $cgss2 has ID "sz", has 气 $q2;
$yy3 isa 阴阳; $yy3 "阴"; $yy3 has ID "sz"; $wx3 isa 五行; $wx3 "水"; $wx3 has ID "sz"; $cg3 isa 藏干; $cg3 "癸"; $cg3 has ID "sz", has 阴阳 $yy3, has 五行 $wx3; 
$q3 isa 气; $q3 "余"; $q3 has ID "sz"; $cgss3 isa 藏干十神; $cgss3 "官"; $cgss3 has ID "sz", has 气 $q3;
$e isa 日支, has ID "sz", has 支 $zhi, has x $x, has y $y, has z $z, has 生旺 $sw, has 藏干 $cg1, has 藏干十神 $cgss1, has 藏干 $cg2, has 藏干十神 $cgss2, has 藏干 $cg3, has 藏干十神 $cgss3;

insert $yy isa 阴阳; $yy "阳"; $yy has ID "sz"; $wx isa 五行; $wx "金"; $wx has ID "sz"; $zhi isa 支; $zhi "申"; $zhi has ID "sz", has 阴阳 $yy, has 五行 $wx; 
$x isa x; $x 3; $x has ID "sz"; $y isa y; $y 1; $y has ID "sz"; $z isa z; $z 0; $z has ID "sz"; $sw isa 生旺; $sw "病"; $sw has ID "sz"; 
$yy1 isa 阴阳; $yy1 "阳"; $yy1 has ID "sz"; $wx1 isa 五行; $wx1 "金"; $wx1 has ID "sz"; $cg1 isa 藏干; $cg1 "庚"; $cg1 has ID "sz", has 阴阳 $yy1, has 五行 $wx1; 
$q1 isa 气; $q1 "本"; $q1 has ID "sz"; $cgss1 isa 藏干十神; $cgss1 "才"; $cgss1 has ID "sz", has 气 $q1;
$yy2 isa 阴阳; $yy2 "阳"; $yy2 has ID "sz"; $wx2 isa 五行; $wx2 "水"; $wx2 has ID "sz"; $cg2 isa 藏干; $cg2 "壬"; $cg2 has ID "sz", has 阴阳 $yy2, has 五行 $wx2; 
$q2 isa 气; $q2 "中"; $q2 has ID "sz"; $cgss2 isa 藏干十神; $cgss2 "杀"; $cgss2 has ID "sz", has 气 $q2;
$yy3 isa 阴阳; $yy3 "阳"; $yy3 has ID "sz"; $wx3 isa 五行; $wx3 "土"; $wx3 has ID "sz"; $cg3 isa 藏干; $cg3 "戊"; $cg3 has ID "sz", has 阴阳 $yy3, has 五行 $wx3; 
$q3 isa 气; $q3 "余"; $q3 has ID "sz"; $cgss3 isa 藏干十神; $cgss3 "食"; $cgss3 has ID "sz", has 气 $q3;
$e isa 时支, has ID "sz", has 支 $zhi, has x $x, has y $y, has z $z, has 生旺 $sw, has 藏干 $cg1, has 藏干十神 $cgss1, has 藏干 $cg2, has 藏干十神 $cgss2, has 藏干 $cg3, has 藏干十神 $cgss3;

query example:

match $r($x, $y) isa 辰辰自刑; $x has 支 $xn; $y has 支 $yn; get $r, $xn, $yn;

If this could work, it will be an exllent example usage of complated concept inference.

Thanks a lot!!

Hi Zack,
You seem to have a large number of rules which are mutually dependent. especially. E.g. a relation (相邻:$z1, 相邻:$z2) isa 两两相邻; that appears in your rule can trigger 44 other rules.
Sadly, the reasoner planner is not prepared for this kind of situation and it is taking a very long time to just construct the dependencies. I hope to optimise this in a version after 3.0

Is it possible to write the rules in a way that they do not depend on 44 other rules? I’m unfamiliar with the language so can’t read the schema to give suggestions.

I think I have an idea of what’s going on.
(1) You have many rules with the line: (相邻: $z1, 相邻: $z2) isa 两两相邻;
(2) These rules conclude a type which is a subtype of 两两相邻;

For example,
(1) under the heading 刑冲合害规则 is the rule

### 天干五合
rule 是甲己五合土: when {
    $z1 isa 天干, has 干 $a1;    
    $a1 like "(甲|己)";
    $z2 isa 天干, has 干 $a2;    
    $a2 like "(甲|己)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻; # (1) This line matches many rules
} then {
    (相邻: $z1, 相邻: $z2) isa 甲己五合土; # This type is a subtype of 两两相邻;
};

(2) I see you have many rules under the heading ### 两两相邻 which conclude 两两相邻. For example:

rule 是天干两两相邻01: when {
    $z1 isa 天干, has x $x1;
    $z2 isa 天干, has x $x2;
    $x1 = 0; $x2 = 1;
} then {
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
};

This means, all these rules are dependent on each other.
Is there a way to avoid this and make the rules less dependent on each other?

I have seen a similar schema once before.
Please tell me if my assumption is correct.

I assume you only want the line marked (A) to match only the 6 rules with then { (相邻: $z1, 相邻: $z2) isa 两两相邻; };

If so, please considering refactor to use isa! on the line (A)

### 天干五合
rule 是甲己五合土: when {
    $z1 isa 天干, has 干 $a1;    
    $a1 like "(甲|己)";
    $z2 isa 天干, has 干 $a2;    
    $a2 like "(甲|己)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa! 两两相邻; # (A) Only this line changes. `isa!` matches only the 6 rules.
} then {
    (相邻: $z1, 相邻: $z2) isa 甲己五合土; 
};

This works well, and finds a single result:
image

True. During my test, >10 rules triggered by ‘两两相邻’ will cause long running time. Actually, ‘两两相邻’ means ‘next to each other’, its about a position relation. That’s why I used x=(0, 1, 2, 3) to mark the possible position. 0-1, 1-2, 2-3 are three types of ‘两两相邻’.

Since ‘两两相邻’ is a basic and foundermental relation, most of other rules are baed on this relation, I’m not sure how to re-construct the schema to avoid multi-level nested rules.

Based on your explanation, I guess, to keep the speed performance, one-level rule is the best practice before v3. Am I right?

One way I can think of is to split the ‘两两相邻’ to 3 position marker combinations, meaning to use more one-level rules to replace the two-level rules.

rule 是甲己五合土: when {
    $z1 isa 天干, has 干 $a1;    
    $a1 like "(甲|己)";
    $z2 isa 天干, has 干 $a2;    
    $a2 like "(甲|己)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 甲己五合土;
};

change to =>

rule 是甲己五合土01: when {
    $z1 isa 天干, has 干 $a1, has x $x1, has ID $n1;
    $a1 like "(甲|己)";
    $z2 isa 天干, has 干 $a2, has x $x1, has ID $n1;
    $a2 like "(甲|己)";
    $n1 = $n2;
    $a1 != $a2;
    $x1 = 0;
    $x2 = 1;
} then {
    (相邻: $z1, 相邻: $z2) isa 甲己五合土;
};

rule 是甲己五合土12: when {
    $z1 isa 天干, has 干 $a1, has x $x1, has ID $n1;
    $a1 like "(甲|己)";
    $z2 isa 天干, has 干 $a2, has x $x1, has ID $n1;
    $a2 like "(甲|己)";
    $n1 = $n2;
    $a1 != $a2;
    $x1 = 1;
    $x2 = 2;
} then {
    (相邻: $z1, 相邻: $z2) isa 甲己五合土;
};

rule 是甲己五合土23: when {
    $z1 isa 天干, has 干 $a1, has x $x1, has ID $n1;
    $a1 like "(甲|己)";
    $z2 isa 天干, has 干 $a2, has x $x1, has ID $n1;
    $a2 like "(甲|己)";
    $n1 = $n2;
    $a1 != $a2;
    $x1 = 2;
    $x2 = 3;
} then {
    (相邻: $z1, 相邻: $z2) isa 甲己五合土;
};

Is this a good way? What do you think about it?

Thanks a lot,

rule 是甲己五合土: when {
    $z1 isa 天干, has 干 $a1;    
    $a1 like "(甲|己)";
    $z2 isa 天干, has 干 $a2;    
    $a2 like "(甲|己)";
    $a1 != $a2;
    (相邻: $z1, 相邻: $z2) isa 两两相邻;
} then {
    (相邻: $z1, 相邻: $z2) isa 甲己五合土;
};

This rule means:
for any two ‘天干’ entities next to each other, as long as one of them is 甲 or 己 and the other one is 己 or 甲, there is a relation called ‘是甲己五合土’ between them.

So I’m not sure ‘isa!’ is what I should use.

In my case, tons of relations need to be build for ‘next to each other’ entities. The reason I want to use rules to generate those relations is that I think they are sort of caculation results which will be generated dynamically, and shouldn’t be saved to graph database.

The modification you suggested should indeed work. But I think my suggestion is equivalent.

If you call level-1 rules the 6 rules concluding 两两相邻;
And level-2 rules to be the rules below line 300

##==============================================   刑冲合害规则  ====================================================================

It is ok if all the rules level-2 depends on all the rules in level-1.
The problem here is happening because all the rules in level-2 also depend on all the other rules in level-2 !!!

This is because the line (相邻: $z1, 相邻: $z2) isa 两两相邻; also unifies with the conclusion (相邻: $z1, 相邻: $z2) isa 甲己五合土; since 甲己五合土 isa subtype of 两两相邻

You’re definitely right. It took some time, but I think I got your idea, the ‘isa!’ is the best choice here. ‘isa!’ excludes the subtypes, which is a very good tool to decrease the number of unnecessary calculations.

To sum up:

  1. to construct the multi-level rules is not the problem
  2. in my case, the real problem is that there’re too much level-2 rule defined relations depending on each other, which cause N*N dependency constructing problem (takes too long)
  3. as long as to exclude those subtype relation by using ‘isa!’, everything goes smoothly

Correct me if I’m wrong.
@krishnan
Hope we can teach LLM to generate the schema for us, that would be very interesting and useful.

You’re correct. I think you understand it perfectly.

If you think the isa! solution is too restrictive, you can change your schema so that the type in the then clauses of level-2 rules are not (e.g. 甲己五合土) are not subtypes of the type you match in the when of those rules (here 两两相邻).

E.g.
level-1-两两相邻 sub 两两相邻; and then you can use this type in the then of level-1 rules and the when of level-2 rules instead of the isa!.
This may be slightly more flexible than the isa!