You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2e08dc5
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+58-39Lines changed: 58 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,33 +10,40 @@ This is a Python wrapper for [LanguageTool](https://languagetool.org). LanguageT
10
10
11
11
## Local and Remote Servers
12
12
13
-
By default, `language_tool_python` will download a LanguageTool server `.jar` and run that in the background to detect grammar errors locally. However, LanguageTool also offers a [Public HTTP Proofreading API](http://wiki.languagetool.org/public-http-api) that is supported as well. Follow the link for rate limiting details. (Running locally won't have the same restrictions.)
13
+
By default, `language_tool_python` will download a LanguageTool server `.jar` and run that in the background to detect grammar errors locally. However, LanguageTool also offers a [Public HTTP Proofreading API](https://dev.languagetool.org/public-http-api) that is supported as well. Follow the link for rate limiting details. (Running locally won't have the same restrictions.)
14
14
15
15
### Using `language_tool_python` locally
16
16
17
17
Local server is the default setting. To use this, just initialize a LanguageTool object:
18
18
19
-
import language_tool_python
20
-
tool = language_tool_python.LanguageTool('en-US') # use a local server (automatically set up), language English
19
+
```python
20
+
import language_tool_python
21
+
tool = language_tool_python.LanguageTool('en-US') # use a local server (automatically set up), language English
22
+
```
21
23
22
24
### Using `language_tool_python` with the public LanguageTool remote server
23
25
24
26
There is also a built-in class for querying LanguageTool's public servers. Initialize it like this:
25
27
26
-
import language_tool_python
27
-
tool = language_tool_python.LanguageToolPublicAPI('es') # use the public API, language Spanish
28
+
```python
29
+
import language_tool_python
30
+
tool = language_tool_python.LanguageToolPublicAPI('es') # use the public API, language Spanish
31
+
```
28
32
29
33
### Using `language_tool_python` with the another remote server
30
34
31
35
Finally, you're able to pass in your own remote server as an argument to the `LanguageTool` class:
32
36
33
-
import language_tool_python
34
-
tool = language_tool_python.LanguageTool('ca-ES', remote_server='https://language-tool-api.mywebsite.net') # use a remote server API, language Catalan
37
+
```python
38
+
import language_tool_python
39
+
tool = language_tool_python.LanguageTool('ca-ES', remote_server='https://language-tool-api.mywebsite.net') # use a remote server API, language Catalan
40
+
```
35
41
36
42
### Apply a custom list of matches with `utils.correct`
37
43
38
44
If you want to decide which `Match` objects to apply to your text, use `tool.check` (to generate the list of matches) in conjunction with `language_tool_python.utils.correct` (to apply the list of matches to text). Here is an example of generating, filtering, and applying a list of matches. In this case, spell-checking suggestions for uppercase words are ignored:
39
45
46
+
```python
40
47
>>> s ="Department of medicine Colombia University closed on August 1 Milinda Samuelli"
41
48
>>> is_bad_rule =lambdarule: rule.message =='Possible spelling mistake found.'andlen(rule.replacements) and rule.replacements[0][0].isupper()
42
49
>>>import language_tool_python
@@ -45,84 +52,96 @@ If you want to decide which `Match` objects to apply to your text, use `tool.che
45
52
>>> matches = [rule for rule in matches ifnot is_bad_rule(rule)]
'A sentence with an error in the Hitchhiker’s Guide to the Galaxy'
91
+
```python
92
+
>>> tool.correct(text)
93
+
'A sentence with an error in the Hitchhiker’s Guide to the Galaxy'
94
+
```
80
95
81
96
From the command line:
82
97
83
-
$ echo 'This are bad.' > example.txt
84
-
85
-
$ language_tool_python example.txt
86
-
example.txt:1:1: THIS_NNS[3]: Did you mean 'these'?
87
-
98
+
```bash
99
+
$ echo'This are bad.'> example.txt
100
+
$ language_tool_python example.txt
101
+
example.txt:1:1: THIS_NNS[3]: Did you mean 'these'?
102
+
```
88
103
89
104
## Installation
90
105
91
106
To install via pip:
92
107
93
-
$ pip install --upgrade language_tool_python
108
+
```bash
109
+
$ pip install --upgrade language_tool_python
110
+
```
94
111
95
112
### Customizing Download URL or Path
96
113
97
114
To overwrite the host part of URL that is used to download LanguageTool-{version}.zip:
98
115
99
-
$ export LTP_DOWNLOAD_HOST = [alternate URL]
116
+
```bash
117
+
$ export LTP_DOWNLOAD_HOST = [alternate URL]
118
+
```
100
119
101
120
This can be used to downgrade to an older version, for example, or to download from a mirror.
102
121
103
122
And to choose the specific folder to download the server to:
104
123
105
-
$ export LTP_PATH = /path/to/save/language/tool
124
+
```bash
125
+
$ export LTP_PATH = /path/to/save/language/tool
126
+
```
106
127
107
128
The default download path is `~/.cache/language_tool_python/`. The LanguageTool server is about 200 MB, so take that into account when choosing your download folder. (Or, if you you can't spare the disk space, use a remote URL!)
108
129
109
130
## Prerequisites
110
131
111
-
-`Python 3.5+ <https://www.python.org>`
112
-
-`LanguageTool <https://www.languagetool.org>` (Java 8.0 or higher)
132
+
-[Python 3.5+](https://www.python.org)
133
+
-[LanguageTool](https://www.languagetool.org) (Java 8.0 or higher)
113
134
114
135
115
136
The installation process should take care of downloading LanguageTool (it may
116
137
take a few minutes). Otherwise, you can manually download
117
-
`LanguageTool-stable.zip
118
-
<https://www.languagetool.org/download/LanguageTool-stable.zip>`_ and unzip it
138
+
[LanguageTool-stable.zip](https://www.languagetool.org/download/LanguageTool-stable.zip) and unzip it
119
139
into where the ``language_tool_python`` package resides.
120
140
121
141
### LanguageTool Version
122
142
123
143
As of April 2020, `language_tool_python` was forked from `language-check` and no longer supports LanguageTool versions lower than 4.0.
124
144
125
145
### Acknowledgements
126
-
This is a fork of https://github.com/myint/language-check/ (which is a fork of
127
-
https://bitbucket.org/spirit/language_tool) that produces more easily parsable
146
+
This is a fork of https://github.com/myint/language-check/ that produces more easily parsable
0 commit comments