-
Notifications
You must be signed in to change notification settings - Fork 24
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
Narrative API #17
Conversation
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): |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
Add example notebook
This PR introduces the Narrative API which allows manual setting of variables in templates. Other changes include: