utahnlp / madlibs

MIT License
0 stars 0 forks source link

Names for dependent variables #4

Open svivek opened 3 years ago

svivek commented 3 years ago

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.