Back to LanguageTool Homepage - Privacy - Imprint

Count Grammar and Spelling Error


(Anjali Karn) #1

I like this tool very much and i have intregated it into my website also. I just want to know that can we count the grammatical errors and spelling errors of what it is showing.


(Daniel Naber) #2

This is not supported out of the box, you'll need to modify the Javascript code to do this.


(Anjali Karn) #3

first of all i would like to thank you for your response. can you please help me out in making changes in javascript and i also don't know what to change and where to change.
thanks in advance.


(Anjali Karn) #4

please Sir, help me out in making changes in Javascript. Can you please send me updated javascript code so that it can also counts errors.
Thanks inAdvance


(Alan) #5

If you have integrated LT on your website, why don't you code the number of errors found in PHP?

//first we load the outputted XML file
$xml=simplexml_load_file("$outputfile") or die("Error: Cannot create object");

//now we get the contents of that file
$grammarerrors = file_get_contents($outputfile);
//now we count the number of times FROMX appears in that file
$grammarerrorscount = substr_count($grammarerrors, 'fromx');

//now, let's print the number of errors
if ($grammarerrorscount==0){
          echo "<h3>Perfect!</h3>";
          echo "<div>Not a single grammar mistake was found!</div>";
  }
  elseif ($grammarerrorscount==1){
          echo "<h3>Only one grammar mistake!</h3>";
  }
  else {
          echo "<h3>You seem to have made $grammarerrorscount grammar mistakes!</h3>";
  }

(shada) #6

the same problem here I want to get the count of the grammar and spelling errors instead. Can you help me for the solution?


#7

Hi asmith, I already tried your code in my php page but somehow the output of the java script is not in xml form, could you please elaborate more on the script how to get the xml result? I use the java cript in http://wiki.languagetool.org/integration-on-websites

thx in advance


(Alan) #8

My PHP code does not alter javascript or LT. It takes the XML file which is generated by LT when a user processes an input, it counts the number of errors in that XML file, and it outputs the result in PHP.


#9

Do you know exactly where is LT put the XML file more precisely so I can pinpoint it to input it in the PHP code


(Alan) #10

Actually I've just noticed that the XML file format has been deprecated, so I'm going to have to make my own changes:

http://wiki.languagetool.org/command-line-options

Having said that, here's a simple PHP command-line integration code which specifies where to put the input file and the outputted XML file:

$inputfilename = md5($input);
$inputfile = "input-directory/$inputfilename" . '.txt';
$outputfile = "output-directory/$inputfilename" . '.xml';

$cmd = "java -jar languagetool/languagetool-commandline.jar -l en -c UTF-8 -d --api $inputfile > $outputfile 2>&1";

#11

Thank you!
For those who need an answer to workaround counting grammatical error from many text file in a folder here is the link