writer / replaCy

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

Support negative `PATTERN_REF` values #53

Closed sam-writer closed 4 years ago

sam-writer commented 4 years ago

If there are optional tokens in your spacy match pattern, and you want to reference the last token in your suggestion, you currently cannot do this. It should be possible, however, to do this, by checking to see if the token is negative and then referencing end instead of start in this line

sam-writer commented 4 years ago

this really isn't useful unless we can say "if the optional token match happened, use it here", e.g.

"patterns": [
            {
                "POS": "DET",
                "OP": "?"
            },
            {
                "LOWER": {
                    "IN": [
                        "some",
                        "list"
                    ]
                }
            },
            {
                "POS": "NOUN"
            }
        ]

would want to say

"suggestions": [
            [
                {
                    "PATTERN_REF": 0,
                    "OP": "?"
                },
                {
                    "PATTERN_REF": -1
                },
                {
                    "TEXT": "with"
                },
                {
                    "PATTERN_REF": -2
                }
            ]
        ],

Meaning, copy the first token if it matched... which AFAICT is hard

sam-writer commented 4 years ago

Closing this, optional matches is a different, harder problem.