Index: gc_lang/fr/modules-js/conj.js ================================================================== --- gc_lang/fr/modules-js/conj.js +++ gc_lang/fr/modules-js/conj.js @@ -86,47 +86,49 @@ getSimil: function (sWord, sMorph, bSubst=false) { if (!sMorph.includes(":V")) { return new Set(); } let sInfi = sMorph.slice(1, sMorph.indexOf(" ")); - let tTags = this._getTags(sInfi); let aSugg = new Set(); - if (!bSubst) { - // we suggest conjugated forms - if (sMorph.includes(":V1")) { - aSugg.add(sInfi); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":2p")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Iq", ":1s")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Iq", ":3s")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Iq", ":3p")); - } else if (sMorph.includes(":V2")) { - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); - } else if (sMorph.includes(":V3")) { - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":1s")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":3s")); - } else if (sMorph.includes(":V0a")) { - aSugg.add("eus"); - aSugg.add("eut"); - } else { - aSugg.add("étais"); - aSugg.add("était"); - } - aSugg.delete(""); - } else { - // we suggest past participles - aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q1")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q2")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q3")); - aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q4")); - aSugg.delete(""); - // if there is only one past participle (epi inv), unreliable. - if (aSugg.size === 1) { - aSugg.clear(); + let tTags = this._getTags(sInfi); + if (tTags) { + if (!bSubst) { + // we suggest conjugated forms + if (sMorph.includes(":V1")) { + aSugg.add(sInfi); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":2p")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Iq", ":1s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Iq", ":3s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Iq", ":3p")); + } else if (sMorph.includes(":V2")) { + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); + } else if (sMorph.includes(":V3")) { + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":1s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":3s")); + } else if (sMorph.includes(":V0a")) { + aSugg.add("eus"); + aSugg.add("eut"); + } else { + aSugg.add("étais"); + aSugg.add("était"); + } + aSugg.delete(""); + } else { + // we suggest past participles + aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q1")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q2")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q3")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q4")); + aSugg.delete(""); + // if there is only one past participle (epi inv), unreliable. + if (aSugg.size === 1) { + aSugg.clear(); + } } } return aSugg; }, @@ -181,20 +183,23 @@ class Verb { constructor (sVerb, sVerbPattern="") { // conjugate a unknown verb with rules from sVerbPattern if (typeof sVerb !== "string" || sVerb === "") { - throw new TypeError ("The value should be a non-empty string"); + throw new TypeError ("The value should be a non-empty string."); } if (sVerbPattern.length == 0) { sVerbPattern = sVerb; } this.sVerb = sVerb; this.sVerbAux = ""; this._sRawInfo = conj.getVtyp(sVerbPattern); this.sInfo = this._readableInfo(this._sRawInfo); this._tTags = conj._getTags(sVerbPattern); + if (!this._tTags) { + throw new RangeError ("Unknown verb."); + } this._tTagsAux = conj._getTags(this.sVerbAux); this.bProWithEn = (this._sRawInfo[5] === "e"); this.cGroup = this._sRawInfo[0]; this.dConj = new Map ([ [":Y", new Map ([ Index: gc_lang/fr/modules/conj.py ================================================================== --- gc_lang/fr/modules/conj.py +++ gc_lang/fr/modules/conj.py @@ -57,62 +57,63 @@ def getSimil (sWord, sMorph, bSubst=False): if ":V" not in sMorph: return set() sInfi = sMorph[1:sMorph.find(" ")] - tTags = _getTags(sInfi) - aSugg = set() - #if ":Q" in sMorph or ":Y" in sMorph: - if not bSubst: - # we suggest conjugated forms - if ":V1" in sMorph: - aSugg.add(sInfi) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":2p")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":1s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3p")) - elif ":V2" in sMorph: - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":1s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s")) - elif ":V3" in sMorph: - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":1s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":1s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":3s")) - elif ":V0a" in sMorph: - aSugg.add("eus") - aSugg.add("eut") - else: - aSugg.add("étais") - aSugg.add("était") - aSugg.discard("") - else: - # we suggest past participles - aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q1")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q2")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q3")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q4")) - aSugg.discard("") - # if there is only one past participle (epi inv), unreliable. - if len(aSugg) == 1: - aSugg.clear() + aSugg = set() + tTags = _getTags(sInfi) + if tTags: + if not bSubst: + # we suggest conjugated forms + if ":V1" in sMorph: + aSugg.add(sInfi) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":2p")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":1s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3p")) + elif ":V2" in sMorph: + aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":1s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s")) + elif ":V3" in sMorph: + aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":1s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":1s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":3s")) + elif ":V0a" in sMorph: + aSugg.add("eus") + aSugg.add("eut") + else: + aSugg.add("étais") + aSugg.add("était") + aSugg.discard("") + else: + # we suggest past participles + aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q1")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q2")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q3")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q4")) + aSugg.discard("") + # if there is only one past participle (epi inv), unreliable. + if len(aSugg) == 1: + aSugg.clear() return aSugg def getConjSimilInfiV1 (sInfi): if sInfi not in _dVerb: return set() - tTags = _getTags(sInfi) aSugg = set() - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":2s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3p")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":1s")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":2p")) - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":2p")) - aSugg.discard("") + tTags = _getTags(sInfi) + if tTags: + aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":2s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3p")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":1s")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":2p")) + aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":2p")) + aSugg.discard("") return aSugg def _getTags (sVerb): "returns tuple of tags (usable with functions _getConjWithTags and _hasConjWithTags)" @@ -148,13 +149,13 @@ class Verb (): def __init__ (self, sVerb, sVerbPattern=""): # conjugate a unknown verb with rules from sVerbPattern if not isinstance(sVerb, str): - raise TypeError + raise TypeError("sVerb should be a string") if not sVerb: - raise ValueError + raise ValueError("Empty string.") if sVerbPattern == "": sVerbPattern = sVerb self.sVerb = sVerb @@ -161,10 +162,12 @@ self.sVerbAux = "" self._sRawInfo = getVtyp(sVerbPattern) self.sInfo = self._readableInfo() self.bProWithEn = (self._sRawInfo[5] == "e") self._tTags = _getTags(sVerbPattern) + if not self._tTags: + raise ValueError("Unknown verb.") self._tTagsAux = _getTags(self.sVerbAux) self.cGroup = self._sRawInfo[0]; self.dConj = { ":Y": { "label": "Infinitif",