コード例 #1
0
        private IEnumerable <string> ComputeForms(string noun)
        {
            var exceptions = ExceptionMapping.GetValueOrDefault(noun);

            if (exceptions != null)
            {
                foreach (var exception in exceptions)
                {
                    yield return(exception);
                }
                yield break;
            }

            var hyphenIndex = noun.LastIndexOf('-');

            var root = FindRoot(hyphenIndex > -1 ? noun.Substring(hyphenIndex + 1) : noun);
            var hyphenatadAppendage = hyphenIndex > -1 ? noun.Substring(0, hyphenIndex + 1) : string.Empty;
            IEnumerable <string> results;

            if (!ExceptionMapping.TryGetValue(root, out results))
            {
                foreach (var form in synthesize())
                {
                    yield return(form);
                }
            }
            else
            {
                foreach (var form in from result in results select hyphenatadAppendage + result)
                {
                    yield return(form);
                }
            }
            yield return(hyphenatadAppendage + root);

            IEnumerable <string> synthesize()
            {
                for (var i = 0; i < sufficies.Length; i++)
                {
                    if (root.EndsWith(endings[i]) || endings[i].Length == 0)
                    {
                        yield return(hyphenatadAppendage + root.Substring(0, root.Length - endings[i].Length) + sufficies[i]);

                        yield break;
                    }
                }
            }
        }
コード例 #2
0
        IEnumerable <string> ComputeForms(string containingRoot)
        {
            var hyphenIndex         = containingRoot.IndexOf('-');
            var root                = FindRoot(hyphenIndex > -1 ? containingRoot.Substring(0, hyphenIndex) : containingRoot);
            var hyphenatedAppendage = hyphenIndex > -1 ? root.Substring(hyphenIndex) : "";
            IEnumerable <string> exceptionalForms;

            if (!ExceptionMapping.TryGetValue(root, out exceptionalForms))
            {
                foreach (var(suffix, ending) in suffices.Zip(endings))
                {
                    if (root.EndsWith(suffix, ordinalIgnoreCase) || string.IsNullOrEmpty(ending))
                    {
                        if (root.EndsWith("y", ordinalIgnoreCase))
                        {
                            root = root.Substring(0, root.Length - 1) + 'i';
                        }
                        yield return(root + ending + hyphenatedAppendage);
                    }
                }
                yield break;
            }
        }