Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrative API #17

Merged
merged 15 commits into from
Jan 17, 2020
Merged

Narrative API #17

merged 15 commits into from
Jan 17, 2020

Conversation

jaidevd
Copy link
Member

@jaidevd jaidevd commented Jan 16, 2020

This PR introduces the Narrative API which allows manual setting of variables in templates. Other changes include:

  1. Multiple inflection detection
  2. Tighter spacy integration
  3. Tutorial notebook

nlg/grammar.py Outdated
@@ -237,10 +237,11 @@ def find_inflections(text, search, fh_args, df):
tmpl = [t['tmpl'] for t in tklist if t.get('enabled', False)][0]
rendered = Template('{{{{ {} }}}}'.format(tmpl)).generate(
df=df, fh_args=fh_args).decode('utf8')
if rendered != token:
if rendered != getattr(token, "text", token):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quants and fh_args are still not ported over to spacy tokens and spans - which has necessitated this.

nlg/grammar.py Outdated
if infl:
inflections[token] = [infl]
inflections[token.text] = [infl]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail if token is a string. Ensure #15 is fixed.

@@ -195,8 +265,29 @@ def search_quant(self, quants, nround=2, cell_fmt='df["{}"].iloc[{}]'):
'location': 'cell', 'tmpl': cell_fmt.format(self.df.columns[y], x),
'type': 'quant'}

def search_derived_quant(self, quants, nround=2):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obsolete.

dfix.update(search_args(dfs.ents, args))
dfix.clean()
inflections = grammar.find_inflections(clean_text, dfix, args, df)
inflections = grammar.find_inflections(text.text, dfix, args, df)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary. Inflections should work with tokens / spans

return narrative.Nugget(clean_text, dfix, infl, args)


def add_manual_template(input_template, manual_template=None):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obsolete.

@@ -228,3 +228,28 @@ def add_html_styling(template, style):
ss=spanstyle, token=token)
template = re.sub(re.escape(token), repl, template, 1)
return '<p>{template}</p>'.format(template=template)


def infer_quant(token):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be replaced with numerizer.

@jaidevd jaidevd changed the title WIP: Template API Narrative API Jan 17, 2020
@jaidevd jaidevd merged commit 2e03e2f into dev Jan 17, 2020
@jaidevd jaidevd deleted the jd-tmpl-interface branch January 17, 2020 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants