Giter Site home page Giter Site logo

New Mapping Type about strictyaml HOT 2 OPEN

crdoconnor avatar crdoconnor commented on July 28, 2024 2
New Mapping Type

from strictyaml.

Comments (2)

crdoconnor avatar crdoconnor commented on July 28, 2024 3

No, that looks pretty much exactly how I'd do it.

from strictyaml.

bt2901 avatar bt2901 commented on July 28, 2024

I'm interested in something similar: some sort of Map() | Map(). The use case:

We have a sequence of building blocks (taken together, they specify a training process for a particular topic model). There is a small list of building blocks available (at the moment, only two: CubeCreator and RegularizerModifierCube), but each takes a lot of input parameters. Different blocks require different parameters, however.

For now, I'm handling the situation like this:

base_schema = Map({
    'stages': Seq(Any()),
...
})
SUPPORTED_CUBES = [CubeCreator, RegularizersModifierCube]

def build_schema_for_cubes():
    """
    Returns
    -------
    dict
        each element is str -> strictyaml.Map
        where key is name of cube,
        value is a schema used for validation and type-coercion
    """
    schemas = {}
    for class_of_object in SUPPORTED_CUBES:
        res = build_schema_from_signature(class_of_object)
        res = Map(res)

        specific_schema = Map({class_of_object.__name__: res})
        schemas[class_of_object.__name__] = specific_schema
    return schemas

parsed = load(yaml_string, base_schema)
schemas = build_schema_for_cubes()

for i, stage in enumerate(parsed['stages']):
    assert len(stage) == 1
    name = list(stage.data)[0]

    if name not in schemas:
        raise ValueError(f"Unsupported stage ID: {name} at line {stage.start_line}")
    local_schema = schemas[name]

    stage.revalidate(local_schema)

Is there a better way?

from strictyaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.