【问题标题】:variable bound check in a clips rule RHS剪辑规则 RHS 中的变量边界检查
【发布时间】:2015-03-31 07:12:19
【问题描述】:
checkIntfIntVlanMemberConfigRule = """
    (defrule checkSubIntfIntVlanMemberConfigRule
    (checkIntf (intf ?intf) )
    (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan          ?intVlan))
    (or (not (VlanStatus (vlan ?intVlan) (intf ?intf)) )
     ?f <- (VlanStatus (vlan ?intVlan) (intf ?intf)) )
    =>
    (if (isbound ?f) then (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf) (return 0) )
    (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf)
    )"""

在上述剪辑规则中, (isbound ?f) 的等效剪辑内置函数是什么?一般来说,如果变量绑定在 LHS 中,是否有任何内置函数可以在 RHS 中检查?

【问题讨论】:

    标签: clips


    【解决方案1】:

    没有用于确定变量是否已绑定的功能。 or 条件元素是通过为 or 中包含的每个条件元素创建规则来实现的,因此您现有的规则将转换为以下内容:

     (defrule checkSubIntfIntVlanMemberConfigRule-1
        (checkIntf (intf ?intf) )
        (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan))
        (not (VlanStatus (vlan ?intVlan) (intf ?intf)) 
        =>
        (if (isbound ?f) then (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf) (return 0) )
        (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf)
        )
    
     (defrule checkSubIntfIntVlanMemberConfigRule-2
        (checkIntf (intf ?intf) )
        (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan))
        ?f <- (VlanStatus (vlan ?intVlan) (intf ?intf)) 
        =>
        (if (isbound ?f) then (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf) (return 0) )
        (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf)
        )
    

    您需要将此作为两个单独的规则来实现,以便每个规则的 RHS 可以不同:

    (defrule checkSubIntfIntVlanMemberConfigRule-1
        (checkIntf (intf ?intf) )
        (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan))
        (not (VlanStatus (vlan ?intVlan) (intf ?intf))) 
        =>
        (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf)
        )
    
     (defrule checkSubIntfIntVlanMemberConfigRule-2
        (checkIntf (intf ?intf) )
        (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan))
        ?f <- (VlanStatus (vlan ?intVlan) (intf ?intf)) 
        =>
        (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf)
        )
    

    或者,您可以使用事实查询函数从规则的 RHS 测试事实是否存在:

      (defrule checkSubIntfIntVlanMemberConfigRule
        (checkIntf (intf ?intf) )
        (SwitchIntfConfig (intf ?intf) (switchportMode "routed") (nativeVlan ?intVlan))
        (VlanStatus (vlan ?intVlan) (intf ?intf)) 
        =>
        (if (any-factp ((?f VlanStatus)) (and (eq ?f:vlan ?intVlan) (eq ?f:intf ?intf)))
          then
          (printout t "PASS: vlanStatus exists for " ?intf " " ?intVlan crlf)
          else 
         (printout t "vlanStatus does not exist for " ?intf " " ?intVlan crlf)))
    

    【讨论】:

    • 谢谢!最后一个解决方案对我有用。我试图减少规则的数量 - 所以拆分 RHS 无济于事。我觉得用于 var bound check 的 api 有助于在 RHS 中检查一个或 CE 的子事实/子条款在 LHS 中被击中。可能还有其他有用的用例。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    相关资源
    最近更新 更多