summaryrefslogtreecommitdiffstats
path: root/silpa/modules/dictionary/dictionary.py
diff options
context:
space:
mode:
Diffstat (limited to 'silpa/modules/dictionary/dictionary.py')
-rwxr-xr-x[-rw-r--r--]silpa/modules/dictionary/dictionary.py47
1 files changed, 27 insertions, 20 deletions
diff --git a/silpa/modules/dictionary/dictionary.py b/silpa/modules/dictionary/dictionary.py
index 4de0f76..927c06c 100644..100755
--- a/silpa/modules/dictionary/dictionary.py
+++ b/silpa/modules/dictionary/dictionary.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
-# English Malayalam Dictionary
+# Dictionary
# Copyright 2008 Santhosh Thottingal <santhosh.thottingal@gmail.com>
# http://www.smc.org.in
#
@@ -24,49 +24,56 @@
from common import *
import os
-import pickle
+from dictdlib import DictDB
class Dictionary(SilpaModule):
- def lookup_en_ml(self, key):
- key=key.lower()
- self.dictFile=os.path.dirname(__file__) + "/data/dict.dat"
- pickled_dict=open(self.dictFile,'r')
- self.dictionary=pickle.load(pickled_dict)
- meaning=""
- if self.dictionary.has_key(key):
- meaningList=self.dictionary[key]
- for meaning_item in meaningList:
- meaning=meaning+meaning_item.strip() +"<br/>"
- else :
- meaning="No Meaning found"
- return meaning.decode('utf-8')
+ def getdef(self, word, dictionary):
+ dict_dir=os.path.join(os.path.dirname(__file__), 'dictionaries')
+ dictdata=dict_dir+ "/"+dictionary
+ dict=DictDB(dictdata)
+ meanings = dict.getdef(word)
+ meaningstring= ""
+ if (meanings==None):
+ meaningstring = "No definition found"
+ return meaningstring
+ for meaning in meanings:
+ meaningstring += meaning
+ return meaningstring.decode("utf-8")
def process(self,form):
response = """
- <h2>English Malayalam Dictionary</h2></hr>
+ <h2>Dictionary</h2></hr>
<p>Enter the word to lookup in the dictionary
</p>
<form action="" method="post">
- <input type="text" value="%s" name="word"/>
+ <p align="center">
+ Word : <input type="text" value="%s" name="word"/>
+ Dictionary :<select id="dictionary" name="dictionary" style="width:12em;">
+ <option value="freedict-eng-hin">English-Hindi</option>
+ <option value="freedict-eng-mal">English-Malayalam</option>
+ </select>
<input type="hidden" name="action" value="Dictionary">
+ </br>
<input type="submit" id="Find_Meaning" value="Find Meaning" style="width:12em;"/>
</br>
+ </p>
</form>
"""
if(form.has_key('word')):
search_key = form['word'].value
+ dictionary = form['dictionary'].value
response=response % search_key
response = response+"<h2>Search Results</h2></hr>"
if(search_key==None):
response = response+ "Enter a word to find meaning."
else:
- response = response+ self.lookup_en_ml(search_key)
+ response = response+ "<pre> "+ self.getdef(search_key,dictionary) + "</pre> "
else:
response=response % ""
return response
def get_module_name(self):
- return "English Malayalam Dictionary"
+ return "Dictionary"
def get_info(self):
- return "English Malayalam Dictionary. Dictionary is compiled by Kerala state IT Mission"
+ return "Bilingual Dictionaries"
def getInstance():
return Dictionary()