Git Product home page Git Product logo

madlibs's People

Contributors

svivek avatar

Watchers

 avatar

madlibs's Issues

Names for dependent variables

The following test fails

def test_multiple_dependents_failure():
    fillers = {
        "person": [
            {"name": "Jack", "pronoun": "he", "noun": "man"},
            {"name": "Jill", "pronoun": "she", "noun": "woman"},
        ],
        "place": [
            {"location": "New York", "pronoun": "it"},
            {"location": "Chicago", "pronoun": "it"},
        ],
    }

    template = '{{name}} {{p | type("pronoun")}} {{noun}} {{p}}'

    pytest.raises(Exception):
        m = MadLibTemplate(template, fillers)

The expected behavior is that there should be confusion with which pronoun is to be used. But the template is created with the assumption that the first pronoun is used. This may be okay, but unsatisfactory and can lead to silent bugs downstream.

Maybe one way to get around this is to allow for types to be specified using fully qualified names like:

'{{person.name}} {{p | type("person.pronoun")}} {{person.noun}} {{p}}'

This will remove all ambiguity about which pronoun we are talking about.

Variables for dependent domains

The following test fails:

def test_dependent_variables():
    fillers = {
        "person": [
            {"name": "Jack", "pronoun": "he", "noun": "man"},
            {"name": "Jill", "pronoun": "she", "noun": "woman"},
        ],
        "location": ["New York", "Chicago"],
    }
    template = '{{name}} {{p | type("pronoun")}} {{noun}} {{p}}'

    m = MadLibTemplate(template, fillers)
    generated = m.render({"name": "Jack", "pronoun": "he", "noun": "man"})
    assert generated == "Jack he man he"

The expected behavior is that the variable p in the template should be reused, but the template creation fails with an Exception: Unknown domain for p, probably because there is so much hard coding in how variables for dependent domains are handled.

Numeric comparison in templates

Allow constraints in templates that include numeric comparison. Here is an example template:

{
    "s1": "{{person}} is {{n | range(5, 50, 5)}} years old.",
    "s2": "{{person}} is less than {{m | range(6, 51, 5) | less_than(n, m)}} years old."
}

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.