Python Rule Processing Engine 🏺

Hammurabi works as a rule engine to parse input using a defined set of rules. It uses a simple and readable syntax to define complex rules to handle phrase matching. The syntax supports nested logical statements, regular expressions, reusable or side-loaded variables and match triggered callback functions to modularize your rules. The latest version works with both spaCy 2.X and 3.X. For more information check the documentation on ReadTheDocs.


import spacy # __version__ 3.0+ from hmrb.core import SpacyCore grammar = """ Var is_hurting: ( optional (lemma: "be") (lemma: "hurt") ) Law: - package: "headache" - callback: "mark_headache" ( (lemma: "head", pos: "NOUN") $is_hurting )""" conf = { "rules": grammar "callbacks": { "mark_headache": "callbacks.headache_handler", }, "map_doc": "augmenters.jsonify_span", "sort_length": True, } nlp = spacy.load("en_core_web_sm") nlp.add_pipe("hammurabi", config=conf) nlp(sentences)

Author info

Kristian Boda


Categories pipeline standalone scientific biomedical

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