Skip to content

Commit 00c6811

Browse files
committed
update README, remove xml and --api flag
1 parent 7936e39 commit 00c6811

4 files changed

Lines changed: 36 additions & 68 deletions

File tree

‎README.md‎

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,41 @@
1-
# language_tool_python
1+
# `language_tool_python`: a grammar checker for Python
22

3-
Python wrapper for LanguageTool.
4-
5-
.. image:: https://travis-ci.org/myint/language_tool_python.svg?branch=master
6-
:target: https://travis-ci.org/myint/language_tool_python
7-
:alt: Build status
8-
9-
This is a fork of https://github.com/myint/language_tool_python/ (which is a fork of
10-
https://bitbucket.org/spirit/language_tool) that produces more easily parsable
11-
results from the command-line.
3+
This is a Python wrapper for [LanguageTool](languagetool.org). LanguageTool is open-source grammar tool, also known as the spellchecker for OpenOffice. This library allows you to make to detect grammar errors and spelling mistakes through a Python script or through a command-line interface.
124

135
## Example usage
146

157
From the interpreter:
168

17-
>>> import language_tool_python
18-
>>> tool = language_tool_python.LanguageTool('en-US')
19-
>>> text = u'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy'
20-
>>> matches = tool.check(text)
21-
>>> len(matches)
22-
2
9+
> import language_tool_python
10+
> tool = language_tool_python.LanguageTool('en-US')
11+
> text = u'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy'
12+
> matches = tool.check(text)
13+
> len(matches)
14+
2
2315

2416
Check out some ``Match`` object attributes:
2517

26-
>>> matches[0].fromy, matches[0].fromx
27-
(0, 16)
28-
>>> matches[0].ruleId, matches[0].replacements
29-
('EN_A_VS_AN', ['an'])
30-
>>> matches[1].fromy, matches[1].fromx
31-
(0, 50)
32-
>>> matches[1].ruleId, matches[1].replacements
33-
('TOT_HE', ['to the'])
18+
> matches[0].fromy, matches[0].fromx
19+
(0, 16)
20+
> matches[0].ruleId, matches[0].replacements
21+
('EN_A_VS_AN', ['an'])
22+
> matches[1].fromy, matches[1].fromx
23+
(0, 50)
24+
> matches[1].ruleId, matches[1].replacements
25+
('TOT_HE', ['to the'])
3426

3527
Print a ``Match`` object:
3628

37-
>>> print(matches[1])
38-
Line 1, column 51, Rule ID: TOT_HE[1]
39-
Message: Did you mean 'to the'?
40-
Suggestion: to the
41-
...
29+
print(matches[1])
30+
Line 1, column 51, Rule ID: TOT_HE[1]
31+
Message: Did you mean 'to the'?
32+
Suggestion: to the
33+
...
4234

4335
Automatically apply suggestions to the text:
4436

45-
>>> language_tool_python.correct(text, matches)
46-
'A sentence with an error in the Hitchhiker’s Guide to the Galaxy'
37+
language_tool_python.correct(text, matches)
38+
'A sentence with an error in the Hitchhiker’s Guide to the Galaxy'
4739

4840
From the command line::
4941

@@ -59,9 +51,6 @@ To install via pip::
5951

6052
$ pip install --upgrade language_tool_python
6153

62-
If you are using Python 2, you'll need to install 3to2 beforehand::
63-
64-
$ pip install --upgrade 3to2
6554

6655
To overwrite the host part of URL that is used to download LanguageTool-{version}.zip::
6756

@@ -82,16 +71,11 @@ take a few minutes). Otherwise, you can manually download
8271
<https://www.languagetool.org/download/LanguageTool-stable.zip>`_ and unzip it
8372
into where the ``language_tool_python`` package resides.
8473

85-
## Vim plugin
74+
### LanguageTool Version
8675

87-
To use language_tool_python in Vim, install Syntastic_ and use the following
88-
settings:
76+
As of April 2020, `language_tool_python` was forked from `language-check` and no longer supports LanguageTool versions lower than 4.0.
8977

90-
.. code-block:: vim
91-
92-
let g:syntastic_text_checkers = ['language_tool_python']
93-
let g:syntastic_text_language_tool_python_args = '--language=en-US'
94-
95-
Customize your language as appropriate.
96-
97-
.. _Syntastic: https://github.com/scrooloose/syntastic
78+
### Acknowledgements
79+
This is a fork of https://github.com/myint/language-check/ (which is a fork of
80+
https://bitbucket.org/spirit/language_tool) that produces more easily parsable
81+
results from the command-line.

‎language_tool_python/__init__.py‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,11 @@
4040
from functools import total_ordering
4141
from weakref import WeakValueDictionary
4242

43-
try:
44-
from xml.etree import cElementTree as ElementTree
45-
except ImportError:
46-
from xml.etree import ElementTree
47-
4843
from .backports import subprocess
4944
from .which import which
5045

5146

52-
__version__ = '2.0'
47+
__version__ = '2.0.1'
5348

5449

5550
__all__ = ['LanguageTool', 'Error', 'get_languages', 'correct', 'get_version',
@@ -263,12 +258,6 @@ def check(self, text: str, srctext=None) -> [Match]:
263258
matches = response['matches']
264259
return [Match(match) for match in matches]
265260

266-
def _check_api(self, text: str, srctext=None) -> bytes:
267-
""" Match text against enabled rules (result in XML format)."""
268-
root = self._get_root(self._url, self._encode(text, srctext))
269-
return (b'<?xml version="1.0" encoding="UTF-8"?>\n' +
270-
ElementTree.tostring(root) + b"\n")
271-
272261
def _encode(self, text, srctext=None):
273262
params = {'language': self.language, 'text': text.encode('utf-8')}
274263
if srctext is not None:
@@ -409,12 +398,12 @@ def _start_local_server(cls):
409398
data = urllib.parse.urlencode(params).encode()
410399
try:
411400
with urlopen(cls._url, data, cls._TIMEOUT) as f:
412-
tree = ElementTree.parse(f)
401+
data = json.loads(f)
413402
except (IOError, http.client.HTTPException) as e:
414403
if err:
415404
raise err
416405
raise ServerError('{}: {}'.format(cls._url, e))
417-
root = tree.getroot()
406+
root = data
418407

419408
# LanguageTool 1.9+
420409
if root.get('software') != 'LanguageTool':

‎language_tool_python/main.py‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ def parse_args():
3131
parser.add_argument('--enabled-only', action='store_true',
3232
help='disable all rules except those specified in '
3333
'--enable')
34-
parser.add_argument('--api', action='store_true',
35-
help='print results as XML')
3634
parser.add_argument(
3735
'--version', action='version',
3836
version='%(prog)s {}'.format(__version__),
@@ -129,9 +127,8 @@ def main():
129127
return 1
130128
else:
131129
language = guess_language(text)
132-
if not args.api:
133-
print('Detected language: {}'.format(language),
134-
file=sys.stderr)
130+
print('Detected language: {}'.format(language),
131+
file=sys.stderr)
135132
if not language:
136133
return 1
137134
lang_tool.language = language
@@ -146,9 +143,7 @@ def main():
146143
lang_tool.enabled_only = args.enabled_only
147144

148145
try:
149-
if args.api:
150-
print_unicode(lang_tool._check_api(text).decode())
151-
elif args.apply:
146+
if args.apply:
152147
print_unicode(lang_tool.correct(text))
153148
else:
154149
for match in lang_tool.check(text):

‎setup.cfg‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ classifier=
1919
packages=
2020
language_tool_python
2121
language_tool_python.backports
22-
package_data=
22+
package_data=

0 commit comments

Comments
 (0)