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

Architecture for sharing processed data across rules #20

Closed
mpacer opened this issue Jan 22, 2015 · 1 comment
Closed

Architecture for sharing processed data across rules #20

mpacer opened this issue Jan 22, 2015 · 1 comment

Comments

@mpacer
Copy link
Member

mpacer commented Jan 22, 2015

If we need to use more computationally intense analyses in multiple rules (e.g., nltk & syntax parsing to identify whether •while• is being used as a conjunction or a adverb) it would make more sense to memoize the output so that it can be accessed by other rules rather than rerun.

This should be a fairly general system that automatically builds the data structures so that they can be shared across individual checks, possibly with some kind of a require type statement being present in more than one rule?

@suchow
Copy link
Member

suchow commented Jan 22, 2015

Commit 3ae3d83 introduces a framework for memoization, allowing you to define shared processing functions like this:

from memoize import memoize


@memoize
def reverse(text):
    return text[::-1]

and then call them from within the check function of a particular linting rule:

from proselint.reverse import reverse


def check(text):

    reversed_text = reverse(text)

    error_code = "PL000"
    msg = "First line always has an error."

    return [(1, 1, error_code, msg)]

One of the nice things about this system is that each linter rule includes all the data transformations it requires (e.g., maybe someday there will be parse_tree = parse(text)), but because the same text is passed to all the linters, the parsing is run only the very first time that it's requested by a linter rule.

I think this closes this issue because it implements a minimal version of what's requested.

Does that work for you?

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

No branches or pull requests

2 participants