spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

Support custom attributes for tokens and spans in json conversion

Open thomashacker opened this issue 1 year ago • 1 comments

Description

Currently, Doc.to_json() and Doc.from_json() only support custom attributes set on the whole Doc object. This PR adds support for custom attributes in tokens and spans.

Types of change

New Feature

Checklist

  • [x] I confirm that I have the right to submit this contribution under the project's MIT license.
  • [x] I ran the tests, and all new and existing tests passed.
  • [x] My changes don't require a change to the documentation, or if they do, I've added all required information.

thomashacker avatar Jul 13 '22 14:07 thomashacker

I've adjusted the naming and ensured that added keys in the future wouldn't break the code. I also ensured that the code checks whether the user_data is a tuple + attributes with the same name for Doc, Token, and Span are now supported.

For the new logic, I also added some additional tests.

thomashacker avatar Jul 29 '22 11:07 thomashacker