【问题标题】:How to add facts through rules in Jess?Jess中如何通过规则添加事实?
【发布时间】:2015-09-22 00:42:19
【问题描述】:

我尝试阅读有关 Jess 的教程,但找不到任何有用的东西。我想建立一个程序来找出我正在谈论的乐器。

因此,如果一种乐器有弦乐,我们就知道该乐器属于弦乐或打击乐器(即钢琴)类别。我将如何编写一个规则来保存一个事实,即基于此标准该类别是打击乐还是弦乐?

我考虑过绑定,但绑定是否意味着我必须为每个潜在类别设置一个单独的变量?或者,我应该使用断言吗?

【问题讨论】:

    标签: assert rule-engine jess inference-engine


    【解决方案1】:

    这演示了如何从规则中插入一个事实来存储一组可能的类别。

    (deftemplate Instrument (slot strings))
    (deftemplate Classification (multislot category))
    (defrule cat-by-strings 
      ?i <- (Instrument (strings ?s&:(> ?s 0)))
    =>
      (assert (Classification (category STRING PERCUSSION)))
    )
    (assert (Instrument (strings 18)))
    (run)
    (facts)
    

    输出:

    f-0   (MAIN::initial-fact)
    f-1   (MAIN::Instrument (strings 18))
    f-2   (MAIN::Classification (category STRING PERCUSSION))
    For a total of 3 facts in module MAIN.
    

    使用绑定变量是无用的,因为它们仅限于规则的上下文。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多