summaryrefslogtreecommitdiff
path: root/bladictionary.py
diff options
context:
space:
mode:
authorJoe Robinson <joe@mumsnet.com>2014-09-23 15:31:43 +0100
committerJoe Robinson <joe@mumsnet.com>2014-09-23 15:31:43 +0100
commit1e81f6bbad20ca5e821f40b7024ee95588f07465 (patch)
tree01debcf0c785d2cf6ea900ed2b25a6ae5a843b43 /bladictionary.py
parent57d881279c1267c6d2fa98b90fb1496f138f466a (diff)
Added item uses from wordnet database
Diffstat (limited to 'bladictionary.py')
-rwxr-xr-xbladictionary.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/bladictionary.py b/bladictionary.py
index b5e3099..a46137d 100755
--- a/bladictionary.py
+++ b/bladictionary.py
@@ -8,7 +8,7 @@ from lxml import etree
import sqlite3
import requests
-VERSION = "2.3.0"
+VERSION = "2.3.1"
class Definition(object):
#ID is relative to the word type, eg noun 1, noun 2, verb 1, verb 2, not to the entire list
@@ -147,7 +147,7 @@ def parse_args():
if not args:
args = shlex.split(sys.stdin.read())
- parser = optparse.OptionParser( usage = "!define <term> <type> <dictionary>" )
+ parser = optparse.OptionParser( usage = "!define <term> [type] [dictionary] | types: noun, verb, adjective, adverb | dictionaries: wordnet, oed, foldoc, urban" )
parser.add_option( "-v", "--version", action = "store_true", help = "Print the version number" )
parser.add_option( "-c", "--channel", action = "store", help = "The IRC channel of the request")
options, args = parser.parse_args( args )
@@ -294,11 +294,22 @@ def get_sql(word):
rows = cur.fetchall()
for row in rows:
- item = Definition(row['word'], row['sub_id'], "db", types[row['type_id']-1], row['definition'], [], row['synset_id'], [])
- cur.execute("SELECT * from uses where definition_id = ?", [row['id']])
- rows = cur.fetchall()
- item.uses = rows
+ id = row['id']
+ word = row['word']
+ sub_id = row['sub_id']
+ type = types[row['type_id']-1]
+ definition = row['definition']
+ synset_id = row['synset_id']
+
+ cur.execute("SELECT * from uses where definition_id = ?", [id])
+ use_rows = cur.fetchall()
+ uses = []
+
+ for use in use_rows:
+ uses.append(use['quote'])
+
+ item = Definition(word, sub_id, "wn", type,definition, uses, synset_id, [])
items.append(item)
return items
@@ -453,7 +464,7 @@ def main():
items = parse_urban(word)
else:
if word_dict is None or word_dict == "":
- word_dict = "db"
+ word_dict = "wn"
items = get_sql(word)
foldoc_items = parse_foldoc(word)
if foldoc_items is not None and len(foldoc_items) > 0:
@@ -475,7 +486,7 @@ def main():
else:
max_length = 460
- types = ["n", "v", "adj", "adv", "tech"]
+ types = ["n", "v", "adj", "adv", "tech", "urban"]
type_id = 0
all_types = word_type is ""