Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Removes ignored characters from the specified environment string.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static string RemoveIgnoredCharacters(string environment, CIEOptions cieOptions)
        {
            if (string.IsNullOrEmpty(environment))
            {
                return(null);
            }

            var ignoredList = cieOptions.SearchQuery.GetIgnoredCharacters();
            var bldrEnv     = new StringBuilder(environment);

            // Get rid of all explicitly ignored characters (as opposed to
            // getting rid of all characters that are considered diacritics).
            bldrEnv = ignoredList.Aggregate(bldrEnv, (curr, ignoredChar) =>
                                            curr.Replace(ignoredChar, string.Empty));

            if (cieOptions.SearchQuery.IgnoreDiacritics)
            {
                // Loop through the characters in the environment string,
                // getting rid of diacritics.
                for (int i = bldrEnv.Length - 1; i >= 0; i--)
                {
                    char chr = bldrEnv[i];
                    if (chr != App.kBottomTieBarC && chr != App.kTopTieBarC)
                    {
                        var info = App.IPASymbolCache[chr];
                        if (info != null && !info.IsBase)
                        {
                            bldrEnv.Remove(i, 1);
                        }
                    }
                }
            }

            return(bldrEnv.ToString());
        }
Ejemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        public CIEOptions Clone()
        {
            var options = new CIEOptions();

            options.SearchQuery = SearchQuery.Clone();
            options.Type        = Type;
            options.CieType     = CieType;
            return(options);
        }
Ejemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Constructs an object to find the list of minimal pairs within the specified cache.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public CIEBuilder(WordListCache cache, SortOptions sortOptions, CIEOptions cieOptions)
        {
            if (cache == null || cache.Count <= 2)
            {
                return;
            }

            Cache        = cache;
            CIEOptions   = cieOptions;
            _sortOptions = sortOptions.Copy();
            _sortOptions.AdvSortOrder = (CIEOptions.Type == CIEOptions.IdenticalType.After ?
                                         new[] { 2, 0, 1 } : new[] { 1, 0, 2 });
        }
Ejemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// For the phonetic data in the specified entry, this method gets a pattern
        /// appropriate to the CIE options.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static string GetCIESimilarPattern(WordListCacheEntry entry, CIEOptions cieOptions)
        {
            if (cieOptions.Type == CIEOptions.IdenticalType.After)
            {
                string env = GetPatternvalue(RemoveIgnoredCharacters(entry.EnvironmentAfter, cieOptions), CIEOptions.IdenticalType.After);
                return("*__" + (string.IsNullOrEmpty(env) ? "#" : env));
            }

            if (cieOptions.Type == CIEOptions.IdenticalType.Before)
            {
                string env = GetPatternvalue(RemoveIgnoredCharacters(entry.EnvironmentBefore, cieOptions), CIEOptions.IdenticalType.Before);
                return((string.IsNullOrEmpty(env) ? "#" : env) + "__*");
            }

            string before = GetPatternvalue(RemoveIgnoredCharacters(entry.EnvironmentBefore, cieOptions), CIEOptions.IdenticalType.Before);
            string after  = GetPatternvalue(RemoveIgnoredCharacters(entry.EnvironmentAfter, cieOptions), CIEOptions.IdenticalType.After);

            return((string.IsNullOrEmpty(before) ? "#" : before) + "__" +
                   (string.IsNullOrEmpty(after) ? "#" : after));
        }