Skip to main content

idiomatch

An implementation of SpaCy(3.0)'s Matcher specifically designed for identifying English idioms.

Quick Start

Install the library via uv (or whatever package manager you prefer)

uv add idiomatch 
from idiomatch import Idiomatcher

def main():
    sent = "The floodgates will remain opened for a host of new lawsuits."  # a usecase of *open the floodgates*
    idiomatcher = Idiomatcher.from_pretrained()  # this will take approx 50 seconds.
    doc = idiomatcher.nlp(sent)  # use and only use the nlp model that comes with the matcher 
    print(idiomatcher(doc))  # identify the idiom in the sentence



if __name__ == '__main__':
    main()
adding patterns into idiom_matcher...: 100%|██████████| 2756/2756 [00:52<00:00, 52.83it/s]
[{'idiom': 'open the floodgates', 'span': 'The floodgates will remain opened', 'meta': (13612509636477658373, 0, 5)}]

Supported Idioms

List of supported idioms can be found in idiomatch/resources/idioms.txt. Total of 2758 idioms are available for matching. These "target idioms" were extracted from a vocabulary of 5000 most frequently used English idioms, which had been made available for open use courtesy of IBM's SLIDE project.

Adding Idioms Yourself

If you have idioms that are not included in the list of supported idioms, you can add them to Idiomatcher yourself with the add_idioms member method:

from idiomatch import Idiomatcher

def main():
    idiomatcher = Idiomatcher.from_pretrained()  # instantiate 
    # As for a placeholder for openslot, use either: someone / something / someone's / one's 
    idioms = ["have blood on one's hands", "on one's hands"]
    idiomatcher.add_idioms(idioms)  # this will train idiomatcher to identify the given idioms
    sent = "The leaders of this war have the blood of many thousands of people on their hands."
    doc = idiomatcher.nlp(sent)
    print(idiomatcher(doc))


if __name__ == '__main__':
    main()
100%|██████████| 2/2 [00:00<00:00, 145.62it/s]
adding patterns into idiom_matcher...: 100%|██████████| 2/2 [00:00<00:00, 196.40it/s]
[{'idiom': "have blood on one's hands", 'span': 'have the blood of many thousands of people on their hands', 'meta': (5930902300252675198, 5, 16)}]

Supported Variations

English idioms extensively vary in forms, at least in six different ways. Idiomatcher can gracefully handle all the cases, as exemplified below:

variation example result
modification He called my blatant bluff [{'idiom': "call someone's bluff", 'span': 'called my blatant bluff', 'meta': (11321959191976266509, 1, 5)}]
openslot This will keep all of us posted [{'idiom': 'keep someone posted', 'span': 'keep all of us posted', 'meta': (11722464987668971331, 2, 7)}]
hyphenated That was one balls-out street race! [{'idiom': 'balls-out', 'span': 'balls - out', 'meta': (2876800142358111704, 3, 6)}]
hyphen omitted That was one balls out street race! [{'idiom': 'balls-out', 'span': 'balls out', 'meta': (2876800142358111704, 3, 5)}]
passivisation (modification) the floodgates are finally opened [{'idiom': 'open the floodgates', 'span': 'the floodgates are finally opened', 'meta': (13612509636477658373, 0, 5)}]
passivisation (openslot) my bluff was embarrassingly called by her [{'idiom': "call someone's bluff", 'span': 'my bluff was embarrassingly called', 'meta': (11321959191976266509, 0, 5)}]
inclusion If she dies, you wil have her blood on your hands! [{'idiom': "have blood on one's hands", 'span': 'have her blood on your hands', 'meta': (5930902300252675198, 6, 12)}, {'idiom': "on one's hands", 'span': 'on your hands', 'meta': (8246625119345375174, 9, 12)}]

How Does it Work?

The idiom-matching patterns, which are the foundations of Idiomatcher's flexibility, are heavily inspired by Hughs et al.'s briliant work (2021) on Flexible Retrieval of Idiomatic Expressions from a Large Text Corpus.

Metadata

Release files for idiomatch 0.2.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for idiomatch 0.2.14
File Size Uploaded
idiomatch-0.2.14.tar.gz 899.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for idiomatch 0.2.14
File Interpreter ABI Platform
idiomatch-0.2.14-py3-none-any.whl Python 3 none any Details

Total release size: 1.8 MB

Release files / idiomatch-0.2.14.tar.gz

Download URL idiomatch-0.2.14.tar.gz
Size 899.8 kB
Tags Source
SHA-256 checksum
How to use checksums
080201fc07963865af47d284972d5cdfb71a62682d2d2c5e7622a10cdfc6ef93
BLAKE2b-256 checksum
How to use checksums
b60d602fe88b2f4c4a395aab38963427f4505ff0231be78ceecb85ef972baea8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.4

Release files / idiomatch-0.2.14-py3-none-any.whl

Download URL idiomatch-0.2.14-py3-none-any.whl
Size 947.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ad6d8513c46a371cb9f033954acfa7c9263260b1d99da4d95e747086a4bd005
BLAKE2b-256 checksum
How to use checksums
72824d8ce9ad41521585807116f56fd80b917d83a652caee7dc3305bd96de5c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.4

Release history Release notifications | RSS feed

This release

0.2.14 This release

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page