Skip to main content

ReplaCy = spaCy Matcher + pyInflect. Create rules, correct sentences.

Project description


We found that in multiple projects we had duplicate code for using spaCy’s blazing fast matcher to do the same thing: Match-Replace-Grammaticalize. So we wrote replaCy!

  • Match - spaCy’s matcher is great, and lets you match on text, shape, POS, dependency parse, and other features. We extended this with “match hooks”, predicates that get used in the callback function to further refine a match.

  • Replace - Not built into spaCy’s matcher syntax, but easily added. You often want to replace a matched word with some other term.

  • Grammaticalize - If you match on ”LEMMA”: “dance”, and replace with suggestions: ["sing"], but the actual match is danced, you need to conjugate “sing” appropriately. This is the “killer feature” of replaCy


  • spacy >= 2.0 (not installed by default, expected nlp object)


pip install replacy

Quick start

from replacy import ReplaceMatcher
import spacy

# load nlp spacy model of your choice
nlp = spacy.load("en_core_web_sm")

rmatcher = ReplaceMatcher(nlp)

# get inflected suggestions
# look up the first suggestion
span = rmatcher("She extracts revenge.")[0]
# >>> ['exacts']

Testing match_dict (json schema validation)

from replacy import ReplaceMatcher
from replacy.db import load_json

match_dict = load_json('/path/to/your/match/dict')

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for replacy, version 0.9.0
Filename, size File type Python version Upload date Hashes
Filename, size replacy-0.9.0.tar.gz (6.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page