Back to LanguageTool Homepage - Privacy - Imprint

Api (http server) - new line not recognized


(Dawid) #1

I'm trying to make use of the built-in http server. For making requests I use curl (the one built in php). The text is encoded with urlencode() before "posting" (content-type: application/x-www-form-urlencoded).
The problem is that LanguageTool doesn't seem to recognize new lines (CRLF) and treat them as spaces, which obviously produces errors (typographical).


(Daniel Naber) #2

What exactly is the text you're checking? Could you also post the PHP snippet that makes the call?


(Dawid) #3

I have checked with GUI to compare results and it turns out that the newline isn't considered a sentence break. Only double newline (CRLFCRLF) does that. Strange, but I suppose it has something to do with language rules.

Here is the snippet:
$text="Pokonaj ból odpowiedzialnie\r\nAktualnie masz wyłączony JavaScript.";
$ch=curl_init('http://localhost:8081/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'language=pl&text='.urlencode($text));
$r=curl_exec($ch);
curl_close($ch);
var_dump(htmlentities($r));

If you change $text to "Pokonaj ból odpowiedzialnie\r\n\r\nAktualnie masz wyłączony JavaScript." it generates completely different error (the right one!).

The problem is solved for me. :wink:


(Daniel Naber) #4

This is expected - also see the "-b" option at http://wiki.languagetool.org/command-line-options. However, for the HTTP API there's no setting to change the behavior, so you need to modify your text before you send it.