From 5a9083e18b10839b5459c6fb0152ab2fa0ed9ca5 Mon Sep 17 00:00:00 2001 From: Alexey Osipenko Date: Sun, 24 Mar 2013 16:57:22 +0400 Subject: [PATCH 1/2] Added Yandex spellchecker Supported languages: English, Russian, Ukrainian --- src/examples/english/text-yandex.html | 55 +++++++++++ src/examples/russian/text-yandex.html | 57 ++++++++++++ .../php/SpellChecker/Driver/Yandex.php | 91 +++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 src/examples/english/text-yandex.html create mode 100644 src/examples/russian/text-yandex.html create mode 100644 src/webservices/php/SpellChecker/Driver/Yandex.php diff --git a/src/examples/english/text-yandex.html b/src/examples/english/text-yandex.html new file mode 100644 index 0000000..cbea68f --- /dev/null +++ b/src/examples/english/text-yandex.html @@ -0,0 +1,55 @@ + + + + + jQuery Spell Checker example - Text parser using Yandex + + + + +

This example demonstrates how the text parser can be used to check the spelling of text in a form field.

+
+ +
+
+   + + + + + + diff --git a/src/examples/russian/text-yandex.html b/src/examples/russian/text-yandex.html new file mode 100644 index 0000000..d1bf941 --- /dev/null +++ b/src/examples/russian/text-yandex.html @@ -0,0 +1,57 @@ + + + + + + jQuery Spell Checker example + + + + + +

This example demonstrates how the text parser can be used to check the spelling of text in a form field.

+
+ +
+
+   + + + + + + diff --git a/src/webservices/php/SpellChecker/Driver/Yandex.php b/src/webservices/php/SpellChecker/Driver/Yandex.php new file mode 100644 index 0000000..21f13f7 --- /dev/null +++ b/src/webservices/php/SpellChecker/Driver/Yandex.php @@ -0,0 +1,91 @@ + 'ru,en' + ); + + const IGNORE_UPPERCASE = 1; + const IGNORE_DIGITS = 2; // ignore words with digits + const IGNORE_URLS = 4; + const FIND_REPEAT_WORDS = 8; + const IGNORE_LATIN = 16; + const NO_SUGGEST = 32; + const FLAG_LATIN = 128; + const IGNORE_CAPITALIZATION = 512; + + public function get_incorrect_words() + { + $texts = (array) \SpellChecker\Request::post('text'); + $options = self::IGNORE_DIGITS + self::IGNORE_URLS; + + $xml = $this->check_texts($texts, $options + self::NO_SUGGEST); + + $response = array(); + foreach ($xml->SpellResult as $result) + { + $words = array(); + foreach ($result->error as $error) + { + $words[] = (string) $error->word[0]; + } + $response[] = $words; + } + + $this->send_data('success', $response); + } + + public function get_word_suggestions($word = NULL) + { + $xml = $this->check_texts(array($word), 0); + + $suggestions = array(); + $result = $xml->SpellResult[0]; + foreach ($result->error as $error) + { + foreach ($error->s as $s) + { + $suggestions[] = (string) $s; + } + break; + } + + return $suggestions; + } + + public function check_word($word = NULL) {} + + private function check_texts($texts, $options) + { + $url = 'http://speller.yandex.net/services/spellservice/checkTexts'; + + $body = 'lang=' . urlencode($this->_config['lang']); + $body .= '&options=' . $options; + foreach ($texts as $text) + { + $body .= "&text=" . urlencode($text); + } + + if (!function_exists('curl_init')) + { + exit('Curl is not available'); + } + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + $xml_response = curl_exec($ch); + curl_close($ch); + + return simplexml_load_string($xml_response); + } +} From ede140eebb8041876ed386d0c084a01e3e1909d0 Mon Sep 17 00:00:00 2001 From: Alexey Osipenko Date: Tue, 26 Mar 2013 09:59:14 +0400 Subject: [PATCH 2/2] Updated documentation: added driver 'Yandex' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 370a82e..56d8383 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The current version of the plugin is v0.2.4 Beta. * HTML parsing (for using the spellchecker within WSYIWYG editors) * Text parsing (for using the spellchecker on form fields) * Multiple fields -* Multiple PHP back-end drivers (Enchant, PSpell, Google) +* Multiple PHP back-end drivers (Enchant, PSpell, Google, Yandex) * Friendly API * Event based * MIT licensed