2025年专家系统--pyKE小例01

专家系统--pyKE小例01事实库 family kfb son of david bruce son of bruce thomas son of thomas frederik son of frederik hiram 规则库 fc familykrb direct father son foreach family son of son

大家好,我是讯享网,很高兴认识大家。

事实库[family.kfb]

son_of(david, bruce) son_of(bruce, thomas) son_of(thomas, frederik) son_of(frederik, hiram)

讯享网

规则库[fc_familykrb]

讯享网direct_father_son foreach family.son_of($son, $father) assert family.father_son($father, $son, ()) grand_father_son foreach family.father_son($father, $grand_son, ()) family.father_son($grand_father, $father, ()) assert family.father_son($grand_father, $grand_son, (grand)) great_grand_father_son foreach family.father_son($father, $gg_son, ()) family.father_son($gg_father, $father, ($prefix1, *$rest_prefixes)) assert family.father_son($gg_father, $gg_son,(great, $prefix1, *$rest_prefixes))

driver.py


讯享网

from pyke import knowledge_engine # 第一步. 编译pyKe资源文件 # 1..kfb files define fact bases, which are compiled into .fbc pickle files. # 2..krb files define rule bases, which are compiled into 1 to 3 .py Python source files. # 3..kqb files define question bases, which are compiled into .qbc pickle files. engine = knowledge_engine.engine(__file__) # 第二步:删除特殊情况的事实及失效所有的关系规则 engine.reset() # 第三步,激活指定的规则库 engine.activate('fc_family') # This is where the rules are run! # 第三步,获取推理生成规则 rs = engine.get_kb('family').dump_specific_facts() print(rs)

编译结果:
这里写图片描述

compiled_pyke_files.py是一个文件目录文件。
fc_familyh_fc.py是正向推荐的py源代码。
运行结果:

讯享网father_son('bruce', 'david', ()) father_son('thomas', 'bruce', ()) father_son('frederik', 'thomas', ()) father_son('hiram', 'frederik', ()) father_son('thomas', 'david', ('grand',)) father_son('frederik', 'bruce', ('grand',)) father_son('hiram', 'thomas', ('grand',)) father_son('frederik', 'david', ('great', 'grand')) father_son('hiram', 'bruce', ('great', 'grand')) father_son('hiram', 'david', ('great', 'great', 'grand'))
小讯
上一篇 2025-04-05 16:07
下一篇 2025-02-26 12:29

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/91661.html