我对CLIPS和clipsPy都是新手。我正在尝试创建一个CLIPS类的实例
这是我在python环境(clipsPy)中定义并正确构建的类。
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)这可以正常工作,但是当我尝试创建这个类的实例时:
new_instance = "(ent0-0 of ENTITY-CLASS (text 'Bruce Springsteen')(confidence 1.0)(type PER))"
env.make_instance( new_instance )我得到了这个空错误:

我尝试过构建new_instance字符串的多种形式,但都没有成功:
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) )"我的语法错误在哪里?感谢您的帮助
发布于 2020-10-30 17:42:30
空错误问题可能是由于Jupyter重定向IO的方式造成的。
在IPython上,我得到:
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 "内。
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)https://stackoverflow.com/questions/64605683
复制相似问题