# Path: concepts/formats/base.py
# 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
from .base import Format


__all__ = ['WikiTable']


def dump_file(file, objects, properties, bools, *, _serialized=None):
    write = functools.partial(print, file=file)
    write('{| class="featuresystem"')
    write('!')
    write('!{}'.format('!!'.join(properties)))

    wp = list(map(len, properties))

    for o, intent in zip(objects, bools):
        bcells = (('X' if b else '').ljust(w) for w, b in zip(wp, intent))
        write('|-')
        write(f'!{o}')
        write('|{}'.format('||'.join(bcells)))
    write('|}')



# Path: concepts/formats/base.py
# 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/wiki_table.py
import functools
from .base import Format



__all__ = ['WikiTable']


def dump_file(file, objects, properties, bools, *, _serialized=None):
    write = functools.partial(print, file=file)
    write('{| class="featuresystem"')
    write('!')
    write('!{}'.format('!!'.join(properties)))

    wp = list(map(len, properties))

    for o, intent in zip(objects, bools):
        bcells = (('X' if b else '').ljust(w) for w, b in zip(wp, intent))
        write('|-')
        write(f'!{o}')
        write('|{}'.format('||'.join(bcells)))
    write('|}')



class WikiTable(Format):