Skip to content

Commit b3a302c

Browse files
committed
Fancier example usage.
1 parent 58d6771 commit b3a302c

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎README.rst‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,42 @@ language_tool – LanguageTool through server mode
55
Example usage
66
-------------
77

8-
>>> from language_tool import LanguageTool
9-
>>> lang_tool = LanguageTool("en")
8+
>>> import language_tool
9+
>>> lang_tool = language_tool.LanguageTool("en-US")
1010
>>> text = "but it’s suppose to be all yellowy."
1111
>>> matches = lang_tool.check(text)
1212
>>> len(matches)
1313
2
14+
15+
16+
Check out some ``Match`` object attributes:
17+
18+
>>> matches[0].fromy, matches[0].fromx
19+
(0, 0)
1420
>>> matches[0].ruleId, matches[0].replacements
1521
('UPPERCASE_SENTENCE_START', ['But'])
22+
>>> matches[1].fromy, matches[1].fromx
23+
(0, 9)
1624
>>> matches[1].ruleId, matches[1].replacements
1725
('SUPPOSE_TO', ['supposed'])
1826

1927

28+
Print a ``Match`` object:
29+
30+
>>> print(matches[1])
31+
Line 1, column 10, Rule ID: SUPPOSE_TO[1]
32+
Message: Probably you should use a past participle here: 'supposed'.
33+
Suggestion: supposed
34+
but it’s suppose to be all yellowy.
35+
^^^^^^^
36+
37+
38+
Automatically apply suggestions to the text:
39+
40+
>>> language_tool.correct(text, matches)
41+
'But it’s supposed to be all yellowy.'
42+
43+
2044
Installation
2145
------------
2246

‎language_tool/__init__.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ def __str__(self):
125125
if self.replacements:
126126
s += "\nSuggestion: {}".format("; ".join(self.replacements))
127127
s += "\n{}\n{}".format(
128-
self.context,
129-
" " * self.contextoffset + "^" * self.errorlength +
130-
" " * (len(self.context) - self.contextoffset - self.errorlength)
128+
self.context, " " * self.contextoffset + "^" * self.errorlength
129+
#+" " * (len(self.context) - self.contextoffset - self.errorlength)
131130
)
132131
return s
133132

0 commit comments

Comments
 (0)