From 1e81f6bbad20ca5e821f40b7024ee95588f07465 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Tue, 23 Sep 2014 15:31:43 +0100 Subject: Added item uses from wordnet database --- bladictionary.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'bladictionary.py') 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 " ) + parser = optparse.OptionParser( usage = "!define [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 "" -- cgit v1.2.3