# Path: concepts/formats/base.py
# class ContextArgs(typing.NamedTuple):
#     """Return value of ``.loads()`` and ``.load()``."""
# 
#     objects: typing.List[str]
# 
#     properties: typing.List[str]
# 
#     bools: typing.List[typing.Tuple[bool, ...]]
# 
#     serialized: typing.Optional['SerializedArgs'] = None
# 
# class Format(metaclass=FormatMeta):
#     """Parse and serialize formal contexts in a specific string format."""
# 
#     __abstract__ = True
# 
#     encoding = None
# 
#     newline = None
# 
#     dumps_rstrip = None
# 
#     @classmethod
#     def load(cls, filename, encoding, **kwargs) -> ContextArgs:
#         """Load and parse serialized objects, properties, bools from file."""
#         if encoding is None:
#             encoding = cls.encoding
# 
#         with open(filename, encoding=encoding, newline=cls.newline) as f:
#             return cls.loadf(f, **kwargs)
# 
#     @classmethod
#     def loads(cls, source, **kwargs) -> ContextArgs:
#         """Parse source string and return ``ContextArgs``."""
#         with io.StringIO(source) as buf:
#             return cls.loadf(buf, **kwargs)
# 
#     @classmethod
#     def dump(cls, filename, objects, properties, bools,
#              *, encoding: typing.Optional[str], _serialized=None, **kwargs):
#         """Write serialized objects, properties, bools to file."""
#         if encoding is None:
#             encoding = cls.encoding
# 
#         with open(filename, 'w', encoding=encoding, newline=cls.newline) as f:
#             cls.dumpf(f, objects, properties, bools, _serialized=_serialized,
#                       **kwargs)
# 
#     @classmethod
#     def dumps(cls, objects, properties, bools, _serialized=None, **kwargs):
#         with io.StringIO(newline=cls.newline) as buf:
#             cls.dumpf(buf, objects, properties, bools, _serialized=_serialized,
#                       **kwargs)
#             source = buf.getvalue()
#         if cls.dumps_rstrip:
#             source = source.rstrip()
#         return source
# 
#     @staticmethod
#     def loadf(file, **kwargs) -> ContextArgs:
#         """Parse file-like object and return ``ContextArgs``."""
#         raise NotImplementedError  # pragma: no cover
# 
#     @staticmethod
#     def dumpf(file, objects, properties, bools, *, _serialized=None, **kwargs):
#         """Serialize ``(objects, properties, bools)`` into file-like object."""
#         raise NotImplementedError  # pragma: no cover


import functools
import typing
from .base import ContextArgs, Format
    yield ''

    yield from objects
    yield from properties

    for row in bools:
        yield ''.join(symbols[value] for value in row)


class Cxt(Format):
    """Formal context in the classic CXT format."""

    suffix = '.cxt'

    dumps_rstrip = False

    symbols = SYMBOLS

    values = {s: b for b, s in symbols.items()}

    @classmethod
    def loadf(cls, file):
        source = file.read().strip()
        b, yx, table = source.split('\n\n')
        y, x = map(int, yx.split())
        lines = [l.strip() for l in table.strip().split('\n')]
        objects = lines[:y]
        properties = lines[y:y + x]
        bools = [tuple(map(cls.values.__getitem__, l))
                 for l in lines[y + x:]]

# Path: concepts/formats/base.py
# class ContextArgs(typing.NamedTuple):
#     """Return value of ``.loads()`` and ``.load()``."""
# 
#     objects: typing.List[str]
# 
#     properties: typing.List[str]
# 
#     bools: typing.List[typing.Tuple[bool, ...]]
# 
#     serialized: typing.Optional['SerializedArgs'] = None
# 
# class Format(metaclass=FormatMeta):
#     """Parse and serialize formal contexts in a specific string format."""
# 
#     __abstract__ = True
# 
#     encoding = None
# 
#     newline = None
# 
#     dumps_rstrip = None
# 
#     @classmethod
#     def load(cls, filename, encoding, **kwargs) -> ContextArgs:
#         """Load and parse serialized objects, properties, bools from file."""
#         if encoding is None:
#             encoding = cls.encoding
# 
#         with open(filename, encoding=encoding, newline=cls.newline) as f:
#             return cls.loadf(f, **kwargs)
# 
#     @classmethod
#     def loads(cls, source, **kwargs) -> ContextArgs:
#         """Parse source string and return ``ContextArgs``."""
#         with io.StringIO(source) as buf:
#             return cls.loadf(buf, **kwargs)
# 
#     @classmethod
#     def dump(cls, filename, objects, properties, bools,
#              *, encoding: typing.Optional[str], _serialized=None, **kwargs):
#         """Write serialized objects, properties, bools to file."""
#         if encoding is None:
#             encoding = cls.encoding
# 
#         with open(filename, 'w', encoding=encoding, newline=cls.newline) as f:
#             cls.dumpf(f, objects, properties, bools, _serialized=_serialized,
#                       **kwargs)
# 
#     @classmethod
#     def dumps(cls, objects, properties, bools, _serialized=None, **kwargs):
#         with io.StringIO(newline=cls.newline) as buf:
#             cls.dumpf(buf, objects, properties, bools, _serialized=_serialized,
#                       **kwargs)
#             source = buf.getvalue()
#         if cls.dumps_rstrip:
#             source = source.rstrip()
#         return source
# 
#     @staticmethod
#     def loadf(file, **kwargs) -> ContextArgs:
#         """Parse file-like object and return ``ContextArgs``."""
#         raise NotImplementedError  # pragma: no cover
# 
#     @staticmethod
#     def dumpf(file, objects, properties, bools, *, _serialized=None, **kwargs):
#         """Serialize ``(objects, properties, bools)`` into file-like object."""
#         raise NotImplementedError  # pragma: no cover


# Path: concepts/formats/cxt.py
import functools
import typing
from .base import ContextArgs, Format

    yield ''

    yield from objects
    yield from properties

    for row in bools:
        yield ''.join(symbols[value] for value in row)


class Cxt(Format):
    """Formal context in the classic CXT format."""

    suffix = '.cxt'

    dumps_rstrip = False

    symbols = SYMBOLS

    values = {s: b for b, s in symbols.items()}

    @classmethod
    def loadf(cls, file):
        source = file.read().strip()
        b, yx, table = source.split('\n\n')
        y, x = map(int, yx.split())
        lines = [l.strip() for l in table.strip().split('\n')]
        objects = lines[:y]
        properties = lines[y:y + x]
        bools = [tuple(map(cls.values.__getitem__, l))
                 for l in lines[y + x:]]

        return ContextArgs(objects, properties, bools)