def parse(schema, subsample_default):
    '''Parses a generator schema as passed to CrosscatMetamodel.

    schema is a tokenized expression of the form [['GUESS', ['*']], ['x',
    'NUMERICAL'], ...] that is passed to CrosscatMetamodel.create_generator and
    represents the argument to "crosscat" in CREATE GENERATOR ... FOR ... USING
    crosscat(...).

    Returns a GeneratorSchema.

    See test_crosscat_generator_schema.py for examples.
    '''

    guess = False
    subsample = subsample_default
    columns = []
    dep_constraints = []
    for directive in schema:

        if directive == []:
            # Skip extra commas so you can write
            #
            #    CREATE GENERATOR t_cc FOR t USING crosscat(
            #        x,
            #        y,
            #        z,
            #    )
            continue

        if (not isinstance(directive, list) or len(directive) != 2 or
                not isinstance(directive[0], basestring)):
            raise BQLError(
                None,
                'Invalid crosscat column model directive: %r' % (directive,))

        op = casefold(directive[0])
        if op == 'guess' and directive[1] == ['*']:
            guess = True
        elif (op == 'subsample' and isinstance(directive[1], list) and
                len(directive[1]) == 1):
            subsample = _parse_subsample_clause(directive[1][0])
        elif op == 'dependent':
            constraint = (_parse_dependent_clause(directive[1]), True)
            dep_constraints.append(constraint)
        elif op == 'independent':
            constraint = (_parse_dependent_clause(directive[1]), False)
            dep_constraints.append(constraint)
        elif op != 'guess' and casefold(directive[1]) != 'guess':
            columns.append((directive[0], directive[1]))
        else:
            raise BQLError(
                None, 'Invalid crosscat column model: %r' % (directive),)
    return GeneratorSchema(
        guess=guess, subsample=subsample, columns=columns,
        dep_constraints=dep_constraints)
dataset/ETHPy150Open probcomp/bayeslite/src/metamodels/crosscat_generator_schema.py/parse/original