0

From: https://www.textrazor.com/docs/python#Dictionary

I implemented following code:

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')

I get following error when running response.entities():

AttributeError: 'NoneType' object has no attribute 'encode'

When I don't use the custom dicitionary, I get following output:

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

I tested this with different sentences, and different entities in the custom dictionary. I get the same error every time the entity that I added to the custom dictionary occurs in the sentence I am analyzing. If I create a custom dictionary, but there are no words present in the sentence that are entities in the dictionary, there is no error thrown.

This indicates that the entity is recognized using the custom dictionary, otherwise the error wouldn't be thrown. But for some reason, this entity doesn't have a datatype.

So my question could probably be translated to; how do I add a valid data type to an entity that I add to a custom dictionary?

aze45sq6d
  • 876
  • 3
  • 11
  • 26

1 Answers1

0

I got a response from TextRazor:

I can reproduce this and there does appear to be a bug in our Python client when printing entities.

When printing an entity we generate a string that assumes the entity has an ID, custom entities do not, causing this unhelpful error. We’ll fix this in the client. The bug only occurs when printing the entity, you can still access the matched custom entities as normal:

for entity in response.entities():
    print(entity.matched_positions, entity.data, entity.custom_entity_id)
aze45sq6d
  • 876
  • 3
  • 11
  • 26