Пример #1
0
        /// <inheritdoc />
        public override IEnumerable <PunReplacement> GetPossibleReplacements(PhoneticsWord originalWord)
        {
            for (var index = 1; index < originalWord.Syllables.Count - 1; index++)
            {
                var syllable = originalWord.Syllables[index];

                if (syllable.Nucleus.IsStressedVowel())
                {
                    var rhymeSyllable = syllable.GetRhymeSyllable;

                    foreach (var themeWord in ThemeWordLookup[new[] { rhymeSyllable }])
                    {
                        if (themeWord.Syllables.Count == 1 &&
                            !themeWord.Syllables.Single().Equals(syllable))
                        {
                            var spelling = GetSpelling(originalWord.Syllables.Take(index))
                                           + themeWord.Text + GetSpelling(
                                originalWord.Syllables.Skip(index + 1)
                                );

                            yield return(new PunReplacement(
                                             PunType.Infix,
                                             spelling,
                                             true,
                                             themeWord.Text
                                             ));
                        }
                    }
                }
            }
        }
Пример #2
0
        public static int?GetPunScore(PhoneticsWord originalPhoneticsWord, PhoneticsWord replacementPhoneticsWord)
        {
            if (IsSameWord(originalPhoneticsWord.Text, replacementPhoneticsWord.Text))
            {
                return(null);
            }

            var minLength = Math.Min(originalPhoneticsWord.Symbols.Count, replacementPhoneticsWord.Symbols.Count);

            if (minLength < 3)
            {
                return(null);
            }


            var longestStreak    = 0;
            var currentStreak    = 0;
            var unmatchedSymbols = 0;
            var otherMatches     = 0;

            void EndStreak()
            {
                if (longestStreak < currentStreak)
                {
                    otherMatches += longestStreak;
                    longestStreak = currentStreak;
                }
                else
                {
                    otherMatches += currentStreak;
                }

                currentStreak = 0;
            }

            for (var i = 0; i < minLength; i++)
            {
                if (originalPhoneticsWord.Symbols[i] == replacementPhoneticsWord.Symbols[i])
                {
                    currentStreak++;
                }
                else if (originalPhoneticsWord.SyllableTypes.Value[i] == replacementPhoneticsWord.SyllableTypes.Value[i])
                {
                    EndStreak();
                    otherMatches++;
                }
                else
                {
                    EndStreak();
                    unmatchedSymbols++;
                }
            }

            EndStreak();

            //now do the same thing going from the back

            for (var i = 0; i < minLength; i++)
            {
                if (originalPhoneticsWord.Symbols[^ (1 + i)] == replacementPhoneticsWord.Symbols[^ (1 + i)])
Пример #3
0
        /// <inheritdoc />
        public override IEnumerable <PunReplacement> GetPossibleReplacements(PhoneticsWord originalWord)
        {
            foreach (var themeWord in ThemeWordLookup[originalWord.Syllables])
            {
                var punType =
                    originalWord.Text.Equals(themeWord.Text, StringComparison.OrdinalIgnoreCase)
                    ? PunType.SameWord
                    : PunType.Identity;

                yield return(new PunReplacement(punType, themeWord.Text, false, themeWord.Text));
            }
        }
        /// <inheritdoc />
        public override IEnumerable <PunReplacement> GetPossibleReplacements(PhoneticsWord originalWord)
        {
            var sw = GetConsonantSyllables(originalWord);

            foreach (var themeWord in ThemeWordLookup[sw])
            {
                yield return(new PunReplacement(
                                 PunType.SameConsonants,
                                 themeWord.Text,
                                 false,
                                 themeWord.Text
                                 ));
            }
        }
Пример #5
0
 /// <inheritdoc />
 public override IEnumerable<PunReplacement> GetPossibleReplacements(PhoneticsWord originalWord)
 {
     foreach (var themeWord in ThemeWordLookup[originalWord.Syllables])
     {
         if (!themeWord.Text.Equals(originalWord.Text, StringComparison.OrdinalIgnoreCase))
         {
             yield return new PunReplacement(
                 PunType.Prefix,
                 themeWord.Text,
                 false,
                 themeWord.Text
             );
         }
     }
 }
        public override IEnumerable <PunReplacement> GetPossibleReplacements(PhoneticsWord originalWord)
        {
            var lastStressedVowelIndex =
                originalWord.Syllables.LastIndexOf(x => x.Nucleus.IsStressedVowel());

            if (lastStressedVowelIndex < 0)
            {
                yield break; //No stressed vowel
            }
            var syllables = originalWord.Syllables.Skip(lastStressedVowelIndex)
                            .Select((x, i) => i == 0 ? x.GetRhymeSyllable : x)
                            .ToList();

            foreach (var themeWord in ThemeWordLookup[syllables])
            {
                if (originalWord.Text.Contains(themeWord.Text))
                {
                    yield break;
                }

                if (themeWord.Syllables.Count == originalWord.Syllables.Count)
                {
                    yield return(new PunReplacement(
                                     PunType.PerfectRhyme,
                                     themeWord.Text,
                                     false,
                                     themeWord.Text
                                     ));
                }
                else if (themeWord.Syllables.Count < originalWord.Syllables.Count)
                {
                    var replacement = GetSpelling(originalWord.Syllables.Take(lastStressedVowelIndex))
                                      + themeWord.Text;

                    yield return(new PunReplacement(
                                     PunType.PerfectRhyme,
                                     replacement,
                                     false,
                                     themeWord.Text
                                     ));
                }
            }
        }
Пример #7
0
        /// <inheritdoc />
        public override IEnumerable <PunReplacement> GetPossibleReplacements(PhoneticsWord originalWord)
        {
            if (originalWord.Syllables.Count > 2)
            {
                var firstTwoSyllables = originalWord.Syllables.Take(2).ToList();

                foreach (var themeWord in ThemeWordLookup[firstTwoSyllables])
                {
                    if (!themeWord.Text.Equals(originalWord.Text, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return(new PunReplacement(
                                         PunType.SharedPrefix,
                                         themeWord.Text,
                                         false,
                                         themeWord.Text
                                         ));
                    }
                }
            }
        }
Пример #8
0
    /// <inheritdoc />
    public override IEnumerable<IReadOnlyList<Syllable>> GetThemeWordSyllables(PhoneticsWord word)
    {
        for (var i = 1; i < word.Syllables.Count - 1; i++)
        {
            var syllables = word.Syllables.Take(i).ToList();
            yield return syllables;

            var next = word.Syllables[i];

            if (next.Onset.Any())
            {
                var nextSyllables =  syllables.Take(syllables.Count - 1)
                    .Append(new Syllable(syllables.Last().Symbols.Concat(next.Onset).ToList()))
                    .ToList();

                yield return nextSyllables;
            }
                
        }

        //var extra = 
    }
Пример #9
0
 /// <inheritdoc />
 public override IEnumerable <IReadOnlyList <Syllable> > GetThemeWordSyllables(PhoneticsWord word)
 {
     if (word.Syllables.Count > 2)
     {
         yield return(word.Syllables.Take(2).ToList());
     }
 }
Пример #10
0
 /// <inheritdoc />
 public override IEnumerable <IReadOnlyList <Syllable> > GetThemeWordSyllables(PhoneticsWord word)
 {
     if (word.Syllables[^ 1].Nucleus.IsStressedVowel())
Пример #11
0
 public abstract IEnumerable <PunReplacement> GetPossibleReplacements(PhoneticsWord originalWord);
Пример #12
0
 public abstract IEnumerable <IReadOnlyList <Syllable> > GetThemeWordSyllables(PhoneticsWord word);
Пример #13
0
 /// <inheritdoc />
 public override IEnumerable <IReadOnlyList <Syllable> > GetThemeWordSyllables(PhoneticsWord word)
 {
     yield return(word.Syllables);
 }
        private static IReadOnlyList <Syllable> GetConsonantSyllables(PhoneticsWord word)
        {
            var syllables = word.Syllables.Select(s => s.GetNoConsonantSyllable).ToList();

            return(syllables);
        }
Пример #15
0
        /// <inheritdoc />
        public override IEnumerable <IReadOnlyList <Syllable> > GetThemeWordSyllables(PhoneticsWord word)
        {
            var lastStressedVowelIndex = word.Syllables.LastIndexOf(x => x.Nucleus.IsStressedVowel());

            if (lastStressedVowelIndex < 0)
            {
                yield break; //No stressed vowel
            }
            var syllables = word.Syllables.Skip(lastStressedVowelIndex)
                            .Select((x, i) => i == 0 ? x.GetRhymeSyllable : x)
                            .ToList();

            yield return(syllables);
        }
Пример #16
0
 /// <inheritdoc />
 public override IEnumerable <IReadOnlyList <Syllable> > GetThemeWordSyllables(PhoneticsWord word)
 {
     if (word.Syllables.Count == 1)
     {
         yield return(word.Syllables.Select(x => x.GetRhymeSyllable).ToList());
     }
 }