コード例 #1
0
        public override ISentence ParseSentence(string sentence)
        {
            var result = new Sentence();

            Func<string, ISentenceItem> toISentenceItem =
                item =>
                    (!PunctuationSeparator.AllSentenceSeparators.Contains(item) &&
                     !DigitSeparator.ArabicDigits.Contains(item[0].ToString()))
                        ? (ISentenceItem) new Word(item)
                        : (DigitSeparator.ArabicDigits.Contains(item[0].ToString()))
                            ? (ISentenceItem) new Digit(item)
                            : new Punctuation(item);

            foreach (Match match in _sentenceToWordsRegex.Matches(sentence))
            {
                for (var i = 1; i < match.Groups.Count; i++)
                {
                    if (match.Groups[i].Value.Trim() != "")
                    {
                        result.Items.Add(toISentenceItem(match.Groups[i].Value.Trim()));
                    }
                }
            }

            return result;
        }
コード例 #2
0
ファイル: Text.cs プロジェクト: Demenovich-A-J/Text-Handler
 /// <summary>
 ///     Replace word in selected sentence by line.
 /// </summary>
 /// <param name="index">Index of sentence.</param>
 /// <param name="length">Length of word to replace.</param>
 /// <param name="line">String with words and punctuation.</param>
 /// <param name="parseLine">Method to parse string and get new ISentence.</param>
 public void ReplaceWordInSentence(int index, int length, string line, Func<string, ISentence> parseLine)
 {
     Sentences[index] =
         new Sentence(Sentences[index].ReplaceWordByElements((x => x.Length == length), parseLine(line).Items));
 }
コード例 #3
0
ファイル: Text.cs プロジェクト: Demenovich-A-J/Text-Handler
 /// <summary>
 ///     Replace word in selected sentence by list of items type ISentenceItem.
 /// </summary>
 /// <param name="index">Index of sentence.</param>
 /// <param name="length">Length of word to replace.</param>
 /// <param name="elements">ISentenceItem elements that will be insert instead word into the sentence.</param>
 public void ReplaceWordInSentence(int index, int length, IList<ISentenceItem> elements)
 {
     Sentences[index] = new Sentence(Sentences[index].ReplaceWordByElements((x => x.Length == length), elements));
 }