Grammalecte  Check-in [ef57c2c66f]

Overview
Comment:[core][js] mfsp initialization
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | webext2
Files: files | file ages | folders
SHA3-256: ef57c2c66f7d7352f19d19b37da6d5d5e9bca714de0c2d0da3a59f1fbd2c454b
User & Date: olr on 2017-08-03 08:43:26
Other Links: branch diff | manifest | tags
Context
2017-08-03
09:06
[core][js] phonet initialization check-in: 1d14af8272 user: olr tags: core, webext2
08:43
[core][js] mfsp initialization check-in: ef57c2c66f user: olr tags: core, webext2
08:24
[core][js] conj initialization check-in: 63625992e9 user: olr tags: core, webext2
Changes

Modified gc_lang/fr/modules-js/conj.js from [a6c15a3f17] to [afb5910674].

477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
}


// Initialization
if (typeof(browser) !== 'undefined') {
    // WebExtension
    conj.init(helpers.loadFile(browser.extension.getURL("grammalecte/fr/conj_data.json")));
} else if (typeof(exports) !== 'undefined') {
    // Add-on SDK and Thunderbird
    let helpers = require("resource://grammalecte/helpers.js");
    conj.init(helpers.loadFile("resource://grammalecte/fr/conj_data.json"));
} else if (typeof(self) !== 'undefined') {
    // used within Firefox content script (conjugation panel).
    // can’t load JSON from here, so we do it in ui.js and send it here.
    self.port.on("provideConjData", function (sJSONData) {







|







477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
}


// Initialization
if (typeof(browser) !== 'undefined') {
    // WebExtension
    conj.init(helpers.loadFile(browser.extension.getURL("grammalecte/fr/conj_data.json")));
} else if (typeof(require) !== 'undefined') {
    // Add-on SDK and Thunderbird
    let helpers = require("resource://grammalecte/helpers.js");
    conj.init(helpers.loadFile("resource://grammalecte/fr/conj_data.json"));
} else if (typeof(self) !== 'undefined') {
    // used within Firefox content script (conjugation panel).
    // can’t load JSON from here, so we do it in ui.js and send it here.
    self.port.on("provideConjData", function (sJSONData) {

Modified gc_lang/fr/modules-js/mfsp.js from [26dca0e03e] to [7cd637b4cc].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
// Grammalecte

"use strict";


if (typeof(exports) !== 'undefined') {
    var helpers = require("resource://grammalecte/helpers.js");
}


const _oMfspData = JSON.parse(helpers.loadFile("resource://grammalecte/fr/mfsp_data.json"));

// list of affix codes
const _lTagMiscPlur = _oMfspData.lTagMiscPlur;
const _lTagMasForm = _oMfspData.lTagMasForm;

// dictionary of words with uncommon plurals (-x, -ux, english, latin and italian plurals) and tags to generate them
const _dMiscPlur = helpers.objectToMap(_oMfspData.dMiscPlur);



// dictionary of feminine forms and tags to generate masculine forms (singular and plural)





const _dMasForm = helpers.objectToMap(_oMfspData.dMasForm);





const mfsp = {
    isFemForm: function (sWord) {
        // returns True if sWord exists in _dMasForm
        return _dMasForm.has(sWord);
    },

    getMasForm: function (sWord, bPlur) {
        // returns masculine form with feminine form
        if (_dMasForm.has(sWord)) {
            return [ for (sTag of this._whatSuffixCode(sWord, bPlur))  this._modifyStringWithSuffixCode(sWord, sTag) ];
        }
        return [];
    },

    hasMiscPlural: function (sWord) {
        // returns True if sWord exists in dMiscPlur
        return _dMiscPlur.has(sWord);
    },

    getMiscPlural: function (sWord) {
        // returns plural form with singular form
        if (_dMiscPlur.has(sWord)) {
            return [ for (sTag of _lTagMiscPlur[_dMiscPlur.get(sWord)].split("|"))  this._modifyStringWithSuffixCode(sWord, sTag) ];
        }
        return [];
    },

    _whatSuffixCode: function (sWord, bPlur) {
        // necessary only for dMasFW
        let sSfx = _lTagMasForm[_dMasForm.get(sWord)];
        if (sSfx.includes("/")) {
            if (bPlur) {
                return sSfx.slice(sSfx.indexOf("/")+1).split("|");
            }
            return sSfx.slice(0, sSfx.indexOf("/")).split("|");
        }
        return sSfx.split("|");





|




<
|
|
|
|
<
|
|
>
>

|
>
>
>
>
>
|
|
>
>
|
>
|

|
|




|







|




|
|






|







1
2
3
4
5
6
7
8
9
10

11
12
13
14

15
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
// Grammalecte

"use strict";


if (typeof(require) !== 'undefined') {
    var helpers = require("resource://grammalecte/helpers.js");
}



const mfsp = {
    // list of affix codes
    _lTagMiscPlur: null,
    _lTagMasForm: null,

    // dictionary of words with uncommon plurals (-x, -ux, english, latin and italian plurals) and tags to generate them
    _dMiscPlur: {},
    // dictionary of feminine forms and tags to generate masculine forms (singular and plural)
    _dMasForm: {},

    init: function (sJSONData) {
        try {
            let _oData = JSON.parse(sJSONData);
            this._lTagMiscPlur = _oData.lTagMiscPlur;
            this._lTagMasForm = _oData.lTagMasForm;
            this._dMiscPlur = helpers.objectToMap(_oData.dMiscPlur);
            this._dMasForm = helpers.objectToMap(_oData.dMasForm);
        }
        catch (e) {
            console.error(e);
        }
    },

    isFemForm: function (sWord) {
        // returns True if sWord exists in this._dMasForm
        return this._dMasForm.has(sWord);
    },

    getMasForm: function (sWord, bPlur) {
        // returns masculine form with feminine form
        if (this._dMasForm.has(sWord)) {
            return [ for (sTag of this._whatSuffixCode(sWord, bPlur))  this._modifyStringWithSuffixCode(sWord, sTag) ];
        }
        return [];
    },

    hasMiscPlural: function (sWord) {
        // returns True if sWord exists in dMiscPlur
        return this._dMiscPlur.has(sWord);
    },

    getMiscPlural: function (sWord) {
        // returns plural form with singular form
        if (this._dMiscPlur.has(sWord)) {
            return [ for (sTag of this._lTagMiscPlur[this._dMiscPlur.get(sWord)].split("|"))  this._modifyStringWithSuffixCode(sWord, sTag) ];
        }
        return [];
    },

    _whatSuffixCode: function (sWord, bPlur) {
        // necessary only for dMasFW
        let sSfx = this._lTagMasForm[this._dMasForm.get(sWord)];
        if (sSfx.includes("/")) {
            if (bPlur) {
                return sSfx.slice(sSfx.indexOf("/")+1).split("|");
            }
            return sSfx.slice(0, sSfx.indexOf("/")).split("|");
        }
        return sSfx.split("|");
78
79
80
81
82
83
84












85
86
87
88
89
90
91
92
93
        catch (e) {
            console.log(e);
            return "## erreur, code : " + sSfx + " ##";
        }
    }
}














if (typeof(exports) !== 'undefined') {
    exports.isFemForm = mfsp.isFemForm;
    exports.getMasForm = mfsp.getMasForm;
    exports.hasMiscPlural = mfsp.hasMiscPlural;
    exports.getMiscPlural = mfsp.getMiscPlural;
    exports._whatSuffixCode = mfsp._whatSuffixCode;
    exports._modifyStringWithSuffixCode = mfsp._modifyStringWithSuffixCode;
}







>
>
>
>
>
>
>
>
>
>
>
>









86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
        catch (e) {
            console.log(e);
            return "## erreur, code : " + sSfx + " ##";
        }
    }
}


// Initialization
if (typeof(browser) !== 'undefined') {
    // WebExtension
    mfsp.init(helpers.loadFile(browser.extension.getURL("grammalecte/fr/mfsp_data.json")));
} else if (typeof(require) !== 'undefined') {
    // Add-on SDK and Thunderbird
    mfsp.init(helpers.loadFile("resource://grammalecte/fr/mfsp_data.json"));
} else {
    console.log("Error: Impossible d’initialiser le module mfsp");
}


if (typeof(exports) !== 'undefined') {
    exports.isFemForm = mfsp.isFemForm;
    exports.getMasForm = mfsp.getMasForm;
    exports.hasMiscPlural = mfsp.hasMiscPlural;
    exports.getMiscPlural = mfsp.getMiscPlural;
    exports._whatSuffixCode = mfsp._whatSuffixCode;
    exports._modifyStringWithSuffixCode = mfsp._modifyStringWithSuffixCode;
}

Modified gc_lang/fr/webext/gce_worker.js from [804f6b6cbe] to [0692342b85].

21
22
23
24
25
26
27


28
29
30
31
32
33
34
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
*/

helpers.echo("START");

helpers.echo(conj.getConj("devenir", ":E", ":2s"));




let oTokenizer = null;
let oDict = null;
let oLxg = null;

function loadGrammarChecker (sGCOptions="", sContext="JavaScript") {
    if (gce === null) {







>
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
*/

helpers.echo("START");

helpers.echo(conj.getConj("devenir", ":E", ":2s"));

helpers.echo(mfsp.getMasForm("emmerdeuse", true));
helpers.echo(mfsp.getMasForm("pointilleuse", false));

let oTokenizer = null;
let oDict = null;
let oLxg = null;

function loadGrammarChecker (sGCOptions="", sContext="JavaScript") {
    if (gce === null) {

Modified gc_lang/fr/webext/manifest.json from [282aafe91a] to [8518105802].

31
32
33
34
35
36
37

38
39
40
41
42
43
44
  },
  "background": {
    "scripts": [
      "grammalecte/helpers.js",
      "grammalecte/text.js",
      "grammalecte/tokenizer.js",
      "grammalecte/fr/conj.js",

      "gce_worker.js"
    ]
  },
  "web_accessible_resources": [
    "grammalecte/fr/conj_data.json",
    "grammalecte/fr/mfsp_data.json",
    "grammalecte/fr/phonet_data.json",







>







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  },
  "background": {
    "scripts": [
      "grammalecte/helpers.js",
      "grammalecte/text.js",
      "grammalecte/tokenizer.js",
      "grammalecte/fr/conj.js",
      "grammalecte/fr/mfsp.js",
      "gce_worker.js"
    ]
  },
  "web_accessible_resources": [
    "grammalecte/fr/conj_data.json",
    "grammalecte/fr/mfsp_data.json",
    "grammalecte/fr/phonet_data.json",