gramener / gramex-nlg

Natural Language Generation for Gramex applications.
Other
24 stars 24 forks source link

Shorter strings break templatization #25

Closed jaidevd closed 4 years ago

jaidevd commented 4 years ago

In the context of the actors dataset, if any name is passed (e.g.: "Humphrey Bogart") to the templatize function:

~/src/nlg/nlg/search.py in templatize(text, args, df)
    510 {{ df["species"].iloc[1] }} and {{ df["species"].iloc[-1] }}.
    511     """
--> 512     dfix, clean_text, infl = _search(text, args, df)
    513     return narrative.Nugget(clean_text, dfix, infl, args)
    514 

~/src/nlg/nlg/search.py in _search(text, args, df, copy)
    441     dfix.update(search_args(dfs.ents, args))
    442     dfix.clean()
--> 443     inflections = grammar.find_inflections(dfix, args, df)
    444     _infl = {}
    445     for token, funcs in inflections.items():

~/src/nlg/nlg/grammar.py in find_inflections(search, fh_args, df)
    256         rendered = Template('{{{{ {} }}}}'.format(tmpl)).generate(
    257             df=df, fh_args=fh_args).decode('utf8')
--> 258         if rendered != token.text:
    259             x = nlp(rendered)[0]
    260             infl = _token_inflections(x, token)

AttributeError: 'tuple' object has no attribute 'text'