【问题标题】:Clips explode$ not functioning correctly when receiving input from the user收到用户输入时,剪辑爆炸 $ 无法正常工作
【发布时间】:2019-03-29 10:13:12
【问题描述】:

您好,我写了一个 defrule 来模拟命题法则,但是当我给它正确的输入时,defrule 没有触发。

我相信explode$ 可能会添加一些空格,但我不知道如何删除它们

     CLIPS (Cypher Beta 8/21/18)
CLIPS> (batch "AI taak.txt")
TRUE
CLIPS> (deftemplate andprop (slot symbol1)(slot symbol2))
CLIPS> (deftemplate orprop (slot symbol1)(slot symbol2))
CLIPS> (deftemplate implies (multislot premise)(multislot implication))
CLIPS> (deftemplate sentence (multislot sent))
CLIPS> 
(defrule read-from-user
=>
(printout t "Please enter a sentence: Use ~ for not and => for implies 
please " crlf)
 (bind ?response (explode$ (readline)))
(assert (sentence (sent ?response))))
CLIPS> 
(defrule negative
(sentence (sent "~" "(" "~" ?symbol ")"))
 =>
   (printout t "HI " ?symbol crlf))
CLIPS> (run)
Please enter a sentence: Use ~ for not and => for implies please 
~(~P)
CLIPS> (facts)
f-1     (sentence (sent ~ ( ~ P )))
For a total of 1 fact.

所以理论上否定规则应该触发,但它不是#t。帮助找出原因将不胜感激。谢谢

【问题讨论】:

    标签: rules clips


    【解决方案1】:

    explode$ 函数的行为在 6.4 中针对通常充当分隔符的标记进行了调整,以将它们转换为符号而不是字符串。这样做是为了分解一个字符串,然后分解结果产生一个没有额外引号的字符串。

    这是 6.3 曾经发生的情况:

             CLIPS (6.31 2/3/18)
    CLIPS> (implode$ (explode$ "~(~P)"))
    ""~" "(" "~" P ")""
    CLIPS> 
    

    这就是 6.4 发生的情况:

             CLIPS (Cypher Beta 8/21/18)
    CLIPS> (implode$ (explode$ "~(~P)"))
    "~ ( ~ P )"
    CLIPS> 
    

    你可以通过使用read-from-user规则中的replace-member$函数将符号替换为字符串来得到你之前得到的结果:

             CLIPS (Cypher Beta 8/21/18)
    CLIPS> (deftemplate sentence (multislot sent))
    CLIPS> 
    (defrule read-from-user
       =>
       (printout t "Please enter a sentence: Use ~ for not and => for implies please " crlf)
       (bind ?response (explode$ (readline)))
       (bind ?response (replace-member$ ?response "(" (sym-cat "(")))
       (bind ?response (replace-member$ ?response ")" (sym-cat ")")))
       (bind ?response (replace-member$ ?response "~" (sym-cat "~")))
       (assert (sentence (sent ?response))))
    CLIPS> (run)
    Please enter a sentence: Use ~ for not and => for implies please 
    ~(~P)
    CLIPS> (facts)
    f-1     (sentence (sent "~" "(" "~" P ")"))
    For a total of 1 fact.
    CLIPS> 
    

    【讨论】:

    • 非常感谢。如果我只输入 ~(~P) 它现在可以工作,但我希望程序接受包含此字母顺序的任何字符串。有什么办法可以更改代码以接受 _(_X) 之前或之后的任何字符串?感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    相关资源
    最近更新 更多