Menu

Partial Pattern matching in multislot data

Help
2017-05-30
2017-05-30
  • Giovanni Adami

    Giovanni Adami - 2017-05-30

    Hallo,

    I've a deftemplate with a multislot data:

    (deftemplate IPDL-Data
    (multislot RLA))

    and I added the deffacts:

    (deffacts initial-information
    (IPDL-Data (RLA (create$ 247-252 254-255 257-258 260-262 264-266 268 270-271))))

    Furthermore I create a rule to find a data in a multislot field:

    (defrule find-rla
    ?rule <- (find-rla ?rla)
    (IPDL-Data (RLA $?s&:(member$ ?rla ?s)))
    =>
    (retract ?rule)
    (printout t "Element RLA: " ?rla crlf))

    then, after asserted the fact:

    (assert (find-rla 268))

    it works fine and CLIPS returns TRUE, but if I assert:

    (assert (find-rla 254))

    CLIPS returns FALSE because cannot found it due to a partial matching with 254-255

    How I can modify the rule to have also a partial matching?

     
  • Gary Riley

    Gary Riley - 2017-05-30
    CLIPS> 
    (deftemplate IPDL-Data
       (multislot RLA))
    CLIPS> 
    (deffacts initial-information
       (IPDL-Data (RLA (create$ 247-252 254-255 257-258 260-262 264-266 268 270-271))))
    CLIPS> 
    (defrule find-rla-partial
       ?rule <- (find-rla ?rla)
       (IPDL-Data (RLA $? ?s&:(str-index (str-cat ?rla) (str-cat ?s)) $?))
       =>
       (retract ?rule)
       (printout t "Element RLA: " ?rla " in " ?s crlf))
    CLIPS> (reset)
    CLIPS> (assert (find-rla 268) (find-rla 254) (find-rla 101))
    <Fact-4>
    CLIPS> (run)
    Element RLA: 254 in 254-255
    Element RLA: 268 in 268
    CLIPS>
    
     
  • Giovanni Adami

    Giovanni Adami - 2017-05-31

    Thank you so much

     

Log in to post a comment.