Grammalecte  Check-in [5f68edd979]

Overview
Comment:[core][fr] phonet: better code for isSimilAs()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fr | core
Files: files | file ages | folders
SHA3-256: 5f68edd979ac2c87ae27a9226b350e4e73f00ed3b776179931a405f190b6061c
User & Date: olr on 2020-11-14 13:46:50
Other Links: manifest | tags
Context
2020-11-14
13:57
[graphspell] dawg: fix building check-in: ec2ed0b1bc user: olr tags: graphspell, trunk
13:46
[core][fr] phonet: better code for isSimilAs() check-in: 5f68edd979 user: olr tags: core, fr, trunk
11:08
[build][core][fr][misc] phonet token, new syntax check-in: 98cbf77aef user: olr tags: build, core, fr, misc, trunk
Changes

Modified gc_lang/fr/modules-js/phonet.js from [62385b8be1] to [ea83f80d7b].

80
81
82
83
84
85
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
114
                    aSelect.add(sSimil);
                }
            }
        }
        return aSelect;
    },

    isSimilAs: function (sWord, sSimil) {
        // return True if <sWord> phonetically similar to <sSimil> (<sWord> tested with several casing)
        if (!sWord) {
            return false;
        }
        let lSimils = this.getSimil(sSimil);
        if (lSimils.length == 0) {
            return false;
        }
        if (lSimils.includes(sWord)) {
            return true;
        }
        if (sWord.slice(0,1).gl_isUpperCase()) {
            if (lSimils.includes(sWord.toLowerCase())) {
                return true;
            }
            if (sWord.gl_isUpperCase() && lSimils.includes(sWord.gl_toCapitalize())) {
                return true;
            }
        }



        return false;






    }
};


// Initialization
if (!phonet.bInit && typeof(process) !== 'undefined') {
    // NodeJS







|
|
|
|

|
|
|
|
|
|
|
<
<
<
|
<
|
|
|
>
>
>
|
>
>
>
>
>
>







80
81
82
83
84
85
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
114
115
116
117
118
119
                    aSelect.add(sSimil);
                }
            }
        }
        return aSelect;
    },

    _getSetNumber (sWord) {
        // return the set number where <sWord> belongs, else -1
        if (this._dWord.has(sWord)) {
            return this._dWord.get(sWord);
        }
        if (sWord.slice(0,1).gl_isUpperCase()) {
            if (this._dWord.has(sWord.toLowerCase())) {
                return this._dWord.get(sWord.toLowerCase());
            }
            if (sWord.gl_isUpperCase() && this._dWord.has(sWord.gl_toCapitalize())) {
                return this._dWord.get(sWord.gl_toCapitalize());
            }



        }

        return -1;
    },

    isSimilAs: function (sWord, sSimil) {
        // return True if <sWord> phonetically similar to <sSimil> (<sWord> tested with several casing)
        if (!sWord || !sSimil) {
            return false;
        }
        let n = this._getSetNumber(sWord);
        if (n == -1) {
            return false;
        }
        return n == this._getSetNumber(sSimil);
    }
};


// Initialization
if (!phonet.bInit && typeof(process) !== 'undefined') {
    // NodeJS

Modified gc_lang/fr/modules/phonet.py from [a7ff873dfd] to [cf22067e41].

48
49
50
51
52
53
54












55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    aSelect = set()
    for sSimil in getSimil(sWord):
        for sMorph in _dMorph.get(sSimil, []):
            if re.search(sPattern, sMorph):
                aSelect.add(sSimil)
    return aSelect














def isSimilAs (sWord, sSimil):
    "return True if <sWord> phonetically similar to <sSimil> (<sWord> tested with several casing)"
    if not sWord:
        return False
    lSimils = getSimil(sSimil)
    if not lSimils:
        return False
    if sWord in lSimils:
        return True
    if sWord[0:1].isupper():
        if sWord.lower() in lSimils:
            return True
        if sWord.isupper() and sWord.capitalize() in lSimils:
            return True
    return False







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



|

|
|

|
<
<
<
<
<
<
<
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







    aSelect = set()
    for sSimil in getSimil(sWord):
        for sMorph in _dMorph.get(sSimil, []):
            if re.search(sPattern, sMorph):
                aSelect.add(sSimil)
    return aSelect


def _getSetNumber (sWord):
    "return the set number where <sWord> belongs, else -1"
    if sWord in _dWord:
        return _dWord[sWord]
    if sWord[0:1].isupper():
        if sWord.lower() in _dWord:
            return _dWord[sWord.lower()]
        if sWord.isupper() and sWord.capitalize() in _dWord:
            return _dWord[sWord.capitalize()]
    return -1


def isSimilAs (sWord, sSimil):
    "return True if <sWord> phonetically similar to <sSimil> (<sWord> tested with several casing)"
    if not sWord or not sSimil:
        return False
    n = _getSetNumber(sWord)
    if n == -1:
        return False
    return n == _getSetNumber(sSimil)