99 ... api_url='https://languagetool.org/api/v2/',
1010 ... lang='en-US',
1111 ... )
12- {'software': {'name': 'LanguageTool', 'version': '4.6-SNAPSHOT', 'buildDate': '2019-05-15 19:25', 'apiVersion': 1, 'premium': False, 'premiumHint': 'You might be missing errors only the Premium version can find. Contact us at support<at>languagetoolplus.com.', 'status': ''}, 'warnings': {'incompleteResults': False}, 'language': {'name': 'English (US)', 'code': 'en-US', 'detectedLanguage': {'name': 'English (US)', 'code': 'en-US', 'confidence': 0.561}}, 'matches': [{'message': 'Use "an" instead of \'a\' if the following word starts with a vowel sound, e.g. \'an article\', \'an hour\'', 'shortMessage': 'Wrong article', 'replacements': [{'value': 'an'}], 'offset': 8, 'length': 1, 'context': {'text': 'This is a example', 'offset': 8, 'length': 1}, 'sentence': 'This is a example', 'type': {'typeName': 'Other'}, 'rule': {'id': 'EN_A_VS_AN', 'description': "Use of 'a' vs. 'an'", 'issueType': 'misspelling', 'category': {'id': 'MISC', 'name': 'Miscellaneous'}}, 'ignoreForIncompleteSentence': False, 'contextForSureMatch': 1}]}
13-
1412"""
13+ from typing import Optional
14+
1515import requests
1616
1717
18- def get_languages (api_url ) :
18+ def get_languages (api_url : str ) -> list [ dict [ str , str ]] :
1919 """
2020 Return supported languages as a list of dictionaries.
2121
2222 Args:
2323 api_url (str): API base url.
2424
2525 Returns:
26- List [dict]:
26+ list [dict]:
2727 Supported languages as a list of dictionaries.
2828
2929 Each dictionary contains three keys, ``name``, ``code`` and
@@ -47,11 +47,15 @@ def _is_in_pwl(match, pwl):
4747 return word in pwl
4848
4949
50- def check (input_text , api_url , lang , mother_tongue = None , preferred_variants = None ,
51- enabled_rules = None , disabled_rules = None ,
52- enabled_categories = None , disabled_categories = None ,
53- enabled_only = False , picky = False , verbose = False ,
54- pwl = None , username = None , api_key = None ):
50+ def check (
51+ input_text : str , api_url : str ,
52+ lang : str , pwl : list [str ],
53+ mother_tongue : Optional [str ] = None ,
54+ preferred_variants : Optional [str ] = None ,
55+ enabled_rules : Optional [str ] = None , disabled_rules : Optional [str ] = None ,
56+ enabled_categories : Optional [str ] = None , disabled_categories : Optional [str ] = None ,
57+ enabled_only : bool = False , picky : bool = False , verbose : bool = False ,
58+ username : Optional [str ] = None , api_key : Optional [str ] = None ):
5559 """
5660 Check given text and return API response as a dictionary.
5761
@@ -105,7 +109,7 @@ def check(input_text, api_url, lang, mother_tongue=None, preferred_variants=None
105109 If ``True``, a more verbose output will be printed. Defaults to
106110 ``False``.
107111
108- pwl (List [str]):
112+ pwl (list [str]):
109113 Personal world list. A custom dictionary of words that should be
110114 excluded from spell checking errors.
111115
@@ -125,30 +129,38 @@ def check(input_text, api_url, lang, mother_tongue=None, preferred_variants=None
125129
126130 {
127131 "language": {
128- "code": "en-US",
132+ "name": "English (GB)",
133+ "code": "en-GB",
129134 "detectedLanguage": {
130- "code": "en-US",
135+ "name": "English (GB)",
136+ "code": "en-GB",
131137 "confidence": 0.561,
132- "name ": "English (US) ",
138+ "source ": "fasttext ",
133139 },
134- "name": "English (US)",
135140 },
141+ "sentenceRanges": [[0, 17]],
142+ "extendedSentenceRanges": [
143+ {"from": 0, "to": 17, "detectedLanguages": [{"language": "en", "rate": 1.0}]}
144+ ],
136145 "matches": [
137146 {
138- "context": {"length ": 1 , "offset": 8, "text ": "This is a example" },
147+ "context": {"text ": "This is a example" , "offset": 8, "length ": 1 },
139148 "contextForSureMatch": 1,
140149 "ignoreForIncompleteSentence": False,
141150 "length": 1,
142- "message": "Use \" an\" instead of 'a' if the following word "
143- "starts with a vowel sound, e.g. 'an article', 'an "
144- "hour'",
151+ "message": "Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g.\xa0 ‘an article’, ‘an hour’.",
145152 "offset": 8,
146153 "replacements": [{"value": "an"}],
147154 "rule": {
148155 "category": {"id": "MISC", "name": "Miscellaneous"},
149156 "description": "Use of 'a' vs. 'an'",
150157 "id": "EN_A_VS_AN",
151158 "issueType": "misspelling",
159+ "urls": [
160+ {
161+ "value": "https://languagetool.org/insights/post/indefinite-articles/"
162+ }
163+ ],
152164 },
153165 "sentence": "This is a example",
154166 "shortMessage": "Wrong article",
@@ -157,14 +169,12 @@ def check(input_text, api_url, lang, mother_tongue=None, preferred_variants=None
157169 ],
158170 "software": {
159171 "apiVersion": 1,
160- "buildDate": "2019-05-15 19:25",
172+ "buildDate": "2024-09-27 11:27:57 +0200",
173+ "version": "6.5",
161174 "name": "LanguageTool",
162175 "premium": False,
163- "premiumHint": "You might be missing errors only the Premium "
164- "version can find. Contact us at "
165- "support<at>languagetoolplus.com.",
176+ "premiumHint": "You might be missing errors only the Premium version can find. Contact us at support<at>languagetoolplus.com.",
166177 "status": "",
167- "version": "4.6-SNAPSHOT",
168178 },
169179 "warnings": {"incompleteResults": False},
170180 }
@@ -212,4 +222,5 @@ def check(input_text, api_url, lang, mother_tongue=None, preferred_variants=None
212222 match for match in matches
213223 if not _is_in_pwl (match , pwl )
214224 ]
225+ print (print (data ))
215226 return data
0 commit comments