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.

nltk.jsontags.register_tag(cls)[source]

Decorates a class to register it’s json tag.

class nltk.jsontags.JSONTaggedEncoder[source]

Bases: json.encoder.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 a TypeError).

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)
class nltk.jsontags.JSONTaggedDecoder[source]

Bases: json.decoder.JSONDecoder

decode(s)[source]

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

classmethod decode_obj(obj)[source]