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

Plugin architecture #12

Open
osma opened this issue Oct 3, 2017 · 2 comments
Open

Plugin architecture #12

osma opened this issue Oct 3, 2017 · 2 comments
Milestone

Comments

@osma
Copy link
Member

osma commented Oct 3, 2017

We could support plugins for pre- and/or post-processing the document analysis functionality.

A plugin could be a subclass of a class like this:

class AnnifPlugin:
    """A plugin that tweaks Annif queries before and/or after they are executed"""

    def process_analyze_query(query):
        """Preprocess an analyze query, tweaking the parameters before the query is executed"""
        # default implementation is a no-op
        return query

    def postprocess_analyze_query(query, result):
        """Postprocess an analyze query and result, tweaking the result before responding to the client"""
        # default implementation is a no-op
        return query

For registering plugins, we could perhaps make use of PluginBase. Each plugin would be a separate Python project that registers itself to the Annif plugin system. Each Annif project could define a set of plugins to use. The plugins could be stacked/chained, so that the result of one plugin would be fed to the next one in the chain.

Plugins would be fed the raw result of Annif queries (with lots of candidate subject), before cutting down them into the requested size and/or applying score thresholds. This way the plugins have more candidate subjects to work with.

Ideas for plugins:

  • Neural plugin that makes use of neural networks to determine whether a set of subjects is "good" (i.e. looks somewhat like existing subject sets it has been trained on) and tweak the set so that it becomes "better"
  • Co-occurrence plugin that checks whether a set of subject contains pairs of subjects that frequently occur together, and increases their score
@osma osma added this to the Long term milestone Oct 3, 2017
@osma osma modified the milestones: Long term, Blue Sky Dec 14, 2018
@osma
Copy link
Member Author

osma commented Dec 14, 2018

In the current architecture these could simply be separate backends. Backends can register themselves using annif.backend.register_backend so I'm not sure whether the plugin infrastructure is really needed, but of course it would make Annif more extensible.

@kinow
Copy link
Collaborator

kinow commented Jan 20, 2019

but of course it would make Annif more extensible.

I have two systems where plugins are needed. One of them has a few mechanisms for plugins. This project is passing through an update, starting by getting a setup.py file, and making more use of vanilla features.

We are thinking about using simple entry points (other good doc from setuptools).

I believe PyTest and PyLint use this approach. Scrapy is a different beast, so they used a different approach to allow scrappers to easily extend scrapy, without the need to package a python utility with setuptools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants