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 “,2011:” prefix is also accepted in case anyone ends up using it.


Decorates a class to register it’s json tag.

class nltk.jsontags.JSONTaggedEncoder[source]

Bases: json.encoder.JSONEncoder


Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
        iterable = iter(o)
    except TypeError:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class nltk.jsontags.JSONTaggedDecoder[source]

Bases: json.decoder.JSONDecoder


Return the Python representation of s (a str instance containing a JSON document).

classmethod decode_obj(obj)[source]