LanguageTool

English main discussion
Post Reply
  • Author
  • Message
Offline
Posts: 4
Joined: Mon Jan 18, 2016 9:33 pm

LanguageTool

Post by Elgog »

Would it be possible to make a plugin that integrates akelpad with languagetool? I know most users are coders, but it'd be practical to have nonetheless. Langtool can work as a server, so it wouldn't be necesary to pack a 80mb big plugin, but just to make one that connects to the server.

Offline
Posts: 1162
Joined: Sun Oct 20, 2013 11:44 am

Post by Skif_off »

Elgog
Maybe plugin Log? Menu item (check path):

Code: Select all

-"LanguageTool EN" Call("Log::Output", 1, `java -jar "C:\Temp\LanguageTool-3.2\languagetool-commandline.jar" -l en`, "", "^\d+.\) Line (\d+), column (\d+)", "/GOTOLINE=\1:\2", -1, -1, 8192)
File must be saved.
When you click the line with error for example "1.) Line 4, column 10, Rule ID: WHITESPACE_RULE" AkelPad to rearrange the cursor to the position line 4, column 10.

If you want do not save the file, then you or someone need to write a script.

Offline
Posts: 1162
Joined: Sun Oct 20, 2013 11:44 am

Post by Skif_off »

Vile file encoding... It works without problems only with English:

Call("Log::Output", 1, "PROGRAM", "WORKDIR", "REPATTERN", "RETAGS", INPUTCODEPAGE, OUTPUTCODEPAGE, FLAGS, "ALIAS").

For other languages and for all we need to write a script.

Code: Select all

var hMainWnd  = AkelPad.GetMainWnd();
var nCodePage = AkelPad.GetEditCodePage(0);

AkelPad.Call("Log::Output", 1, `java -jar "C:\\Temp\\LanguageTool-3.2\\languagetool-commandline.jar" -l ru`, "", "^\\d+.\\) Line (\\d+), column (\\d+)", "/GOTOLINE=\\1:\\2", nCodePage, nCodePage, 8192)
?
It should work with OEM, ANSI, UTF-8.

Or UTF-8 only:

Code: Select all

var hMainWnd   = AkelPad.GetMainWnd();
var WshShell   = new ActiveXObject("WScript.Shell");
var pTextRange = AkelPad.GetTextRange(0, -1, 3);
var pTempFile;

pTempFile = WshShell.ExpandEnvironmentStrings("%Temp%") + "\\temp.txt";
AkelPad.WriteFile(pTempFile, pTextRange, -1, 65001, false);
AkelPad.Call("Log::Output", 1, "java -jar \"C:\\Temp\\LanguageTool-3.2\\languagetool-commandline.jar\" -l ru \"" + pTempFile + "\"", "", "^\\d+.\\) Line (\\d+), column (\\d+)", "/GOTOLINE=\\1:\\2", 65001, 65001, 8192)
?

Offline
Posts: 53
Joined: Wed Dec 09, 2015 6:33 pm

Post by beotiger »


Offline
Posts: 4
Joined: Mon Jan 18, 2016 9:33 pm

Post by Elgog »

Nice, works like a charm
Image
You'd probably want to change "-l en" for "-l en-GB", as otherwise LT disables spellechecking since it doesn't recognize "En" as a language.

Offline
Posts: 1162
Joined: Sun Oct 20, 2013 11:44 am

Post by Skif_off »

beotiger
I grew up and returned :) I think is necessary to find the optimal solution.

Offline
Posts: 4
Joined: Mon Jan 18, 2016 9:33 pm

Post by Elgog »

Since I don't want to create a new thread just for this: How do I give the selected text as part of a command?
I tried with

Code: Select all

"WordNet"
{
    "Overview" Call("Log::Output", 1, `f:\Program Files\WordNet\2.1\bin\wn.exe \s -over`)
}
but there wasn't any output.

Offline
Posts: 1162
Joined: Sun Oct 20, 2013 11:44 am

Post by Skif_off »

Elgog
For example:

Code: Select all

"WordNet"
{
    "Overview" Call("Scripts::Main", 1, "WordNet.js")
}
And save:

Code: Select all

//WordNet.js
//
// If not installed WordNet: manually edit line 20

var hMainWnd = AkelPad.GetMainWnd();
var pSelText = AkelPad.GetSelText();
var wsh      = new ActiveXObject("WScript.Shell");
var fso      = new ActiveXObject("Scripting.FileSystemObject");
var pWordNet;

// Search path WordNet in Registry
// x86 OS
if (KeyExists("HKEY_LOCAL_MACHINE\\SOFTWARE\\WordNet\\2.1\\") == 1)
  pWordNet = wsh.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\WordNet\\2.1\\WNHome") + "bin\\wn.exe";
// x64 OS
else if (KeyExists("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\WordNet\\2.1\\") == 1)
  pWordNet = wsh.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\WordNet\\2.1\\WNHome") + "bin\\wn.exe";
// Or
else
  pWordNet = "F:\\Program Files\\WordNet\\2.1\\bin\\wn.exe";

if (! fso.FileExists(pWordNet))
{
  AkelPad.MessageBox(hMainWnd, "WordNet not found!\n\nCheck path \"pWordNet\".", WScript.ScriptName, 48 /*MB_ICONWARNING*/);
  WScript.Quit();
}

// If selected text
if (pSelText.length > 1)
  AkelPad.Call("Log::Output", 1, "\"" + pWordNet + "\" \"" + pSelText + "\" -over", pWordNet.replace("\\wn.exe", ""), "", "", -1, -1, 40 /*Append text to the end|Wrap lines*/);

function KeyExists(key)
{
  var key2;
  try
  {
    key2 = wsh.RegRead(key);
    return 1;
  }
  catch (err)
  {
    return 0;
  }
}
as WordNet.js (use ANSI encoding) and move in \AkelFiles\Plugs\Scripts\.

P.S. Read comments.

Offline
Posts: 4
Joined: Mon Jan 18, 2016 9:33 pm

Post by Elgog »

Thanks! working perfectly fine.

Offline
Posts: 53
Joined: Wed Dec 09, 2015 6:33 pm

Post by beotiger »

Excuse me for some kind of offtopic maybe, but where should we add this:

Code: Select all

"WordNet"
{
    "Overview" Call("Scripts::Main", 1, "WordNet.js")
}
?

Offline
Posts: 1162
Joined: Sun Oct 20, 2013 11:44 am

Post by Skif_off »

beotiger
ContextMenu plugin, anywhere.
Post Reply