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

displacy span rendering enhancement #3850

Closed
yanaiela opened this issue Jun 14, 2019 · 6 comments
Closed

displacy span rendering enhancement #3850

yanaiela opened this issue Jun 14, 2019 · 6 comments
Labels
enhancement Feature requests and improvements feat / visualizers Feature: Built-in displaCy and other visualizers

Comments

@yanaiela
Copy link
Contributor

Feature description

Adding a customized html display option into the render function

Hi!
I have a usecase where I want to add a hover into the EntityRenderer spans in displacy.
For the meantime, I just copied the code and hard-coded into it the component I needed but I thought this might be useful for other people as well, and with other customized html options.
Therefore, I'll present here the implementation idea on changing the code before a PR, and I'd be happy to get a feedback if you think this would be a useful feature / how to make it more generic.

So the idea is to add into the options argument another dictionary parameter. This dictionary would consist of additional html code that would be inserted into the html place-holders. The keys of the additional dictionary are additional html code and their values are elements that can be inserted into the keys, is necessary. When that dictionary is not empty, the html place-holders - TPL_ENT and TPL_ENT_RTL would add these additional components.

How does this sound?
Also, I'm not sure if this is useful for the DependencyRenderer, let me know if you think it is.

@ines
Copy link
Member

ines commented Jun 16, 2019

Thanks for raising this – it's definitely something I've thought about before! I wonder if we could maybe just add an option to replace the templates used for the page, container and spans. That would allow full customisation, without the awkwardness of just inserting HTML fragments into the templates (and the error potential here).

Another, slightly more complex solution would be to change the rendering slightly and use templating functions instead of just template strings. So there would be a function along the lines of get_entity_span_html that'd take the text and label as an argument and return a string. The advantage here is that it'd let you compute something with those values and include it in your template – for instance, you could look up the labels in a dictionary and display their descriptions in hover, and stuff like that. But I'm not sure if that's woth the added complexity.

@ines ines added enhancement Feature requests and improvements feat / visualizers Feature: Built-in displaCy and other visualizers labels Jun 16, 2019
@yanaiela
Copy link
Contributor Author

That's a great idea.
I guess the first one is more customized right?
The issue with the second solution is that in a few days/weeks/months someone else would need a different visualization.

Maybe the solution is to combine the two?

Have a function (e.g. get_entity_span_html) that gets the text, label and an html template, where this template can be a prepared template (like the one that exists now) or a completely new one, which will provide the user complete freedom.

@ines
Copy link
Member

ines commented Jun 16, 2019

Have a function (e.g. get_entity_span_html) that gets the text, label and an html template, where this template can be a prepared template (like the one that exists now) or a completely new one, which will provide the user complete freedom.

Ah yeah, sorry if this was confusing in my description. The idea here would be that you could override those getter functions with your own. Your function would need to take the same arguments and has to return a string of markup – everything else is up to you.

@yanaiela
Copy link
Contributor Author

yanaiela commented Jul 5, 2019

I'm starting to work on this. Do you think it make sense to have a customizable html template for each one of the templates in the templates.py file?

@ines
Copy link
Member

ines commented Jul 9, 2019

@yanaiela I think it would be good if the individual HTML templates (at least the most important ones) could be overwritten via an argument on initialization. So html_template_ents (or something like that) would default to the existing TPL_ENT. But a user could also choose to plug in their own.

@yanaiela yanaiela mentioned this issue Aug 14, 2019
3 tasks
@ines ines closed this as completed Aug 18, 2019
@lock
Copy link

lock bot commented Sep 17, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Feature requests and improvements feat / visualizers Feature: Built-in displaCy and other visualizers
Projects
None yet
Development

No branches or pull requests

2 participants