# Path: cjktools/common.py
# def sopen(filename, mode='rb', encoding='utf8'):
#     """
#     Transparently uses compression on the given file based on file
#     extension.
# 
#     :param filename:
#         The filename to use for the file handle.
#     
#     :param mode:
#         The mode to open the file in, e.g. ``'r'`` for read, ``'w'`` for
#         write, ``'a'`` for append.
#     
#     :param encoding:
#         The encoding to use. Can be set to None to avoid
#         using unicode at all.
#     """
#     read_mode = 'r' in mode
#     if read_mode and 'w' in mode:
#         raise Exception("Must be either read mode or write, but not both")
# 
#     # Do this before any streams are opened to hopefully minimize the potential
#     # for failing while resources are open.
#     if encoding not in (None, 'byte') and six.PY2:
#         if read_mode:
#             streamhandler = codecs.getreader(encoding)
#         else:
#             streamhandler = codecs.getwriter(encoding)
#     else:
#         streamhandler = lambda x: x
# 
#     if filename.endswith('.bz2'):
#         stream = bz2.BZ2File(filename, mode)
#     elif filename.endswith('.gz'):
#         stream = gzip.GzipFile(filename, mode)
#     elif filename == '-':
#         if read_mode:
#             stream = sys.stdin
#         else:
#             stream = sys.stdout
#     else:
#         stream = open(filename, mode)
# 
#     return streamhandler(stream)


import random
import six
from cjktools.common import sopen
from six import string_types, text_type, iteritems
        super(Place, self).__init__()
        self.label = label
        self.reading = reading
        self.aliases = aliases

    def get_children(self):
        return self.values()

    children = property(get_children)

    def __repr__(self):
        return text_type(self)

    def __str__(self):
        return '<Place: %s%s %d children>' % (
            self.label,
            (self.reading and ' /%s/' % self.reading or ''),
            len(self),
        )

    if six.PY2:
        __unicode__ = __str__

    def dump(self, filename):
        with sopen(filename, 'w') as o_stream:
            for depth, place in self.walk():
                print(place._to_line(depth), file=o_stream)

    @classmethod
    def from_file(cls, filename):

# Path: cjktools/common.py
# def sopen(filename, mode='rb', encoding='utf8'):
#     """
#     Transparently uses compression on the given file based on file
#     extension.
# 
#     :param filename:
#         The filename to use for the file handle.
#     
#     :param mode:
#         The mode to open the file in, e.g. ``'r'`` for read, ``'w'`` for
#         write, ``'a'`` for append.
#     
#     :param encoding:
#         The encoding to use. Can be set to None to avoid
#         using unicode at all.
#     """
#     read_mode = 'r' in mode
#     if read_mode and 'w' in mode:
#         raise Exception("Must be either read mode or write, but not both")
# 
#     # Do this before any streams are opened to hopefully minimize the potential
#     # for failing while resources are open.
#     if encoding not in (None, 'byte') and six.PY2:
#         if read_mode:
#             streamhandler = codecs.getreader(encoding)
#         else:
#             streamhandler = codecs.getwriter(encoding)
#     else:
#         streamhandler = lambda x: x
# 
#     if filename.endswith('.bz2'):
#         stream = bz2.BZ2File(filename, mode)
#     elif filename.endswith('.gz'):
#         stream = gzip.GzipFile(filename, mode)
#     elif filename == '-':
#         if read_mode:
#             stream = sys.stdin
#         else:
#             stream = sys.stdout
#     else:
#         stream = open(filename, mode)
# 
#     return streamhandler(stream)


# Path: cjktools/resources/place.py
import random
import six
from cjktools.common import sopen
from six import string_types, text_type, iteritems

        super(Place, self).__init__()
        self.label = label
        self.reading = reading
        self.aliases = aliases

    def get_children(self):
        return self.values()

    children = property(get_children)

    def __repr__(self):
        return text_type(self)

    def __str__(self):
        return '<Place: %s%s %d children>' % (
            self.label,
            (self.reading and ' /%s/' % self.reading or ''),
            len(self),
        )

    if six.PY2:
        __unicode__ = __str__

    def dump(self, filename):
        with sopen(filename, 'w') as o_stream:
            for depth, place in self.walk():
                print(place._to_line(depth), file=o_stream)

    @classmethod
    def from_file(cls, filename):

        with sopen(filename, mode='r') as i_stream: