Domain Specific Language for creating language rules

A Domain Specific Language (DSL) for building language patterns. These can be later compiled into spaCy patterns, pure regex, or any other format


import spacy from rita.shortcuts import setup_spacy rules = """ cuts = {"fitted", "wide-cut"} lengths = {"short", "long", "calf-length", "knee-length"} fabric_types = {"soft", "airy", "crinkled"} fabrics = {"velour", "chiffon", "knit", "woven", "stretch"} {IN_LIST(cuts)?, IN_LIST(lengths), WORD("dress")}->MARK("DRESS_TYPE") {IN_LIST(lengths), IN_LIST(cuts), WORD("dress")}->MARK("DRESS_TYPE") {IN_LIST(fabric_types)?, IN_LIST(fabrics)}->MARK("DRESS_FABRIC") """ nlp = spacy.load("en") setup_spacy(nlp, rules_string=rules) r = nlp("She was wearing a short wide-cut dress") print(list([{"label": e.label_, "text": e.text} for e in r.ents]))
Author info

Šarūnas Navickas


Categories standalone

Submit your project

If you have a project that you want the spaCy community to make use of, you can suggest it by submitting a pull request to the spaCy website repository. The Universe database is open-source and collected in a simple JSON file. For more details on the formats and available fields, see the documentation. Looking for inspiration your own spaCy plugin or extension? Check out the project idea label on the issue tracker.

Read the docsJSON source