Grammalecte  Check-in [62c389aedf]

Overview
Comment:[graphspell][js] rename vars
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | graphspell
Files: files | file ages | folders
SHA3-256: 62c389aedfcccfab8b10b30677e8e4db753e604df51fbedb904430d902748f44
User & Date: olr on 2018-02-13 13:38:43
Other Links: manifest | tags
Context
2018-02-16
15:46
[fx][graphspell] merge multid: multi-dictionaries > editable personal dictionary check-in: 607d532bca user: olr tags: trunk, new_feature, fx, graphspell
2018-02-13
13:39
[core][js] multi-dictionaries check-in: d8959f76a4 user: olr tags: core, multid
13:38
[graphspell][js] rename vars check-in: 62c389aedf user: olr tags: trunk, graphspell
10:47
[graphspell][js] spellchecker wrapper for ibdawg check-in: c989c20101 user: olr tags: trunk, graphspell
Changes

Modified graphspell-js/spellchecker.js from [80a940103f] to [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
}


${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)







|
|





|


>
>
|
|

|
|
|
<


|

|



>
>
|
>
>
>
|
>

<
>
>
>





|

|



|

|



|

|







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
}


${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)
146
147
148
149
150
151
152




            yield* this.oExtendedDic.select(sPattern);
        }
        if (this.oPersonalDic) {
            yield* this.oPersonalDic.select(sPattern);
        }
    }
}











>
>
>
>
155
156
157
158
159
160
161
162
163
164
165
            yield* this.oExtendedDic.select(sPattern);
        }
        if (this.oPersonalDic) {
            yield* this.oPersonalDic.select(sPattern);
        }
    }
}

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