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/modules/fortune/fortune.py | 39 ++++++++++++++++++-------- silpa/modules/guesslanguages/guess_language.py | 2 +- silpa/modules/hyphenator/hyphenator.py | 2 +- 3 files changed, 29 insertions(+), 14 deletions(-) (limited to 'silpa/modules') 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