/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Closes a member containing one or more phones.
        /// </summary>
        /// <remarks>
        /// When we arrive at this method, we know we're about to close a member containing
        /// one or more phones. When closing the current member, it will contain the first
        /// phone in the run. If there is more than one phone, then new members are generated
        /// for each of the phones following the first one. Finally, the collection of those
        /// members is returned, with the first in the collection being "this".
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        private PatternGroupMember[] ClosePhoneRunMember()
        {
            MemberType = MemberType.SinglePhone;
            var memberPhones = new List <PatternGroupMember>();

            var phones = App.Project.PhoneticParser.Parse(Member, true,
                                                          Properties.Settings.Default.ConvertPatternsWithTranscriptionChanges);

            if (phones == null || phones.Length == 0)
            {
                return(null);
            }

            // First wrap up this member using the first phone in the run.
            CloseSinglePhoneMemeber(phones[0]);
            memberPhones.Add(this);

            // Now go through any following phones in the run and create new members for them.
            for (int i = 1; i < phones.Length; i++)
            {
                var member = new PatternGroupMember();
                member.CloseSinglePhoneMemeber(phones[i]);
                memberPhones.Add(member);
            }

            return(memberPhones.ToArray());
        }
        /// ------------------------------------------------------------------------------------
        private PatternGroup CreateOuterMostPatternGroup(string pattern)
        {
            //foreach (var grp in _tokenGroups.Values.OfType<PatternGroup>().Where(g => g.Members.Count == 1))
            //    grp.GroupType = GroupType.Sequential;

            var group = new PatternGroup(_currEnvType)
            {
                GroupType = GroupType.Sequential
            };
            PatternGroupMember member = null;

            foreach (char chr in pattern)
            {
                if (chr == '+')
                {
                    if (member != null)
                    {
                        group.AddRangeOfMembers(member.CloseMember() ?? new[] { member });
                        member = null;
                    }

                    group.AddMember(new PatternGroupMember("+"));
                }
                else if (chr < kMinToken)
                {
                    (member ?? (member = new PatternGroupMember())).AddToMember(chr);
                }
                else
                {
                    if (member != null)
                    {
                        group.AddRangeOfMembers(member.CloseMember() ?? new[] { member });
                        member = null;
                    }

                    group.AddMember(_tokenGroups[chr]);
                }
            }

            if (member != null)
            {
                group.AddRangeOfMembers(member.CloseMember() ?? new[] { member });
            }

            if (group.Members.Count == 1 && group.Members[0] is PatternGroup)
            {
                group = (PatternGroup)group.Members[0];
            }

            //if (group.Members.Count == 1 && group.Members[0] is PatternGroupMember)
            //    group.GroupType = GroupType.Sequential;

            return(group);
        }
Example #3
0
        public void CloseSinglePhoneMemberTest4()
        {
            const char dental     = '\u032A';
            const char aspiration = '\u02B0';

            var member = new PatternGroupMember();

            member.AddToMember('t');
            member.AddToMember(dental);
            member.AddToMember(App.kTopTieBarC);
            member.AddToMember('s');
            member.AddToMember(aspiration);
            member.CloseMember();

            Assert.AreEqual(string.Format("t{0}s", App.kTopTieBarC), member.Member);
            Assert.AreEqual(string.Format("{0}{1}", dental, aspiration), member.DiacriticPattern);
        }
Example #4
0
        public void CloseSinglePhoneMemberTest1()
        {
            const char dental     = '\u032A';
            const char aspiration = '\u02B0';

            var member = new PatternGroupMember();

            member.AddToMember('t');
            member.AddToMember(dental);
            member.AddToMember(App.kBottomTieBarC);
            member.AddToMember('s');
            member.DiacriticPattern = aspiration.ToString();
            member.CloseMember();

            Assert.AreEqual(string.Format("t{0}s", App.kBottomTieBarC), member.Member);
            Assert.IsTrue(member.DiacriticPattern.IndexOf(dental) >= 0);
            Assert.IsTrue(member.DiacriticPattern.IndexOf(aspiration) >= 0);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This method goes through the pattern and replaces consonant and vowel class
        /// specifiers (i.e. [C] and [V]) and feature names between square brackets with
        /// tokens. The replacment includes the square brackets.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public string ReplaceSquarBracketedTextWithTokens(string pattern)
        {
            _tokenGroups.Clear();
            var match = FindInnerMostSquareBracketPairs(pattern);

            while (match.Success)
            {
                var bracketedText = match.Result("${bracketedText}");

                if (!bracketedText.Contains(App.DottedCircle))
                {
                    _tokenGroups[++_token] = new PatternGroupMember(bracketedText);
                }
                else
                {
                    _tokenGroups[++_token] = bracketedText;
                }

                pattern = ReplaceMatchedTextWithToken(pattern, match, _token);
                match   = match.NextMatch();
            }

            return(pattern.Replace("$", string.Empty));
        }