Reputation: 83
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.
Upvotes: 0
Views: 264
Reputation: 10757
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>
Upvotes: 1