From 925ba08ecb3ff12496d343a1a0a99daf9a32ad3d Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Tue, 24 Mar 2009 21:53:02 +0530 Subject: Adding Silpa framework --- silpa/utils/__init__.py | 4 +++ silpa/utils/langdetect.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++ silpa/utils/silpautils.py | 6 ++++ 3 files changed, 83 insertions(+) create mode 100644 silpa/utils/__init__.py create mode 100644 silpa/utils/langdetect.py create mode 100644 silpa/utils/silpautils.py (limited to 'silpa/utils') diff --git a/silpa/utils/__init__.py b/silpa/utils/__init__.py new file mode 100644 index 0000000..b7b55b1 --- /dev/null +++ b/silpa/utils/__init__.py @@ -0,0 +1,4 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +from silpautils import * +from langdetect import * diff --git a/silpa/utils/langdetect.py b/silpa/utils/langdetect.py new file mode 100644 index 0000000..c20ac3a --- /dev/null +++ b/silpa/utils/langdetect.py @@ -0,0 +1,73 @@ +# Spellchecker with language detection +# coding: utf-8 +# +# Copyright © 2008 Santhosh Thottingal +# Released under the GPLV3+ license + + +class LangDetect: + + 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 + diff --git a/silpa/utils/silpautils.py b/silpa/utils/silpautils.py new file mode 100644 index 0000000..486c854 --- /dev/null +++ b/silpa/utils/silpautils.py @@ -0,0 +1,6 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +if __name__ == '__main__': + body=" $$SILPA_BREADCRUMB$$ " + print body.replace("$$SILPA_BREADCRUMB$$","hi") -- cgit From c5368252e3091368ae55475757ed3134d6f84249 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Sun, 29 Mar 2009 17:59:40 +0530 Subject: new modules --- silpa/utils/langdetect.py | 12 +++++++++--- silpa/utils/silpautils.py | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) (limited to 'silpa/utils') diff --git a/silpa/utils/langdetect.py b/silpa/utils/langdetect.py index c20ac3a..727ea6d 100644 --- a/silpa/utils/langdetect.py +++ b/silpa/utils/langdetect.py @@ -4,8 +4,9 @@ # Copyright © 2008 Santhosh Thottingal # Released under the GPLV3+ license +from common import * -class LangDetect: +class LangDetect(SilpaModule): def detect_lang(self, text): words=text.split(" ") @@ -63,11 +64,16 @@ class LangDetect: response=response % text detected_lang_dict = self.detect_lang(text) response = response+"

Language Detection Results

" - response = response+"" + response = response+"
WordLanguage
" for key in detected_lang_dict: response = response+"" response = response+"
WordLanguage
"+key+""+detected_lang_dict[key]+"
" else: response=response % "" return response - + def get_module_name(self): + return "Indian Language Detector" + def get_info(self): + return "Detects the language of the given text word by word. Supports only Indian Language" +def getInstance(): + return LangDetect() diff --git a/silpa/utils/silpautils.py b/silpa/utils/silpautils.py index 486c854..02556af 100644 --- a/silpa/utils/silpautils.py +++ b/silpa/utils/silpautils.py @@ -1,6 +1,35 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- - +import codecs +def getTemplate(): + return open(getTemplateName()).read() +def getTemplateName(): + return loadConfiguration()["SILPA_TEMPLATE"] +def getCopyrightInfo(): + return loadConfiguration()["SILPA_SITE_COPYRIGHT"] +def getModulesList(): + conf_dict=loadConfiguration() + action_dict={} + for item in conf_dict : + if(item.startswith("SILPA_ACTION.")): + action_dict[item.replace("SILPA_ACTION.","")]=conf_dict[item] + return action_dict +def loadConfiguration(): + conf_dict={} + conffile = codecs. open("silpa.conf",encoding='utf-8', errors='ignore') + while 1: + text = unicode( conffile.readline()) + if text == "": + break + line = text.split("#")[0].strip() + if(line == ""): + continue + try: + lhs = line.split("=") [ 0 ] + rhs = line.split("=") [ 1 ] + conf_dict[lhs]=rhs + except: + pass + return conf_dict if __name__ == '__main__': - body=" $$SILPA_BREADCRUMB$$ " - print body.replace("$$SILPA_BREADCRUMB$$","hi") + print getModulesList() -- cgit