You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rcube_spellcheck_engine.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | This file is part of the Roundcube Webmail client |
  5. | |
  6. | Copyright (C) 2011-2013, Kolab Systems AG |
  7. | Copyright (C) 2008-2013, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Interface class for a spell-checking backend |
  15. +-----------------------------------------------------------------------+
  16. | Author: Thomas Bruederli <roundcube@gmail.com> |
  17. +-----------------------------------------------------------------------+
  18. */
  19. /**
  20. * Interface class for a spell-checking backend
  21. *
  22. * @package Framework
  23. * @subpackage Utils
  24. */
  25. abstract class rcube_spellcheck_engine
  26. {
  27. const MAX_SUGGESTIONS = 10;
  28. protected $lang;
  29. protected $error;
  30. protected $dictionary;
  31. protected $separator = '/[\s\r\n\t\(\)\/\[\]{}<>\\"]+|[:;?!,\.](?=\W|$)/';
  32. /**
  33. * Default constructor
  34. */
  35. public function __construct($dict, $lang)
  36. {
  37. $this->dictionary = $dict;
  38. $this->lang = $lang;
  39. }
  40. /**
  41. * Return a list of languages supported by this backend
  42. *
  43. * @return array Indexed list of language codes
  44. */
  45. abstract function languages();
  46. /**
  47. * Set content and check spelling
  48. *
  49. * @param string $text Text content for spellchecking
  50. *
  51. * @return bool True when no mispelling found, otherwise false
  52. */
  53. abstract function check($text);
  54. /**
  55. * Returns suggestions for the specified word
  56. *
  57. * @param string $word The word
  58. *
  59. * @return array Suggestions list
  60. */
  61. abstract function get_suggestions($word);
  62. /**
  63. * Returns misspelled words
  64. *
  65. * @param string $text The content for spellchecking. If empty content
  66. * used for check() method will be used.
  67. *
  68. * @return array List of misspelled words
  69. */
  70. abstract function get_words($text = null);
  71. /**
  72. * Returns error message
  73. *
  74. * @return string Error message
  75. */
  76. public function error()
  77. {
  78. return $this->error;
  79. }
  80. }