首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用make_instance时ClipsPy中的Clips错误

使用make_instance时ClipsPy中的Clips错误
EN

Stack Overflow用户
提问于 2020-10-30 17:25:51
回答 1查看 63关注 0票数 1

我对CLIPS和clipsPy都是新手。我正在尝试创建一个CLIPS类的实例

这是我在python环境(clipsPy)中定义并正确构建的类。

代码语言:javascript
复制
ENTITIES_CLASS = """
(defclass ENTITY-CLASS (is-a INITIAL-OBJECT)
    (slot text (type STRING))
    (slot confidence (type FLOAT))
    (slot type (type SYMBOL))
)
"""
env.build(ENTITIES_CLASS)

这可以正常工作,但是当我尝试创建这个类的实例时:

代码语言:javascript
复制
new_instance = "(ent0-0 of ENTITY-CLASS (text 'Bruce Springsteen')(confidence 1.0)(type PER))"
env.make_instance( new_instance )

我得到了这个空错误:

我尝试过构建new_instance字符串的多种形式,但都没有成功:

代码语言:javascript
复制
new_instance = '(ent0-0 of ENTITY-CLASS (text "Bruce Springsteen")(confidence 1.0)(type PER))'
new_instance = "(ent0-0 of ENTITY-CLASS (text 'Bruce Springsteen') (confidence 1.0) (type PER) )"

我的语法错误在哪里?感谢您的帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-30 17:42:30

空错误问题可能是由于Jupyter重定向IO的方式造成的。

在IPython上,我得到:

代码语言:javascript
复制
In [1]: import clips                                                                                                                                                                                               

In [2]: env = clips.Environment()                                                                                                                                                                                  

In [3]: ENTITIES_CLASS = """ 
   ...: (defclass ENTITY-CLASS (is-a INITIAL-OBJECT) 
   ...:     (slot text (type STRING)) 
   ...:     (slot confidence (type FLOAT)) 
   ...:     (slot type (type SYMBOL)) 
   ...: ) 
   ...: """ 
   ...: env.build(ENTITIES_CLASS)                                                                                                                                                                                  

In [4]: env.make_instance("(ent0-0 of ENTITY-CLASS (text 'Bruce Springsteen')(confidence 1.0)(type PER))")                                                                                                         

---------------------------------------------------------------------------
CLIPSError                                Traceback (most recent call last)
<ipython-input-4-92b62ecc6bed> in <module>
----> 1 env.make_instance("(ent0-0 of ENTITY-CLASS (text 'Bruce Springsteen')(confidence 1.0)(type PER))")

/usr/local/lib/python3.6/dist-packages/clips/classes.py in make_instance(self, command)
    215         ist = lib.EnvMakeInstance(self._env, command.encode())
    216         if ist == ffi.NULL:
--> 217             raise CLIPSError(self._env)
    218 
    219         return Instance(self._env, ist)

CLIPSError: [INSFUN7] ('Bruce Springsteen') illegal for single-field slot text of instance [ent0-0] found in put-text primary in class ENTITY-CLASS. [PRCCODE4] Execution halted during the actions of message-handler put-text primary in class ENTITY-CLASS

问题出在您表示字符串'Bruce Springstreen'的方式上。在剪辑中,字符串类型在doublequotes "内。

代码语言:javascript
复制
In [4]: env.make_instance('(ent0-0 of ENTITY-CLASS (text "Bruce Springsteen")(confidence 1.0)(type PER))')                                                                                                         
Out[4]: Instance: [ent0-0] of ENTITY-CLASS (text "Bruce Springsteen") (confidence 1.0) (type PER)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64605683

复制
相关文章

相似问题

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