0

I want to insert two variable values in a string slot of a template but I am having errors. I know about the multislot but it is giving me a dictionary output like this:

('1.', '§ 2 is amended as follows:')

But I want like this:

1. § 2 is amended as follows:

https://www.csee.umbc.edu/portal/clips/usersguide/ug4.html In this link it is written that we can assign many variables to one slot in assert but when I do this I am getting errors. I am importing clips in python in VSCode. Thank you in advance and I hope I am explaining the issue properly. These are the rules:

(defrule createlist1
        (declare (salience 91))
        (ROW (counter ?A) 
                (ID ?id)                  
                (Text ?t)
                (Path "//Document/Sect[3]/Sect/L/LI/Lbl"))
        
        =>  
        (assert (Temp (tempvalue "YES")
                        (temptext ?t))))

(defrule createlist2
        (declare (salience 91))
        (and (Temp (tempvalue "YES")
                   (temptext ?t))
        
        (ROW (counter ?A) 
                (ID ?id)                  
                (Text ?text)
                (Path "//Document/Sect[3]/Sect/L/LI/LBody/ParagraphSpan")))
        
        =>  
        (printout t " value is " ?t ?text crlf)
        (assert (WordPR (counter ?A) 
                        (structure ?id) 
                        (tag "list") 
                        (style "list") 
                        (text ?t ?text))))

These are the templates:

template_WordPR = """
        (deftemplate WordPR
            (slot counter (type INTEGER))
            (slot structure (type INTEGER))
            (slot tag (type STRING))
            (slot style (type STRING))
            (slot text (type STRING)))
        """
template_temporary = """
        (deftemplate Temp
            (slot tempvalue (type STRING))
            (slot temptext (type STRING)))
        """
template_string = """
        (deftemplate ROW
            (slot counter (type INTEGER))
            (slot ID (type INTEGER))
            (slot Text (type STRING))
            (slot Path (type STRING)))
        """

This is the error I am getting:

ERROR: The single field slot 'text' can only contain a single field value.
ANA
  • 83
  • 5
  • How are you defining `WordPR` fact? Are you using PyCLIPS or CLIPSPy? What kind of error are you getting? – noxdafox Nov 11 '21 at 13:37
  • You have not answered to all the above questions. You say "I know about the multislot but it is giving me a dictionary output ...", what do you mean? How is the Python code looking like? – noxdafox Nov 12 '21 at 07:35

1 Answers1

1

You can't put multiple values into a slot without declaring it as a multislot, but if you're dealing with strings you can concatenate the values before assigning them to the slot.

CLIPS> 
(deftemplate WordPR
   (slot counter (type INTEGER))
   (slot structure (type INTEGER))
   (slot tag (type STRING))
   (slot style (type STRING))
   (slot text (type STRING)))
CLIPS>  
(deftemplate Temp
   (slot tempvalue (type STRING))
   (slot temptext (type STRING)))
CLIPS>  
(deftemplate ROW
   (slot counter (type INTEGER))
   (slot ID (type INTEGER))
   (slot Text (type STRING))
   (slot Path (type STRING)))
CLIPS>    
(deffacts start
   (Temp (tempvalue "YES")
         (temptext "1."))
   (ROW (Text "§ 2 is amended as follows:")))
CLIPS> 
(defrule createlist2
   (declare (salience 91))
   (Temp (tempvalue "YES")
         (temptext ?t))
   (ROW (counter ?A) 
        (ID ?id)                  
        (Text ?text))
   =>  
   (assert (WordPR (counter ?A) 
                   (structure ?id) 
                   (tag "list") 
                   (style "list") 
                   (text (str-cat ?t " " ?text)))))
CLIPS> (reset)
CLIPS> (run)
CLIPS> (facts)
f-1     (Temp (tempvalue "YES") (temptext "1."))
f-2     (ROW (counter 0) (ID 0) (Text "§ 2 is amended as follows:") (Path ""))
f-3     (WordPR (counter 0) (structure 0) (tag "list") (style "list") (text "1. § 2 is amended as follows:"))
For a total of 3 facts.
CLIPS>
Gary Riley
  • 10,130
  • 2
  • 19
  • 34
  • Thank you! the str-cat is working great but in the result it is giving me all the possible combinations formats rather then only displaying result in ?t " " ?text format like it displays ?t " " ?text and also ?text " " ?t and ?t and ?text (it displays all of these) – ANA Nov 16 '21 at 12:36
  • It's not clear what the additional issue is? – Gary Riley Nov 16 '21 at 23:31
  • I want to concatenate for example "a" "b" and I use str-cat then the result it is giving me is as follows: a b ab ba rather then giving just ab – ANA Dec 17 '21 at 19:43
  • You'll need to post your code. – Gary Riley Dec 18 '21 at 18:09