Skip to content

Commit 9a0d771

Browse files
committed
Documentation for the new ‘select_replacement’ method in the readme
1 parent 6482a12 commit 9a0d771

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ If you want to decide which `Match` objects to apply to your text, use `tool.che
5454
'Department of medicine Colombia University closed on August 1 Melinda Sam'
5555
```
5656

57+
### Apply a specific suggestion of a match with `Match.select_replacement` and `utils.correct`
58+
59+
If you want to apply a particular suggestion from a `Match`, use `Match.select_replacement` (to select a replacement with its index) in conjunction with `language_tool_python.utils.correct` (to apply selected replacements from the `Match` list to the text). Here is an example of generating, selecting replacements, and applying the list of matches. In this case, the third replacement (book) is selected.
60+
61+
```python
62+
>>> import language_tool_python
63+
>>> s = "There is a bok on the table."
64+
>>> tool = language_tool_python.LanguageTool('en-US')
65+
>>> matches = tool.check(s)
66+
>>> matches
67+
[Match({'ruleId': 'MORFOLOGIK_RULE_EN_US', 'message': 'Possible spelling mistake found.', 'replacements': ['BOK', 'OK', 'book', 'box'], 'offsetInContext': 11, 'context': 'There is a bok on the table.', 'offset': 11, 'errorLength': 3, 'category': 'TYPOS', 'ruleIssueType': 'misspelling', 'sentence': 'There is a bok on the table.'})]
68+
>>> matches[0].select_replacement(2)
69+
>>> patched_text = language_tool_python.utils.correct(s, matches)
70+
>>> patched_text
71+
'There is a book on the table.'
72+
```
73+
5774
## Example usage
5875

5976
From the interpreter:

0 commit comments

Comments
 (0)