Exemplo n.º 1
0
        /// <summary>Process_MultiWordCaps: Break words with Caps to multiple words</summary>
        /// <param name="regEx">Regular Expression to use</param>
        /// <param name="replace">Text to use to replace</param>
        private void Process_MultiWordCaps(string regEx, string replace)
        {
            //StringBuilder toReplace = new StringBuilder(50);
            List <string> replaceList = new List <string>(50);

            StringBuilder currWord  = new StringBuilder();
            StringBuilder upperWord = new StringBuilder();

            bool foundMulti1 = false;
            bool foundMulti2 = false;
            bool foundMulti3 = false;

            try
            {
                //LinkedListNode<wordToken> item = tokens.First;
                for (LinkedListNode <wordToken> item = tokens.First;
                     item != null;
                     item = item.Next)
                {
                    currWord.Length  = 0;
                    upperWord.Length = 0;

                    foundMulti1 = false;
                    foundMulti2 = false;
                    foundMulti3 = false;

                    foreach (char wChar in item.Value.Token)
                    {
                        if ((wChar.CompareTo('A') >= 0) && (wChar.CompareTo('Z') <= 0))
                        {
                            // Process Upper case letter
                            if (foundMulti1)
                            {
                                foundMulti2 = true;
                            }
                            foundMulti1 = true;
                            if (currWord.Length == 1)
                            {
                                upperWord.Append(currWord);
                                currWord.Length = 0;
                            }
                            else if (currWord.Length > 1)
                            {
                                if (upperWord.Length > 0)
                                {
                                    replaceList.Add(upperWord.ToString());
                                    upperWord.Length = 0;
                                }
                                replaceList.Add(currWord.ToString());
                                currWord.Length = 0;
                            }
                            currWord.Append(wChar);
                        }
                        else                         // Process lower case letter
                        {
                            foundMulti3 = true;
                            currWord.Append(wChar);
                        }
                    }

                    if (currWord.Length == 1)
                    {
                        if ((currWord[0].CompareTo('A') >= 0) && (currWord[0].CompareTo('Z') <= 0))
                        {
                            upperWord.Append(currWord);
                            currWord.Length = 0;
                        }
                    }

                    if (upperWord.Length > 0)
                    {
                        replaceList.Add(upperWord.ToString());
                    }

                    if (currWord.Length > 0)
                    {
                        replaceList.Add(currWord.ToString());
                    }
                    currWord.Length  = 0;
                    upperWord.Length = 0;

                    // Check if word contained Multi-Words
                    if (foundMulti1 && foundMulti2 && foundMulti3)
                    {
                        PrePost   spacePrePost = new PrePost(replace);
                        wordToken newToken     = new wordToken(item.Value.PreToken, replaceList[0], spacePrePost);
                        tokens.AddBefore(item, newToken);

                        for (int i = 1; i < replaceList.Count; i++)
                        {
                            PrePost AnotherPrePost = new PrePost(replace);
                            newToken = new wordToken(spacePrePost, replaceList[i], AnotherPrePost);
                            tokens.AddBefore(item, newToken);
                        }
                        newToken.PostToken = item.Value.PostToken;
                        LinkedListNode <wordToken> PrevItem = item.Previous;
                        tokens.Remove(item);
                        item     = PrevItem;
                        PrevItem = null;
                    }
                    replaceList.Clear();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        private void ParseTextToSpeak(string InTextToSpeak)
        {
            StringBuilder preToken = new StringBuilder();
            StringBuilder Token    = new StringBuilder();

            bool inWord = false;
            LinkedListNode <wordToken> theToken =
                new LinkedListNode <wordToken>(new wordToken(new PrePost(""), "", new PrePost("")));
            PrePost lastPreToken = new PrePost("");

            foreach (char theChar in InTextToSpeak)
            {
                // If found delemiter char
                if (wordCharDel.IndexOf(theChar) == -1)
                {
                    if (inWord)
                    {
                        theToken = new LinkedListNode <wordToken>(
                            new wordToken(lastPreToken,
                                          Token.ToString(),
                                          new PrePost("SetLater")));
                        tokens.AddLast(theToken);

                        preToken.Length = 0;
                        preToken.Append(theChar);

                        Token.Length = 0;
                        inWord       = false;
                    }
                    else
                    {
                        preToken.Append(theChar);
                    }
                }
                // found word char
                else
                {
                    if (inWord)
                    {
                        Token.Append(theChar);
                    }
                    else
                    {
                        if (preToken.Length > 0)
                        {
                            lastPreToken = new PrePost(preToken.ToString());
                            if (theToken.Value.PostToken.s.Length > 0)
                            {
                                theToken.Value.PostToken = lastPreToken;
                            }
                        }
                        Token.Append(theChar);
                        inWord = true;
                    }
                }
            }

            if (inWord)
            {
                lastPreToken = new PrePost(preToken.ToString());
                theToken     = new LinkedListNode <wordToken>(
                    new wordToken(lastPreToken,
                                  Token.ToString(),
                                  new PrePost("")));
                tokens.AddLast(theToken);
            }
            else
            {
                if ((preToken.Length > 0) && (theToken.Value.PostToken.s.Length > 0))
                {
                    lastPreToken             = new PrePost(preToken.ToString());
                    theToken.Value.PostToken = lastPreToken;
                }
            }
        }
Exemplo n.º 3
0
 public wordToken(PrePost _preToken, string _token, PrePost _postToken)
 {
     PreToken  = _preToken;
     Token     = _token;
     PostToken = _postToken;
 }