public Sentence CreateSentence(BookId bookId, string validatedSentence, int indexInBook) { validatedSentence = string.Join(" ", _textProcessor.GetWordsEnumerable(validatedSentence)); var sentenceType = SentenceType.Normal; var sentenceId = SentenceId.New(); var words = _textProcessor.GetWordsEnumerable(validatedSentence).ToArray(); var wordsList = new List <Word>(words.Length); var wordsInSentence = words .GroupBy(word => word) .Select(group => new { Word = group.Key, Count = group.Count() }).ToDictionary(x => x.Word); foreach (var word in words) { if (word.All(character => TextConstants.PunctuationCharacters.Contains(character)) && word.Length > 1) { sentenceType = SentenceType.Other; } if (word.EndsWith(".?", StringComparison.Ordinal) || word.EndsWith(".!", StringComparison.Ordinal)) { sentenceType = SentenceType.Other; } } var rawWordsInSentence = words .Select(word => _textProcessor.NormalizeWord(word)) .GroupBy(word => word) .Select(group => new { Word = group.Key, Count = group.Count() }).ToDictionary(x => x.Word); var index = 0; foreach (var word in words) { var keyPairs = CreateKeyPairs(validatedSentence, word); var rawWord = _textProcessor.NormalizeWord(word); wordsList.Add(new Word( sentenceId, index, word, rawWord, wordsInSentence[word].Count, rawWord == string.Empty ? 0 : rawWordsInSentence[rawWord].Count, keyPairs)); index++; } return(new Sentence(bookId, sentenceId, sentenceType, indexInBook, validatedSentence, wordsList)); }
public ValueTask <SentenceId> NextIdAsync() { return(new(SentenceId.New())); }
public void SentenceId_New_ShouldCreateNewGuid() { Assert.True(Guid.TryParse(SentenceId.New(), out var id)); Assert.NotEqual(Guid.Empty, id); }