The unified diff between revisions [9813855c..] and [092dff1e..] is displayed below. It can also be downloaded as a raw diff.
#
#
# patch "config.py"
# from [3c9e18ecf6c0b0698927b01c8a8a22a92d9a096a]
# to [2f4bcd09716fcbb8fed88991cb35d2c009e34cfb]
#
# patch "dictionary.py"
# from [185ab44273d324d8c84cc268846da66d3d7b3a4b]
# to [ded8d84b5aaeecac34aa38ad943654147268e55e]
#
# patch "gcide.py"
# from [b2a42fe20e3942f622374afeec9b32b07a3bbc4a]
# to [f3482e219bb45d78339b2d7ad2785c8fa2e494cc]
#
============================================================
--- config.py 3c9e18ecf6c0b0698927b01c8a8a22a92d9a096a
+++ config.py 2f4bcd09716fcbb8fed88991cb35d2c009e34cfb
@@ -4,3 +4,4 @@ word_shelf = os.path.join(install_path,
install_path = '/Users/grahame/monotone/memes'
storage_path = os.path.join(install_path, 'storage')
word_shelf = os.path.join(install_path, 'word.shelf')
+word_db = os.path.join(install_path, 'word.db')
============================================================
--- dictionary.py 185ab44273d324d8c84cc268846da66d3d7b3a4b
+++ dictionary.py ded8d84b5aaeecac34aa38ad943654147268e55e
@@ -1,19 +1,25 @@
#!/usr/bin/env python
+import config
import sys
class Word(str):
def __init__(self, w):
str.__init__(self)
- self.info = {}
- def update(self, **kwargs):
- self.info.update(kwargs)
- return self
+ self._syllables = None
+ self._syllables_est = None
+ self.rhymes = None
+ self.source = None
def update_from(self, from_word):
- self.info.update(from_word.info)
- return self
+ self._syllables = self._syllables or from_word._syllables
+ self.rhymes = self.rhymes or from_word.rhymes
def __get_syllables(self):
- return self.info.get('syllables') or self.__syllable_estimate()
+ if self._syllables != None:
+ return self._syllables
+ else:
+ return self.__syllable_estimate()
+ def __set_syllables(self, s):
+ self._syllables = s
def __syllable_estimate(self):
"Last resort syllable counter. Reasonably accurate in English." \
"Allegedly works for French."
@@ -35,12 +41,11 @@ class Word(str):
count = count - 1
if count == 0: count = 1
return count
- if not self.info.has_key('syllable_estimate'):
- self.info['syllable_estimate'] = est()
- return self.info['syllable_estimate']
- syllables = property(__get_syllables, None, None, "The number of syllables in this word.")
-
-
+ if self._syllables_est == None:
+ self._syllables_est = est()
+ return self._syllables_est
+ syllables = property(__get_syllables, __set_syllables, None, "The number of syllables in this word.")
+
import shelve
if __name__ == '__main__':
@@ -64,29 +69,41 @@ if __name__ == '__main__':
def generate_db():
# these must have a words() method, which returns
# an iterator yielding Word instances.
- import gcide
- import wiktionary
- modules = [gcide]
-
- d = shelve.open('word.shelf')
+ d = shelve.open(config.word_shelf)
for word in words:
d[word] = word
d.close()
+ def to_sqlite():
+ from pysqlite2 import dbapi2 as sqlite
+ con = sqlite.connect(config.word_db)
+ cur = con.cursor()
+ cur.execute("delete from words")
+ for word in words:
+# print "inserting:", word, word.source, word.syllables, word.rhymes
+ cur.execute("""insert into words (word, source, syllables, rhymes) VALUES (?,?,?,?)""",
+ (word, word.source, word.syllables, word.rhymes))
+ con.commit()
+
commands = { 'syllable_estimate' : estimation_report,
- 'generate' : generate_db }
+ 'generate' : generate_db,
+ 'sqlite' : to_sqlite }
command = commands.get(sys.argv[1])
if not command:
sys.stderr.write('%s: command not understood.\n' % (sys.argv[0]))
sys.exit(1)
+ import gcide
+ import wiktionary
+ modules = [gcide]
+
words = {}
for module in modules:
module.Word = Word
for word in module.words():
to_update = words.setdefault(word, word)
+ to_update.source = "dict"
if id(to_update) != id(word):
to_update.update_from(word)
command()
-
============================================================
--- gcide.py b2a42fe20e3942f622374afeec9b32b07a3bbc4a
+++ gcide.py f3482e219bb45d78339b2d7ad2785c8fa2e494cc
@@ -48,8 +48,7 @@ def words():
if len(syllables) < 2:
continue
word = Word(''.join(syllables))
- word.update(syllables=len(syllables),
- in_gcide=True)
+ word.syllables = len(syllables)
yield word
doc.freeDoc()