Exemple #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Called when the desire is to build a word list that is not a list of find Phone
        /// search results.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void LoadWindow()
        {
            var cache = new WordListCache();

            foreach (var entry in Project.WordCache)
            {
                cache.Add(entry);
            }

            Initialize(cache);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add records to the m_cache.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void AddWords(string words, string pattern, string gloss)
        {
            m_recCache.Clear();
            var entry = new RecordCacheEntry(_prj);

            entry.SetValue(kPhonetic, words);
            entry.SetValue(kCVPattern, pattern);
            entry.SetValue(kGloss, gloss);
            entry.NeedsParsing = true;
            entry.DataSource   = m_dataSource;
            m_recCache.Add(entry);
            m_recCache.BuildWordCache(null);

            m_cache.Clear();
            foreach (var wcEntry in m_recCache.WordCache)
            {
                m_cache.Add(wcEntry);
            }
        }
        /// ------------------------------------------------------------------------------------
        private void AddWords(string words, string pattern)
        {
            var entry = new RecordCacheEntry(_prj);

            entry.NeedsParsing = true;
            entry.SetValue("Phonetic", words);
            entry.SetValue("CVPattern", pattern);
            _dataSource.ParseType = DataSourceParseType.OneToOne;
            entry.DataSource      = _dataSource;
            _recCache.Add(entry);
            _recCache.BuildWordCache(null);
            BuildPhoneSortKeysForTests();

            _cache.Clear();
            foreach (var wcEntry in _recCache.WordCache)
            {
                _cache.Add(wcEntry);
            }
        }
        public void SimplePOASortTest1()
        {
            AddWords("b\u0324it bag", null);
            var cache = new WordListCache();

            foreach (var entry in _recCache.WordCache)
            {
                cache.Add(entry);
            }

            Assert.IsNotNull(cache);

            _sortOptions.SortType        = PhoneticSortType.POA;
            _sortOptions.AdvancedEnabled = false;
            _sortOptions.SetPrimarySortField(_phoneticField, false, kAscending);
            cache.Sort(_sortOptions);

            Assert.AreEqual(2, cache.Count);
            Assert.AreEqual("bag", cache[0].WordCacheEntry["Phonetic"]);
            Assert.AreEqual("b\u0324it", cache[1].WordCacheEntry["Phonetic"]);
        }
        /// ------------------------------------------------------------------------------------
        public WordListCache FindMinimalPairs()
        {
            if (Cache == null || !Cache.IsForSearchResults)
            {
                return(null);
            }

            foreach (var entry in Cache)
            {
                entry.CIEGroupId = -1;
            }

            // First, send a message to see if there is an AddOn to find minimal pairs. If so,
            // then return the cache it generated instead of the one built by this method.
            object args = this;

            if (App.MsgMediator.SendMessage("FindMinimalPairsAlternate", args))
            {
                if (args is WordListCache)
                {
                    return(args as WordListCache);
                }
            }

            var cieGroups = new Dictionary <string, List <WordListCacheEntry> >();
            var noDups    = new HashSet <string>();

            foreach (var entry in Cache)
            {
                string pattern = GetCIEPattern(entry, _cieOptions);

                List <WordListCacheEntry> entryList;
                if (!cieGroups.TryGetValue(pattern, out entryList))
                {
                    entryList          = new List <WordListCacheEntry>();
                    cieGroups[pattern] = entryList;
                }

                var setItem = pattern + "+" + entry.SearchItem;

                if (!noDups.Contains(setItem))
                {
                    noDups.Add(setItem);
                    entryList.Add(entry);
                }
            }
            noDups.Clear();

            // The groups are not guaranteed to be in any particular order, just the words within groups.
            // TODO: Sort groups by POA, or MOA, based on what's specified in _sortOptions.

            // Create a new cache which is the subset containing minimal pair entries.
            int cieGroupId    = 0;
            var cieGroupTexts = new SortedList <int, string>();
            var cieCache      = new WordListCache();

            foreach (var grp in cieGroups.Where(g => g.Value.Count >= 2))
            {
                foreach (var entry in grp.Value)
                {
                    entry.CIEGroupId = cieGroupId;
                    cieCache.Add(entry);
                }

                cieGroupTexts[cieGroupId++] = grp.Key;
            }

            cieCache.IsMinimalPair      = true;
            cieCache.CIEGroupTexts      = cieGroupTexts;
            cieCache.IsForSearchResults = true;
            cieCache.Sort(_sortOptions);
            cieCache.SearchQuery = Cache.SearchQuery.Clone();
            return(cieCache);
        }