writer / replaCy

spaCy match and replace, maintaining conjugation
https://pypi.org/project/replacy/
MIT License
34 stars 8 forks source link

Allow succeeded_by_phrase to take a list, and match if any are true #16

Closed sam-writer closed 4 years ago

sam-writer commented 4 years ago

Let's say you only want to match if the following word is in ["height", "value", "size", "number"]. You might try adding to your match.json:

"match_hook": [
            {
                "name": "succeeded_by_phrase",
                "args": ["height", "value", "size", "number"],
                "match_if_predicate_is": true
            }
]

This will raise when it tries to call lower() on args, since it assumes it gets a string. Maybe you try

"match_hook": [
            {
                "name": "succeeded_by_phrase",
                "args": "height",
                "match_if_predicate_is": true
            },
            {
                "name": "succeeded_by_phrase",
                "args": "value",
                "match_if_predicate_is": true
            },
            {
                "name": "succeeded_by_phrase",
                "args": "size",
                "match_if_predicate_is": true
            },
            {
                "name": "succeeded_by_phrase",
                "args": "number",
                "match_if_predicate_is": true
            }
        ]

This also doesn't work (empirically), and the syntax is horrible and verbose.

Action: make the first syntax work.