Grammalecte  Diff

Differences From Artifact [80a940103f]:

To Artifact [ee0b03faf8]:


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48





49

50
51



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
146
147
148
149
150
151
152




}


${map}


const dDefaultDictionaries = new Map([
    ["fr", "fr.bdic"],
    ["en", "en.bdic"]
]);


class Spellchecker {

    constructor (sLangCode, sfMainDic="", sfExtendedDic="", sfPersonalDic="") {
        // returns true if the main dictionary is loaded
        this.sLangCode = sLangCode;


        if (sfMainDic === "") {
            sfMainDic = dDefaultDictionaries.gl_get(sLangCode, "");
        }
        this.oMainDic = this._loadDictionary(sfMainDic);
        this.oExtendedDic = this._loadDictionary(sfExtendedDic);
        this.oPersonalDic = this._loadDictionary(sfPersonalDic);
        return bool(this.oMainDic);
    }

    _loadDictionary (sfDictionary) {
        // returns an IBDAWG object
        if (sfDictionary === "") {
            return null;
        }
        try {
            return ibdawg.IBDAWG(sfDictionary);





        }

        catch (e) {
            console.log("Error: <" + sDicName + "> not loaded.");



            console.log(e.message);
            return null;
        }
    }

    setMainDictionary (sfDictionary) {
        // returns true if the dictionary is loaded
        this.oMainDic = this._loadDictionary(sfDictionary);
        return bool(this.oMainDic);
    }

    setExtendedDictionary (sfDictionary) {
        // returns true if the dictionary is loaded
        this.oExtendedDic = this._loadDictionary(sfDictionary);
        return bool(this.oExtendedDic);
    }

    setPersonalDictionary (sfDictionary) {
        // returns true if the dictionary is loaded
        this.oPersonalDic = this._loadDictionary(sfDictionary);
        return bool(this.oPersonalDic);
    }

    // IBDAWG functions

    isValidToken (sToken) {
        // checks if sToken is valid (if there is hyphens in sToken, sToken is split, each part is checked)
................................................................................
            yield* this.oExtendedDic.select(sPattern);
        }
        if (this.oPersonalDic) {
            yield* this.oPersonalDic.select(sPattern);
        }
    }
}











|
|





|


>
>
|
|

|
|
|
<


|

|



|
>
>
>
>
>
|
>

<
>
>
>





|

|



|

|



|

|







 







>
>
>
>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
155
156
157
158
159
160
161
162
163
164
165
}


${map}


const dDefaultDictionaries = new Map([
    ["fr", "fr.json"],
    ["en", "en.json"]
]);


class Spellchecker {

    constructor (sLangCode, mainDic=null, extentedDic=null, personalDic=null, sPath="") {
        // returns true if the main dictionary is loaded
        this.sLangCode = sLangCode;
        console.log(sLangCode);
        console.log(mainDic);
        if (mainDic === null) {
            mainDic = dDefaultDictionaries.gl_get(sLangCode, "");
        }
        this.oMainDic = this._loadDictionary(mainDic, sPath, true);
        this.oExtendedDic = this._loadDictionary(extentedDic, sPath);
        this.oPersonalDic = this._loadDictionary(personalDic, sPath);

    }

    _loadDictionary (dictionary, sPath, bNecessary=false) {
        // returns an IBDAWG object
        if (dictionary === null) {
            return null;
        }
        try {
        	if (typeof(require) !== 'undefined') {
        		console.log(">>>> <resource:>");
                return new ibdawg.IBDAWG(dictionary);  // dictionary can be a filename or a JSON object
            } else {
            	console.log(">>>> no <resource:>");
                return new IBDAWG(dictionary, sPath);  // dictionary can be a filename or a JSON object
            }
        }
        catch (e) {

        	if (bNecessary) {
        		throw e.message;
        	}
            console.log(e.message);
            return null;
        }
    }

    setMainDictionary (dictionary) {
        // returns true if the dictionary is loaded
        this.oMainDic = this._loadDictionary(dictionary);
        return bool(this.oMainDic);
    }

    setExtendedDictionary (dictionary) {
        // returns true if the dictionary is loaded
        this.oExtendedDic = this._loadDictionary(dictionary);
        return bool(this.oExtendedDic);
    }

    setPersonalDictionary (dictionary) {
        // returns true if the dictionary is loaded
        this.oPersonalDic = this._loadDictionary(dictionary);
        return bool(this.oPersonalDic);
    }

    // IBDAWG functions

    isValidToken (sToken) {
        // checks if sToken is valid (if there is hyphens in sToken, sToken is split, each part is checked)
................................................................................
            yield* this.oExtendedDic.select(sPattern);
        }
        if (this.oPersonalDic) {
            yield* this.oPersonalDic.select(sPattern);
        }
    }
}

if (typeof(exports) !== 'undefined') {
    exports.Spellchecker = Spellchecker;
}