def mention_subclass(class_name, cardinality=None, values=None, table_name=None):
if table_name is None:<EOL><INDENT>table_name = camel_to_under(class_name)<EOL><DEDENT>if cardinality is None and values is None:<EOL><INDENT>values = [True, False]<EOL>cardinality = <NUM_LIT:2><EOL><DEDENT>elif values is not None:<EOL><INDENT>if cardinality is not None and len(values) != cardinality:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if None in values:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if any([isinstance(v, int) and not isinstance(v, bool) for v in values]):<EOL><INDENT>raise ValueError(<EOL>(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>)<EOL><DEDENT>cardinality = len(values)<EOL><DEDENT>elif cardinality is not None:<EOL><INDENT>values = list(range(cardinality))<EOL><DEDENT>args = ["<STR_LIT>"]<EOL>class_spec = (args, table_name, cardinality, values)<EOL>if class_name in mention_subclasses:<EOL><INDENT>if class_spec == mention_subclasses[class_name][<NUM_LIT:1>]:<EOL><INDENT>return mention_subclasses[class_name][<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>f"<STR_LIT>"<EOL>f"<STR_LIT>"<EOL>f"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>class_attribs = {<EOL>"<STR_LIT>": table_name,<EOL>"<STR_LIT:id>": Column(<EOL>Integer, ForeignKey("<STR_LIT>", ondelete="<STR_LIT>"), primary_key=True<EOL>),<EOL>"<STR_LIT>": values,<EOL>"<STR_LIT>": cardinality,<EOL>"<STR_LIT>": {"<STR_LIT>": table_name},<EOL>"<STR_LIT>": args,<EOL>}<EOL>class_attribs["<STR_LIT>"] = Column(<EOL>Integer, ForeignKey("<STR_LIT>", ondelete="<STR_LIT>")<EOL>)<EOL>class_attribs["<STR_LIT>"] = relationship(<EOL>"<STR_LIT>",<EOL>backref=backref(table_name + "<STR_LIT:s>", cascade="<STR_LIT>"),<EOL>foreign_keys=class_attribs["<STR_LIT>"],<EOL>)<EOL>unique_args = []<EOL>for arg in args:<EOL><INDENT>class_attribs[arg + "<STR_LIT>"] = Column(<EOL>Integer, ForeignKey("<STR_LIT>", ondelete="<STR_LIT>")<EOL>)<EOL>class_attribs[arg] = relationship(<EOL>"<STR_LIT>", foreign_keys=class_attribs[arg + "<STR_LIT>"]<EOL>)<EOL>unique_args.append(class_attribs[arg + "<STR_LIT>"])<EOL><DEDENT>class_attribs["<STR_LIT>"] = (UniqueConstraint(*unique_args),)<EOL>C = type(class_name, (Mention,), class_attribs)<EOL>if not Meta.engine.dialect.has_table(Meta.engine, table_name):<EOL><INDENT>C.__table__.create(bind=Meta.engine)<EOL><DEDENT>mention_subclasses[class_name] = C, class_spec<EOL>return C<EOL><DEDENT>
Creates and returns a Mention subclass with provided argument names,
which are Context type. Creates the table in DB if does not exist yet.

Import using:

.. code-block:: python

    from fonduer.candidates.models import mention_subclass

:param class_name: The name of the class, should be "camel case" e.g.
    NewMention
:param table_name: The name of the corresponding table in DB; if not
    provided, is converted from camel case by default, e.g. new_mention
:param values: The values that the variable corresponding to the Mention
    can take. By default it will be [True, False].
:param cardinality: The cardinality of the variable corresponding to the
    Mention. By default is 2 i.e. is a binary value, e.g. is or is not
    a true mention.