![](/img/trans.png)
[英]Destructure a `dict` of length one to assign its key and value to two variables in Python
[英]Clips Beginner: How to assign two variables to one template slot value without using multislot in pyclips
我想在模板的字符串槽中插入兩個變量值,但出現錯誤。 我知道多插槽,但它給了我這樣的字典輸出:
('1.', '§ 2 is amended as follows:')
但我想要這樣:
1. § 2 is amended as follows:
https://www.csee.umbc.edu/portal/clips/usersguide/ug4.html在此鏈接中寫道,我們可以將許多變量分配給 assert 中的一個插槽,但是當我這樣做時,我會收到錯誤消息。 我正在 VSCode 中的 python 中導入剪輯。 提前謝謝你,我希望我能正確解釋這個問題。 這些是規則:
(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))))
這些是模板:
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)))
"""
這是我得到的錯誤:
ERROR: The single field slot 'text' can only contain a single field value.
您不能在不將其聲明為多槽的情況下將多個值放入槽中,但是如果您正在處理字符串,則可以在將它們分配給槽之前連接這些值。
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.