nltk.jsontags module¶
Register JSON tags, so the nltk data loader knows what module and class to look for.
NLTK uses simple ‘!’ tags to mark the types of objects, but the fully-qualified “tag:nltk.org,2011:” prefix is also accepted in case anyone ends up using it.
- class nltk.jsontags.JSONTaggedDecoder[source]¶
Bases:
JSONDecoder
- class nltk.jsontags.JSONTaggedEncoder[source]¶
Bases:
JSONEncoder
- default(obj)[source]¶
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)