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 deb9772
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+53-32Lines changed: 53 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,27 +16,34 @@ By default, `language_tool_python` will download a LanguageTool server `.jar` an
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,64 +52,78 @@ 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!)
0 commit comments