Skip to content

Commit 30cb835

Browse files
committed
fix issues with .correct()
1 parent 2049379 commit 30cb835

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Print a ``Match`` object:
5757

5858
Automatically apply suggestions to the text:
5959

60-
language_tool_python.correct(text, matches)
60+
tool.correct(text)
6161
'A sentence with an error in the Hitchhiker’s Guide to the Galaxy'
6262

6363
From the command line::

‎language_tool_python/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
migration URL: https://languagetool.org/http-api/migration.php
44
"""
55

6-
__version__ = '2.0.2'
6+
__version__ = '2.0.3'
77

88
from .language_tag import LanguageTag
99
from .match import Match

‎language_tool_python/match.py‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
def get_match_ordered_dict():
55
slots = OrderedDict([
6-
('ruleId', str), ('message', str),
6+
('ruleId', str),
7+
('message', str),
78
('replacements', list),
8-
('context', str), ('contextOffset', int), ('contextLength', int),
9-
('offset', int), ('errorlength', int),
10-
('category', str), ('ruleIssueType', str),
9+
('context', str),
10+
('offset', int),
11+
('errorLength', int),
12+
('category', str),
13+
('ruleIssueType', str),
1114
])
1215
return slots
1316

@@ -45,9 +48,12 @@ def __init__(self, attrib):
4548
attrib['ruleIssueType'] = attrib['rule']['issueType']
4649
del attrib['rule']
4750
# Process context.
48-
attrib['contextOffset'] = attrib['context']['offset']
49-
attrib['contextLength'] = attrib['context']['length']
5051
attrib['context'] = attrib['context']['text']
52+
# Process replacements.
53+
attrib['replacements'] = [r['value'] for r in attrib['replacements']]
54+
# Rename error length.
55+
attrib['errorLength'] = attrib['length']
56+
# Store objects on self.
5157
for k, v in attrib.items():
5258
setattr(self, k, v)
5359

@@ -75,7 +81,7 @@ def __str__(self):
7581
if self.replacements:
7682
s += '\nSuggestion: {}'.format('; '.join(self.replacements))
7783
s += '\n{}\n{}'.format(
78-
self.context, ' ' * self.contextoffset + '^' * self.errorlength
84+
self.context, ' ' * self.offset + '^' * self.errorLength
7985
)
8086
return s
8187

‎language_tool_python/utils.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ def correct(text: str, matches: [Match]) -> str:
4545
"""Automatically apply suggestions to the text."""
4646
ltext = list(text)
4747
matches = [match for match in matches if match.replacements]
48-
errors = [ltext[match.offset:match.offset + match.errorlength]
48+
errors = [ltext[match.offset:match.offset + match.errorLength]
4949
for match in matches]
5050
correct_offset = 0
5151
for n, match in enumerate(matches):
5252
frompos, topos = (correct_offset + match.offset,
53-
correct_offset + match.offset + match.errorlength)
53+
correct_offset + match.offset + match.errorLength)
5454
if ltext[frompos:topos] != errors[n]:
5555
continue
5656
repl = match.replacements[0]

0 commit comments

Comments
 (0)