diff options
author | Joe Robinson <joe@lc8n.com> | 2014-09-21 03:17:12 +0100 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2014-09-21 03:17:12 +0100 |
commit | c25b3542dd182ce97816f135de2b41559ab72c44 (patch) | |
tree | 4dc049e0485c0d83569381919088513f29b9b5e9 | |
parent | a180f1a6f8a5dc7e96dbe15cf4a73488dc3b75ed (diff) |
Add support for multiple definitions in FOLDOC
-rwxr-xr-x | bladictionary.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/bladictionary.py b/bladictionary.py index 4ad0fd4..0adb568 100755 --- a/bladictionary.py +++ b/bladictionary.py @@ -7,7 +7,7 @@ import optparse from lxml import etree import sqlite3 -VERSION = "2.2.0" +VERSION = "2.2.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 @@ -310,6 +310,9 @@ def parse_foldoc(word, refer = False): found = False count_blank = 0 items = [] + multiple = False + id = 0 + skip = False #If it's been referred from another definition, include the new word if refer: @@ -340,23 +343,38 @@ def parse_foldoc(word, refer = False): count_blank += 1 if count_blank == 1: continue + elif multiple: + skip = True else: break #If the line is just one string enclosed in {}s, then it means "see also", so look up that word - if line[0] == "{" and line[-1] == "}": + if len(line) > 0 and line[0] == "{" and line[-1] == "}": item = parse_foldoc(line.strip("{} "), True)[0] items.append(item) return items - - for part in word_parts: - definition += part.strip().replace("{", "").replace("}", "") + " " + if line[0:2] == "1.": + multiple = True + + if multiple: + id_parts = line.split(".") + if id_parts[0].isdigit() and definition is not None and definition != "": + definition = definition[3:] + item = Definition(word, id, "foldoc", "tech", definition, [], [], []) + items.append(item) + id = id_parts[0] + definition = "" + skip = False + + if not skip: + for part in word_parts: + definition += part.strip().replace("{", "").replace("}", "") + " " if not found : return else: - item = Definition(word, 0, "foldoc", "tech", definition, [], [], []) + item = Definition(word, id, "foldoc", "tech", definition, [], [], []) items.append(item) return items |