首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >剪辑初学者:如何将两个变量赋给一个模板槽值,而不使用pyclips中的多槽

剪辑初学者:如何将两个变量赋给一个模板槽值,而不使用pyclips中的多槽
EN

Stack Overflow用户
提问于 2021-11-11 11:18:46
回答 1查看 64关注 0票数 0

我想在一个模板的字符串槽中插入两个变量值,但是我遇到了错误。我知道多槽,但它给我一个字典输出,如下所示:

代码语言:javascript
复制
('1.', '§ 2 is amended as follows:')

但我希望是这样的:

代码语言:javascript
复制
1. § 2 is amended as follows:

在这个链接中,我们可以将多个变量赋给assert中的一个槽,但是当我这样做的时候,我得到了错误。https://www.csee.umbc.edu/portal/clips/usersguide/ug4.html。我在VSCode中导入python中的剪辑。提前谢谢你,我希望我能正确地解释这个问题。以下是规则:

代码语言:javascript
复制
(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))))

以下是模板:

代码语言:javascript
复制
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)))
        """

这是我得到的错误:

代码语言:javascript
复制
ERROR: The single field slot 'text' can only contain a single field value.
EN

回答 1

Stack Overflow用户

发布于 2021-11-13 22:03:29

不能在不声明为多槽的情况下将多个值放入槽中,但是如果要处理字符串,则可以在将值分配给槽之前连接这些值。

代码语言:javascript
复制
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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69927395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档