|
From: <hma...@us...> - 2010-01-28 07:08:06
|
Revision: 2079
http://ndlb.svn.sourceforge.net/ndlb/?rev=2079&view=rev
Author: hmazariegos
Date: 2010-01-28 07:07:59 +0000 (Thu, 28 Jan 2010)
Log Message:
-----------
added spelling lib
Added Paths:
-----------
portal/ror/plugins/tmb_engine/trunk/lib/spelling.rb
Added: portal/ror/plugins/tmb_engine/trunk/lib/spelling.rb
===================================================================
--- portal/ror/plugins/tmb_engine/trunk/lib/spelling.rb (rev 0)
+++ portal/ror/plugins/tmb_engine/trunk/lib/spelling.rb 2010-01-28 07:07:59 UTC (rev 2079)
@@ -0,0 +1,36 @@
+module Spelling
+ require 'net/https'
+ require 'uri'
+ require 'rexml/document'
+
+ ASPELL_WORD_DATA_REGEX = Regexp.new(/\&\s\w+\s\d+\s\d+(.*)$/)
+ #ASPELL_PATH = "/opt/local/bin/aspell"
+ ASPELL_PATH = "/usr/bin/aspell"
+
+ def check_spelling(spell_check_text, command, lang)
+ xml_response_values = Array.new
+ spell_check_text = spell_check_text.join(' ') if command == 'checkWords'
+ spell_check_response = `echo "#{spell_check_text}" | #{ASPELL_PATH} -a -l #{lang}`
+ if (spell_check_response != '')
+ spelling_errors = spell_check_response.split("\n").slice(1..-1)
+ if (command == 'checkWords')
+ for error in spelling_errors
+ error.strip!
+ if (match_data = error.match(ASPELL_WORD_DATA_REGEX))
+ arr = match_data[0].split(' ')
+ xml_response_values << arr[1]
+ end
+ end
+ elsif (command == 'getSuggestions')
+ for error in spelling_errors
+ error.strip!
+ if (match_data = error.match(ASPELL_WORD_DATA_REGEX))
+ xml_response_values << error.split(',')[1..-1].collect(&:strip!)
+ xml_response_values = xml_response_values.first
+ end
+ end
+ end
+ end
+ return xml_response_values
+ end
+end
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|