Ejemplo n.º 1
0
        /// <summary>
        /// Cherche les phonèmes dans <c>pw</c> et complète <c>pw</c> pour qu'il contienne l'information.
        /// </summary>
        /// <param name="pw">Le <see cref="PhonWord"/> à analyser et à compléter avec ses phonèmes.</param>
        /// <param name="conf">La <see cref="Config"/> à utiliser au cours de cette analyse.</param>
        public void FindPhons(PhonWord pw, Config conf)
        {
            logger.ConditionalTrace("FindPhons");
            Debug.Assert(pw != null);

            if (!AutomDictionary.FindPhons(pw, conf))
            {
                int         pos = 0;
                string      w   = pw.GetWord();
                AutomLetter al;

                while (pos < w.Length)
                {
                    if (automLetters.TryGetValue(w[pos], out al))
                    {
                        al.FireRule(pw, ref pos, conf);
                    }
                    else if (automLetters.TryGetValue('*', out al))
                    {
                        // strange character encountered --> handle it as letter '*'
                        al.FireRule(pw, ref pos, conf);
                    }
                    else
                    {
                        // this should not happen!!
                        string message = String.Format(ConfigBase.cultF, "La règle générique n'existe pas et on en aurait besoin...");
                        throw new KeyNotFoundException(message);
                    }
                } // while
            }     // if
        }         // FindPhons
Ejemplo n.º 2
0
 /// <summary>
 /// Crée un <see cref="PhonInW"/>. Il n'est PAS ajouté à la liste des phonèmes du mot.
 /// </summary>
 /// <param name="inW">Le <see cref="PhonWord"/> à l'intérieur duquel se trouve le
 /// <see cref="PhonInW"/></param>
 /// <param name="inBeg">Postion dans le <see cref="TheText"/> de base, de la première
 /// lettre correspondant au phonème.</param>
 /// <param name="inEnd">Postion dans le <see cref="TheText"/> de base, de la dernière
 /// lettre correspondant au phonème.</param>
 /// <param name="inP">Le phonème</param>
 public PhonInW(PhonWord inW, int inBeg, int inEnd, Phonemes inP)
 // inBeg and inEnd are relative to the original TheText!
     : base(inW.T, inBeg, inEnd)
 {
     PW            = inW;
     P             = inP;
     firedRuleName = "NoRule";
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Crée un <see cref="PhonInW"/> et l'ajoute à la liste des phonèmes de
 /// <paramref name="inW"/>
 /// </summary>
 /// <param name="inW">Le <see cref="PhonWord"/> à l'intérieur duquel se trouve le
 /// <see cref="PhonInW"/></param>
 /// <param name="inBeg">Position dans le mot (<paramref name="inW"/>) de la première
 /// lettre qui correspond au phonème. 0 correspond à la première lettre du mot.</param>
 /// <param name="inEnd">Position dans le mot (<paramref name="inW"/>) de la dernière
 /// lettre qui correspond au phonème. 0 correspond à la première lettre du mot.</param>
 /// <param name="colSE">Le phonème au format ColSimplifiéEtendu.</param>
 /// <param name="ruleName">La règle qui a détecté le phonème.</param>
 public PhonInW(PhonWord inW, int inBeg, int inEnd, char colSE, string ruleName)
     : base(inW.T, inW.First + inBeg, inW.First + inEnd)
 {
     PW            = inW;
     P             = ColSE2phon(colSE);
     firedRuleName = ruleName;
     inW.AddPhon(this);
 }
Ejemplo n.º 4
0
        // Retourne la correspondance "Lexique" (voir lexique.org) du phonème.

        /// <summary>
        /// Crée un <see cref="PhonInW"/> et l'ajoute à la liste des phonèmes de
        /// <paramref name="inW"/>
        /// </summary>
        /// <param name="inW">Le <see cref="PhonWord"/> à l'intérieur duquel se trouve le
        /// <see cref="PhonInW"/></param>
        /// <param name="inBeg">Position dans le mot (<paramref name="inW"/>) de la première
        /// lettre qui correspond au phonème. 0 correspond à la première lettre du mot.</param>
        /// <param name="inEnd">Position dans le mot (<paramref name="inW"/>) de la dernière
        /// lettre qui correspond au phonème. 0 correspond à la première lettre du mot.</param>
        /// <param name="inP">Le phonème</param>
        /// <param name="ruleName">La règle qui a détecté le phonème.</param>
        public PhonInW(PhonWord inW, int inBeg, int inEnd, Phonemes inP, string ruleName)
            : base(inW.T, inW.First + inBeg, inW.First + inEnd)
        {
            PW            = inW;
            P             = inP;
            firedRuleName = ruleName;
            inW.AddPhon(this);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Essaye d'appliquer la règle pour <paramref name="pw"/> à la position <c>pos</c>. Si le filtre de la règle
        /// le permet, la règle est appliquée et le phonème correspondant est ajouté à <c>pw</c>. Sinon, rien n'est
        /// fait et <c>false est retourné</c>.
        /// </summary>
        /// <param name="pw">Le mot à analyser.</param>
        /// <param name="pos">La position dans le mot (zeor based) de la lettre examinée.</param>
        /// <param name="firstPart">La partie du texte qui précède la lettre dans le mot (les positions
        /// 0 à pos -1.</param>
        /// <param name="secondPart">La partie du texte qui suit la lettre dans le mot (les positions
        /// pos + 1 à Length - 1.</param>
        /// <param name="conf">La <see cref="Config"/> qui contient les paramètres concernant les flags à appliquer
        /// à la règle.</param>
        /// <returns><c>true</c> si la règle a été appliquée, <c>false</c> sinon.</returns>
        public bool TryApplyRule(PhonWord pw, ref int pos, string firstPart, string secondPart, Config conf)
        {
            logger.ConditionalTrace("TryApplyRule");
            bool found = conf.colors[PhonConfType.phonemes].GetFlag(flag) && rf.Check(pw, pos, firstPart, secondPart);

            if (found)
            {
                PhonInW piw = new PhonInW(pw, pos, pos + incr - 1, p, RuleName);
                pos = pos + incr;
            }
            return(found);
        }
        public void FindPhons(PhonWord pw)
        {
            Debug.Assert(pw != null);

            int         pos = 0;
            string      w   = pw.GetWord();
            AutomLetter al;

            while (pos < w.Length)
            {
                if (automLetters.TryGetValue(w[pos], out al))
                {
                    al.FireRule(pw, ref pos);
                }
                else
                {
                    // strange character encountered --> just leave it where it is... and go to the next char
                    pos++;
                }
            }     // while
        }         // FindPhons
Ejemplo n.º 7
0
        /// <summary>
        /// Fires the appropriate rule for the letter in <paramref name="pw"/> at position
        /// <paramref name="pos"/>. The <see cref="PhonWord"/> <c>pw</c> is expanded with the corresponding
        /// 'phonème'.
        /// </summary>
        /// <param name="pw">The <see cref="PhonWord"/> that must be analysed and where phonèmes must be identified.</param>
        /// <param name="pos">The position in <c>pw</c> (zero based) of the letter to analyse.</param>
        /// <param name="conf">The <see cref="Config"/> to use when deciding how the rules should be applied.</param>
        public void FireRule(PhonWord pw, ref int pos, Config conf)
        // Fires the appropriate rule for the letter in pw at position pos
        {
            logger.ConditionalTrace("FireRule");
            Debug.Assert(pw != null);
            bool   found = false;
            int    i = 0;
            string firstPart, secondPart;
            string w = pw.GetWord();

            Debug.Assert((w[pos] == Letter) || (Letter == '*'));
            firstPart = w.Substring(0, pos); // string before the letter under examination. if pos is the first letter in the string then ""
            if (pos == w.Length - 1)
            {
                secondPart = "";
            }
            else
            {
                secondPart = w.Substring(pos + 1, w.Length - (pos + 1)); // string after the letter under examination. if pos is the last letter in the string then ""
            }
            while ((!found) && (i < ruleOrder.Count))
            {
                AutomRule ar;
                if (rules.TryGetValue(ruleOrder[i], out ar))
                {
                    found = ar.TryApplyRule(pw, ref pos, firstPart, secondPart, conf);
                }
                else
                {
                    string message = String.Format(ConfigBase.cultF, "La règle \"{0}\" n'existe pas", ruleOrder[i]);
                    throw new KeyNotFoundException(message);
                }
                i++;
            }
            Debug.Assert(found, String.Format(ConfigBase.cultF, "Pas de règle pour pos {0} dans \"{1}\" ", pos, pw.GetWord()));
        } // public void FireRule
Ejemplo n.º 8
0
 public SylInW(PhonWord inW, int inBeg, int inEnd, Phonemes inP)
     : base(inW, inBeg, inEnd, inP)
 {
 }