TextRazor 自定义词典 - AttributeError

TextRazor Custom Dicitionary - AttributeError

发件人:https://www.textrazor.com/docs/python#Dictionary

我实现了以下代码:

client = textrazor.TextRazor("API_key", extractors=["words", "phrases", "topics", "relations","entities"])
client.set_classifiers(["textrazor_iab"])

manager = textrazor.DictionaryManager('API_key')
manager.create_dictionary({'id':'dict_ID'})

new_entity_type_data = {'type': ['cpp_developer']}
manager.add_entries('dict_ID', [{'id': 'DEV1', 'text': 'Andrei Alexandrescu', 'data':new_entity_type_data}, {'id': 'DEV2', 'text':'Bjarne Stroustrup', 'data':new_entity_type_data}])
client.set_entity_dictionaries(['dict_ID'])

response = client.analyze('Although it is very early in the process, higher-level parallelism is slated to be a key theme of the next version of C++, says Bjarne Stroustrup')

当 运行 response.entities():

时出现以下错误
AttributeError: 'NoneType' object has no attribute 'encode'

当我不使用自定义词典时,我得到以下输出:

[TextRazor Entity b'Bjarne Stroustrup' at positions [26, 27],
 TextRazor Entity b'C++' at positions [23]]

我用不同的句子和自定义词典中的不同实体对此进行了测试。 每当我添加到自定义词典的实体出现在我正在分析的句子中时,我都会遇到同样的错误。 如果我创建了一个自定义词典,但句子中没有单词是词典中的实体,则不会抛出任何错误。

这表示使用自定义词典可以识别实体,否则不会抛出错误。但由于某种原因,该实体没有数据类型。

所以我的问题可能会被翻译成;如何向添加到自定义词典的实体添加有效数据类型?

我收到了 TextRazor 的回复:

我可以重现这个,我们的 Python 客户端在打印实体时似乎确实存在错误。

打印实体时,我们会生成一个字符串,该字符串假定该实体具有 ID,而自定义实体则没有,从而导致了这个无用的错误。我们将在客户端中修复此问题。该错误仅在打印实体时出现,您仍然可以正常访问匹配的自定义实体:

for entity in response.entities():
    print(entity.matched_positions, entity.data, entity.custom_entity_id)