diff options
author | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2009-04-22 23:42:35 +0530 |
---|---|---|
committer | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2009-04-22 23:42:35 +0530 |
commit | 550f1ef9f4cd12f6a75090fa14490effc1230631 (patch) | |
tree | 74fddb746c0b849e88ca375a3fa5fabb246ff82d | |
parent | 39d12a4a44fe0a2b386ba9562833f8bf6f6275f2 (diff) | |
download | AnjaliOldLipi.git-550f1ef9f4cd12f6a75090fa14490effc1230631.tar.gz AnjaliOldLipi.git-550f1ef9f4cd12f6a75090fa14490effc1230631.tar.xz AnjaliOldLipi.git-550f1ef9f4cd12f6a75090fa14490effc1230631.zip |
Bug Fixes
-rw-r--r-- | silpa/common/modulemanager.py | 9 | ||||
-rw-r--r-- | silpa/modules/fortune/fortune.py | 39 | ||||
-rw-r--r-- | silpa/modules/guesslanguages/guess_language.py | 2 | ||||
-rw-r--r-- | silpa/modules/hyphenator/hyphenator.py | 2 |
4 files changed, 36 insertions, 16 deletions
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+"<table class=\"table1\"><tr><th>Module</th><th>Description</th><th>Status</th></tr>" for action in module_dict: module_instance=self.getModuleInstance(action) - response = response+"<tr><td><a href='?action="+ action +"'>"+module_instance.get_module_name()+"</a></td>" - response = response+"<td>"+module_instance.get_info()+"</td><td>OK</td></tr>" + if(module_instance!=None): + response = response+"<tr><td><a href='?action="+ action +"'>"+module_instance.get_module_name()+"</a></td>" + response = response+"<td>"+module_instance.get_info()+"</td><td>OK</td></tr>" + else: + response = response+"<tr><td>"+action.replace("_"," ")+"</td>" + response = response+"<td>Error while retrieving module details</td><td>Fail</td></tr>" return response+"</table>" 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 = """ - <h2>Lemmatization</h2></hr> + <h2>Guess the language</h2></hr> <p>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 </p> 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+"<h2>Language Detection Results</h2></hr>" + response = response+"<h2>Hyphenation Results</h2></hr>" response = response+"<table class=\"table1\"><tr><th>Word</th><th>Hyphenated Word</th></tr>" for word in words: word=word.strip() |