使用 make_instance 时 ClipsPy 中的 Clips 空错误
Clips empty error in ClipsPy when using make_instance
我是 CLIPS 和 clipsPy 的新手。我正在尝试创建 CLIPS class
的实例
这是我在 python 环境中定义并正确构建的 class (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)
这按预期工作,但是当我尝试创建此实例时 class:
new_instance = "(ent0-0 of ENTITY-CLASS (text 'Bruce Springsteen')(confidence 1.0)(type PER))"
env.make_instance( new_instance )
我收到这个空错误:
我尝试了多种构建 new_instance 字符串的形式,但 none 有效果:
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) )"
我的语法错误在哪里?
感谢任何帮助
空错误问题可能是由于 Jupyter re-directs 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'
。在 CLIPS 中,STRING 类型在双引号内 "
.
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)
我是 CLIPS 和 clipsPy 的新手。我正在尝试创建 CLIPS class
的实例这是我在 python 环境中定义并正确构建的 class (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)
这按预期工作,但是当我尝试创建此实例时 class:
new_instance = "(ent0-0 of ENTITY-CLASS (text 'Bruce Springsteen')(confidence 1.0)(type PER))"
env.make_instance( new_instance )
我收到这个空错误:
我尝试了多种构建 new_instance 字符串的形式,但 none 有效果:
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) )"
我的语法错误在哪里? 感谢任何帮助
空错误问题可能是由于 Jupyter re-directs 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'
。在 CLIPS 中,STRING 类型在双引号内 "
.
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)