Exemple #1
0
        /// ------------------------------------------------------------------------------------
        private PhoneCache GetPhonesFromWordCache(IEnumerable <WordCacheEntry> wordCache)
        {
            var phoneCache = new PhoneCache(_project);

            foreach (var entry in wordCache)
            {
                var phones = entry.Phones;

                if (phones == null)
                {
                    continue;
                }

                for (int i = 0; i < phones.Length; i++)
                {
                    // Don't bother adding break characters.
                    if (App.BreakChars.Contains(phones[i]))
                    {
                        continue;
                    }

                    if (!phoneCache.ContainsKey(phones[i]))
                    {
                        phoneCache.AddPhone(phones[i]);
                    }

                    // Determine if the current phone is the primary
                    // phone in an uncertain group.
                    bool isPrimaryUncertainPhone = (entry.ContiansUncertainties &&
                                                    entry.UncertainPhones.ContainsKey(i));

                    // When the phone is the primary phone in an uncertain group, we
                    // don't add it to the total count but to the counter that keeps
                    // track of the primary	uncertain phones. Then we also add to the
                    // cache the non primary uncertain phones.
                    if (!isPrimaryUncertainPhone)
                    {
                        phoneCache[phones[i]].TotalCount++;
                    }
                    else
                    {
                        phoneCache[phones[i]].CountAsPrimaryUncertainty++;

                        // Go through the uncertain phones and add them to the cache.
                        if (entry.ContiansUncertainties)
                        {
                            AddUncertainPhonesToCache(entry.UncertainPhones[i], phoneCache);
                            UpdateSiblingUncertainties(entry.UncertainPhones, phoneCache);
                        }
                    }
                }
            }

            AddUndefinedCharsToCaches(phoneCache);
            return(phoneCache);
        }
Exemple #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds the specified list of uncertain phones to the phone cache. It is assumed the
        /// first (i.e. primary) phone in the list has already been added to the cache and,
        /// therefore, it will not be added nor its count incremented.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static void AddUncertainPhonesToCache(string[] uncertainPhoneGroup,
                                                      PhoneCache phoneCache)
        {
            // Go through the uncertain phone groups, skipping the
            // primary one in each group since that was already added
            // to the cache above.
            for (int i = 1; i < uncertainPhoneGroup.Length; i++)
            {
                string phone = uncertainPhoneGroup[i];

                // Don't bother adding break characters.
                if (!App.BreakChars.Contains(phone))
                {
                    if (!phoneCache.ContainsKey(phone))
                    {
                        phoneCache.AddPhone(phone);
                    }

                    phoneCache[phone].CountAsNonPrimaryUncertainty++;
                }
            }
        }