Skip to content

Instantly share code, notes, and snippets.

@Farhaduneci
Last active February 21, 2024 13:17
Show Gist options
  • Save Farhaduneci/150a0c877ede9f0a171db7f9c5e676c6 to your computer and use it in GitHub Desktop.
Save Farhaduneci/150a0c877ede9f0a171db7f9c5e676c6 to your computer and use it in GitHub Desktop.
Language Tool JS Library Test
const languagetool = require("languagetool-api");
var params = {
language: "en-US",
text: "If i was you, i wouldt do that",
};
languagetool.check(params, function (err, res) {
if (err) {
console.log(err);
} else {
languagetool.bestSuggestion(res, function (arr) {
arr.forEach(function (item) {
console.log(
"Best suggestion for " +
item.mistake +
" is " +
item.bestSuggestion
);
});
});
}
});
// Output:
// Best suggestion for i is I
// Best suggestion for wouldt is would
{
"software": {
"name": "LanguageTool",
"version": "6.4.15",
"buildDate": "2024-02-20 15:07:03 +0100",
"apiVersion": 1,
"premium": true,
"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": 1,
"source": "ngram"
}
},
"matches": [
{
"message": "The personal pronoun “I” should be uppercase.",
"shortMessage": "",
"replacements": [
{
"value": "I"
}
],
"offset": 3,
"length": 1,
"context": {
"text": "If i was you, i woulnt do that",
"offset": 3,
"length": 1
},
"sentence": "If i was you, i woulnt do that",
"type": {
"typeName": "Other"
},
"rule": {
"id": "I_LOWERCASE",
"subId": "1",
"sourceFile": "grammar.xml",
"description": "i vs. I",
"issueType": "misspelling",
"category": {
"id": "TYPOS",
"name": "Possible Typo"
},
"isPremium": false
},
"ignoreForIncompleteSentence": true,
"contextForSureMatch": -1
},
{
"message": "Possible spelling mistake found.",
"shortMessage": "Spelling mistake",
"replacements": [
{
"value": "would"
},
{
"value": "Mount"
},
{
"value": "count"
},
{
"value": "mount"
},
{
"value": "wound"
},
{
"value": "wouldst"
},
{
"value": "fount"
},
{
"value": "wont"
},
{
"value": "wouldn"
},
{
"value": "woulds"
}
],
"offset": 16,
"length": 6,
"context": {
"text": "If i was you, i woulnt do that",
"offset": 16,
"length": 6
},
"sentence": "If i was you, i woulnt do that",
"type": {
"typeName": "UnknownWord"
},
"rule": {
"id": "MORFOLOGIK_RULE_EN_US",
"description": "Possible spelling mistake",
"issueType": "misspelling",
"category": {
"id": "TYPOS",
"name": "Possible Typo"
},
"isPremium": false
},
"ignoreForIncompleteSentence": false,
"contextForSureMatch": 0
}
],
"sentenceRanges": [
[
0,
30
]
],
"extendedSentenceRanges": [
{
"from": 0,
"to": 30,
"detectedLanguages": [
{
"language": "en",
"rate": 1
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment