From 02d0626ee9a64e4393db1e311f355ac5e0b041f5 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Thu, 26 Mar 2009 22:14:43 +0530 Subject: changes fir plugin architecture --- silpa/www/utils/__init__.py | 4 +++ silpa/www/utils/langdetect.py | 76 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 silpa/www/utils/__init__.py create mode 100644 silpa/www/utils/langdetect.py (limited to 'silpa/www/utils') diff --git a/silpa/www/utils/__init__.py b/silpa/www/utils/__init__.py new file mode 100644 index 0000000..b7b55b1 --- /dev/null +++ b/silpa/www/utils/__init__.py @@ -0,0 +1,4 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +from silpautils import * +from langdetect import * diff --git a/silpa/www/utils/langdetect.py b/silpa/www/utils/langdetect.py new file mode 100644 index 0000000..a75ba15 --- /dev/null +++ b/silpa/www/utils/langdetect.py @@ -0,0 +1,76 @@ +# Spellchecker with language detection +# coding: utf-8 +# +# Copyright © 2008 Santhosh Thottingal +# Released under the GPLV3+ license + +from common import * + +class LangDetect(SilpaModule): + + def detect_lang(self, text): + words=text.split(" ") + word_count=len(words) + word_iter=0 + word="" + result_dict=dict() + while word_iter < word_count: + word=words[word_iter] + if(word): + length = len(word) + index = 0 + while index < length: + letter=word[index] + if ((letter >= u'ം') & (letter <=u'൯')): + result_dict[word]= "ml_IN" + if ((letter >= u'ঁ') & (letter <= u'৺')): + result_dict[word]= "bn_IN" + if ((letter >= u'ँ') & (letter <= u'ॿ')): + result_dict[word]= "hi_IN" + if ((letter >=u'ઁ') & (letter <= u'૱')): + result_dict[word]= "gu_IN" + if ((letter >= u'ਁ') & (letter <=u'ੴ')): + result_dict[word]= "pa_IN" + if ((letter >= u'ಂ') & (letter <=u'ೲ')): + result_dict[word]= "ka_IN" + if ((letter >= u'ଁ') & (letter <= u'ୱ')): + result_dict[word]= "or_IN" + if ((letter >=u'ஂ') & (letter <= u'௺')): + result_dict[word]= "ta_IN" + if ((letter >=u'ఁ') & (letter <= u'౯')): + result_dict[word]= "te_IN" + if ((letter <= u'z')): + result_dict[word]= "en_US" + + index=index+1 + word_iter=word_iter+1 + return result_dict + def process(self,form): + response = """ +

Language Detection

+

Enter the text for detecting the language in the below text area. + Language of each word will be detected. + You can give the text in any language and even with mixed language +

+
+ + + +
+
+ """ + if(form.has_key('input_text')): + text = action=form['input_text'].value .decode('utf-8') + response=response % text + detected_lang_dict = self.detect_lang(text) + response = response+"

Language Detection Results

" + response = response+"" + for key in detected_lang_dict: + response = response+"" + response = response+"
WordLanguage
"+key+""+detected_lang_dict[key]+"
" + else: + response=response % "" + return response + +def getInstance(): + return LangDetect() -- cgit