summaryrefslogtreecommitdiff
path: root/bladictionary.py
diff options
context:
space:
mode:
Diffstat (limited to 'bladictionary.py')
-rwxr-xr-xbladictionary.py37
1 files changed, 29 insertions, 8 deletions
diff --git a/bladictionary.py b/bladictionary.py
index 6d16240..58ddfeb 100755
--- a/bladictionary.py
+++ b/bladictionary.py
@@ -8,7 +8,7 @@ from lxml import etree
import sqlite3
import requests
-VERSION = "2.3.4"
+VERSION = "2.4.0"
class Definition(object):
#ID is relative to the word type, eg noun 1, noun 2, verb 1, verb 2, not to the entire list
@@ -278,10 +278,18 @@ def parse_oed(word):
return items
#Gets all matching WordNet definitions from the database
-def get_sql(word):
+def get_sql(word, dictionary = "wn"):
items = []
- types = ["n", "v", "adj", "adv"]
+ types = ["n", "v", "adj", "adv", "tech"]
+
+ if dictionary == "wordnet" or dictionary == "wn":
+ dict_id = 1
+ elif dictionary == "foldoc" or dictionary == "tech":
+ dict_id = 2
+ else:
+ print "Invalid dictionary"
+ sys.exit(1)
con = sqlite3.connect('dictionaries/wordnet.db');
con.row_factory = sqlite3.Row
@@ -289,10 +297,15 @@ def get_sql(word):
with con:
cur = con.cursor()
- cur.execute("SELECT * from definitions where word = ? ORDER BY type_id,sub_id;", [word])
+ cur.execute("SELECT * from definitions where word = ? and dictionary_id = ? ORDER BY type_id,sub_id;", [word, dict_id])
rows = cur.fetchall()
+ # If no results were found, try a case insensitive search
+ if rows is None or len(rows) == 0:
+ cur.execute("SELECT * from definitions where word = ? COLLATE NOCASE and dictionary_id = ? ORDER BY type_id,sub_id;", [word, dict_id])
+ rows = cur.fetchall()
+
for row in rows:
id = row['id']
@@ -301,6 +314,7 @@ def get_sql(word):
type = types[row['type_id']-1]
definition = row['definition']
synset_id = row['synset_id']
+ dictionary_id = row['dictionary_id']
cur.execute("SELECT * from uses where definition_id = ?", [id])
use_rows = cur.fetchall()
@@ -309,7 +323,14 @@ def get_sql(word):
for use in use_rows:
uses.append(use['quote'])
- item = Definition(word, sub_id, "wn", type,definition, uses, synset_id, [])
+ cur.execute("SELECT name from dictionaries where id = ?", [dictionary_id])
+ dict_row = cur.fetchone()
+ if dict_row is not None:
+ dictionary = dict_row[0]
+ else:
+ dictionary = "wn"
+
+ item = Definition(word, sub_id, dictionary, type,definition, uses, synset_id, [])
items.append(item)
return items
@@ -465,15 +486,15 @@ def main():
items = parse_xml(xml)
elif word_dict == "foldoc" or word_type == "tech":
- items = parse_foldoc(word)
+ items = get_sql(word, word_dict)
elif word_dict == "urban":
items = parse_urban(word)
else:
if word_dict is None or word_dict == "":
word_dict = "wn"
- items = get_sql(word)
+ items = get_sql(word, "wn")
- foldoc_items = parse_foldoc(word)
+ foldoc_items = get_sql(word, "foldoc")
if foldoc_items is not None and len(foldoc_items) > 0:
items += foldoc_items