From 550f1ef9f4cd12f6a75090fa14490effc1230631 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 22 Apr 2009 23:42:35 +0530 Subject: Bug Fixes --- silpa/common/modulemanager.py | 9 ++++-- silpa/modules/fortune/fortune.py | 39 ++++++++++++++++++-------- silpa/modules/guesslanguages/guess_language.py | 2 +- silpa/modules/hyphenator/hyphenator.py | 2 +- 4 files changed, 36 insertions(+), 16 deletions(-) (limited to 'silpa') diff --git a/silpa/common/modulemanager.py b/silpa/common/modulemanager.py index 8f9c79d..a3e9f1b 100644 --- a/silpa/common/modulemanager.py +++ b/silpa/common/modulemanager.py @@ -18,6 +18,7 @@ class ModuleManager: return obj def getModuleInstance(self,action): + action=action.replace(" ","_") module_name = self.find_module(action) if(module_name): try: @@ -37,8 +38,12 @@ class ModuleManager: response = response+"" for action in module_dict: module_instance=self.getModuleInstance(action) - response = response+"" - response = response+"" + if(module_instance!=None): + response = response+"" + response = response+"" + else: + response = response+"" + response = response+"" return response+"
ModuleDescriptionStatus
"+module_instance.get_module_name()+""+module_instance.get_info()+"OK
"+module_instance.get_module_name()+""+module_instance.get_info()+"OK
"+action.replace("_"," ")+"Error while retrieving module detailsFail
" if __name__ == '__main__': mm=ModuleManager() diff --git a/silpa/modules/fortune/fortune.py b/silpa/modules/fortune/fortune.py index e7aac98..cf31aad 100644 --- a/silpa/modules/fortune/fortune.py +++ b/silpa/modules/fortune/fortune.py @@ -1,22 +1,37 @@ -# Spellchecker with language detection -# coding: utf-8 +# Fortune +# -*- coding: utf-8 -*- # # Copyright © 2008 Santhosh Thottingal # Released under the GPLV3+ license -import os +import os,random from common import * class Fortune(SilpaModule): + def fortunes(self,infile,pattern=None): + """ Yield fortunes as lists of lines """ + result = [] + for line in infile: + line=line.decode("utf-8") + if line == "%\n": + yield result + result = [] + else: + if(pattern==None): + result.append(line) + else: + if(line.find(pattern)==-1): + result.append(line) + if result: + yield result + def fortune_ml(self, word): - if(word>""): - command = "/usr/games/fortune -m " + word + " ./modules/fortune/database/fortune-ml" - else: - command = "/usr/games/fortune ./modules/fortune/database/fortune-ml" - command=command.encode('utf-8') - pipe = os.popen('{ ' + command + '; } 2>&1', 'r') - text = pipe.read().decode('utf-8') - pipe.close() - return text + filename="./modules/fortune/database/fortune-ml" + """ Pick a random fortune from a file """ + for index, fortune in enumerate(self.fortunes(file(filename),None)): + if random.random() < (1.0 / (index+1)): + chosen = fortune + + return "".join(chosen) def process(self, form): response = """ diff --git a/silpa/modules/guesslanguages/guess_language.py b/silpa/modules/guesslanguages/guess_language.py index 1d88891..158b5f5 100644 --- a/silpa/modules/guesslanguages/guess_language.py +++ b/silpa/modules/guesslanguages/guess_language.py @@ -531,7 +531,7 @@ def normalize(u): class LangGuess(SilpaModule): def process(self, form): response = """ -

Lemmatization

+

Guess the language

Enter the text for guessing the language in the below text area. You can give the text in any language and even with mixed language

diff --git a/silpa/modules/hyphenator/hyphenator.py b/silpa/modules/hyphenator/hyphenator.py index 3f223d4..f5e8fe2 100644 --- a/silpa/modules/hyphenator/hyphenator.py +++ b/silpa/modules/hyphenator/hyphenator.py @@ -244,7 +244,7 @@ class Hyphenator(SilpaModule): text = action=form['input_text'].value .decode('utf-8') response=response % text words=text.split(" ") - response = response+"

Language Detection Results

" + response = response+"

Hyphenation Results

" response = response+"" for word in words: word=word.strip() -- cgit
WordHyphenated Word