Skip to content

Commit 2e08dc5

Browse files
authored
Merge pull request jxmorris12#31 from aokellermann/documentation/FixMD
Documentation Edits
2 parents a0840a9 + 9beef18 commit 2e08dc5

1 file changed

Lines changed: 58 additions & 39 deletions

File tree

‎README.md‎

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,40 @@ This is a Python wrapper for [LanguageTool](https://languagetool.org). LanguageT
1010

1111
## Local and Remote Servers
1212

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.)
1414

1515
### Using `language_tool_python` locally
1616

1717
Local server is the default setting. To use this, just initialize a LanguageTool object:
1818

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+
```
2123

2224
### Using `language_tool_python` with the public LanguageTool remote server
2325

2426
There is also a built-in class for querying LanguageTool's public servers. Initialize it like this:
2527

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+
```
2832

2933
### Using `language_tool_python` with the another remote server
3034

3135
Finally, you're able to pass in your own remote server as an argument to the `LanguageTool` class:
3236

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+
```
3541

3642
### Apply a custom list of matches with `utils.correct`
3743

3844
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:
3945

46+
```python
4047
>>> s = "Department of medicine Colombia University closed on August 1 Milinda Samuelli"
4148
>>> is_bad_rule = lambda rule: rule.message == 'Possible spelling mistake found.' and len(rule.replacements) and rule.replacements[0][0].isupper()
4249
>>> import language_tool_python
@@ -45,84 +52,96 @@ If you want to decide which `Match` objects to apply to your text, use `tool.che
4552
>>> matches = [rule for rule in matches if not is_bad_rule(rule)]
4653
>>> language_tool_python.utils.correct(s, matches)
4754
'Department of medicine Colombia University closed on August 1 Melinda Sam
48-
55+
```
4956

5057
## Example usage
5158

5259
From the interpreter:
5360

54-
import language_tool_python
55-
tool = language_tool_python.LanguageTool('en-US')
56-
text = 'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy'
57-
matches = tool.check(text)
58-
len(matches)
59-
2
61+
```python
62+
>>> import language_tool_python
63+
>>> tool = language_tool_python.LanguageTool('en-US')
64+
>>> text = 'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy'
65+
>>> matches = tool.check(text)
66+
>>> len(matches)
67+
2
68+
```
6069

6170
Check out some ``Match`` object attributes:
6271

63-
matches[0].ruleId, matches[0].replacements
64-
('EN_A_VS_AN', ['an'])
65-
matches[1].ruleId, matches[1].replacements
66-
('TOT_HE', ['to the'])
72+
```python
73+
>>> matches[0].ruleId, matches[0].replacements # ('EN_A_VS_AN', ['an'])
74+
('EN_A_VS_AN', ['an'])
75+
>>> matches[1].ruleId, matches[1].replacements
76+
('TOT_HE', ['to the'])
77+
```
6778

6879
Print a ``Match`` object:
6980

70-
print(matches[1])
71-
Line 1, column 51, Rule ID: TOT_HE[1]
72-
Message: Did you mean 'to the'?
73-
Suggestion: to the
74-
...
81+
```python
82+
>>> print(matches[1])
83+
Line 1, column 51, Rule ID: TOT_HE[1]
84+
Message: Did you mean 'to the'?
85+
Suggestion: to the
86+
...
87+
```
7588

7689
Automatically apply suggestions to the text:
7790

78-
tool.correct(text)
79-
'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+
```
8095

8196
From the command line:
8297

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+
```
88103

89104
## Installation
90105

91106
To install via pip:
92107

93-
$ pip install --upgrade language_tool_python
108+
```bash
109+
$ pip install --upgrade language_tool_python
110+
```
94111

95112
### Customizing Download URL or Path
96113

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

99-
$ export LTP_DOWNLOAD_HOST = [alternate URL]
116+
```bash
117+
$ export LTP_DOWNLOAD_HOST = [alternate URL]
118+
```
100119

101120
This can be used to downgrade to an older version, for example, or to download from a mirror.
102121

103122
And to choose the specific folder to download the server to:
104123

105-
$ export LTP_PATH = /path/to/save/language/tool
124+
```bash
125+
$ export LTP_PATH = /path/to/save/language/tool
126+
```
106127

107128
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!)
108129

109130
## Prerequisites
110131

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)
113134

114135

115136
The installation process should take care of downloading LanguageTool (it may
116137
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
119139
into where the ``language_tool_python`` package resides.
120140

121141
### LanguageTool Version
122142

123143
As of April 2020, `language_tool_python` was forked from `language-check` and no longer supports LanguageTool versions lower than 4.0.
124144

125145
### 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
128147
results from the command-line.

0 commit comments

Comments
 (0)