Grammalecte  Check-in [c075441c64]

Overview
Comment:[graphspell] spellchecker: handling exception when loading dictionary file
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | graphspell | multid
Files: files | file ages | folders
SHA3-256: c075441c64d3321bdc24f3a612ef4c86976b3eac38a702c8915a2df7d7cf1b8d
User & Date: olr on 2018-02-17 10:13:11
Other Links: branch diff | manifest | tags
Context
2018-02-17
11:31
[graphspell][js][bug] spellchecker: dictionary not always a filename string check-in: ae469535bc user: olr tags: graphspell, multid
10:13
[graphspell] spellchecker: handling exception when loading dictionary file check-in: c075441c64 user: olr tags: graphspell, multid
09:56
[build][core] add options for extended and personal dictionaries check-in: f91f4879a1 user: olr tags: build, core, multid
Changes

Modified graphspell-js/spellchecker.js from [61ed7ab1e9] to [2310ecd9b2].

    47     47               if (typeof(require) !== 'undefined') {
    48     48                   return new ibdawg.IBDAWG(dictionary);  // dictionary can be a filename or a JSON object
    49     49               } else {
    50     50                   return new IBDAWG(dictionary, sPath);  // dictionary can be a filename or a JSON object
    51     51               }
    52     52           }
    53     53           catch (e) {
    54         -            console.log(e.message);
    55     54               if (bNecessary) {
    56         -                throw e.message;
           55  +                throw "Error: <" + sfDictionary + "> not loaded. " + e.message;
    57     56               }
           57  +            console.log("Error: <" + sfDictionary + "> not loaded.")
           58  +            console.log(e.message);
    58     59               return null;
    59     60           }
    60     61       }
    61     62   
    62     63       setMainDictionary (dictionary) {
    63     64           // returns true if the dictionary is loaded
    64     65           this.oMainDic = this._loadDictionary(dictionary);

Modified graphspell/spellchecker.py from [9a77ab3107] to [638f8d8cdf].

    22     22   class SpellChecker ():
    23     23   
    24     24       def __init__ (self, sLangCode, sfMainDic="", sfExtendedDic="", sfPersonalDic=""):
    25     25           "returns True if the main dictionary is loaded"
    26     26           self.sLangCode = sLangCode
    27     27           if not sfMainDic:
    28     28               sfMainDic = dDefaultDictionaries.get(sLangCode, "")
    29         -        self.oMainDic = self._loadDictionary(sfMainDic)
           29  +        self.oMainDic = self._loadDictionary(sfMainDic, True)
    30     30           self.oExtendedDic = self._loadDictionary(sfExtendedDic)
    31     31           self.oPersonalDic = self._loadDictionary(sfPersonalDic)
    32     32   
    33         -    def _loadDictionary (self, sfDictionary):
           33  +    def _loadDictionary (self, sfDictionary, bNecessary=False):
    34     34           "returns an IBDAWG object"
    35     35           if not sfDictionary:
    36     36               return None
    37     37           try:
    38     38               return ibdawg.IBDAWG(sfDictionary)
    39         -        except:
           39  +        except Exception as e:
           40  +            if bNecessary:
           41  +                raise Exception(str(e), "Error: <" + sfDictionary + "> not loaded.")
    40     42               print("Error: <" + sfDictionary + "> not loaded.")
    41     43               traceback.print_exc()
    42     44               return None
    43     45   
    44     46       def setMainDictionary (self, sfDictionary):
    45     47           "returns True if the dictionary is loaded"
    46     48           self.oMainDic = self._loadDictionary(sfDictionary)