gramener / gramex-nlg

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

Cloning nuggets with different FormHandler arguments #37

Open jaidevd opened 4 years ago

jaidevd commented 4 years ago

Nuggets should have a .clone() method, which copies a nugget but assigns a different set of FormHandler arguments. This would help auto-generate new nuggets.

E.g, in the context of the actors dataset

fh_args = {'_sort': ['-rating']}
doc = nlp('James Stewart is the actor who has the highest rating.')
nugget = nlg.templatize(doc, fh_args, df)

new_nugget = nugget.clone({'_sort': ['rating']})  # note the change in sort order
new_nugget.render(df)
# Katharine Hepburn is the actress who has the highest rating.

CAUTION: This will only work correctly if all tokens have been properly templatized. Note that the token "highest", left un-templatized, stays as it is even when the order of sorting changes. In this case, the token will have to be made sensitive to the sorting order (see #38) . But generally, any token left un-templatized may get affected.