Guys such a problem: Assignment with online courses ulearn.
"This time we will process the text. Our final goal is the text continuation algorithm, which, according to several words, guesses the most likely following based on the knowledge gained from analyzing a large text array. The whole task is divided into 3 stages: text preparation, analysis of the frequency of digrams and the actual continuation of the text, based on information about the frequency. In this task, you need to break the text into sentences, and sentences into words. Perform the task in the SentencesParserTask class. "
Actually the file itself with the task below. I duplicate the code here.
I tried to do the task using LINQ, left comments on what each method does.
Error gives this:
Error on: ab, c 0th element (subitems delimited by pipe symbol) should be [b|c], but was [b,|c] Thanks in advance for your help!)
using System.Collections.Generic; using System.Linq; using System.Text; namespace TextAnalysis { static class SentencesParserTask { public static readonly string[] StopWords = { "the", "and", "to", "a", "of", "in", "on", "at", "that", "as", "but", "with", "out", "for", "up", "one", "from", "into" }; /* Π Π°Π·Π±Π΅ΠΉΡΠ΅ ΡΠ°ΠΉΠ» Ρ ΡΠ΅ΠΊΡΡΠΎΠΌ Π½Π° ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΈ ΡΠ»ΠΎΠ²Π°. Π‘ΡΠΈΡΠ°ΠΉΡΠ΅, ΡΡΠΎ ΡΠ»ΠΎΠ²Π° ΠΌΠΎΠ³ΡΡ ΡΠΎΡΡΠΎΡΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΠΈΠ· Π±ΡΠΊΠ² (ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠΉΡΠ΅ ΠΌΠ΅ΡΠΎΠ΄ char.IsLetter) ΠΈΠ»ΠΈ ΡΠΈΠΌΠ²ΠΎΠ»Π° Π°ΠΏΠΎΡΡΡΠΎΡΠ° ', Π° ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΡ ΡΠ°Π·Π΄Π΅Π»Π΅Π½Ρ ΠΎΠ΄Π½ΠΈΠΌ ΠΈΠ· ΡΠ»Π΅Π΄ΡΡΡΠΈΡ
ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠ² .!?;:() Π£Π΄Π°Π»ΠΈΡΠ΅ ΠΈΠ· ΡΠ°ΠΉΠ»Π° ΡΠ»ΠΎΠ²Π°, ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΠΈΠ΅ΡΡ Π² ΠΌΠ°ΡΡΠΈΠ²Π΅ StopWords (ΡΠ°ΡΡΡΠ΅ Π½Π΅Π·Π½Π°ΡΠ°ΡΠΈΠ΅ ΡΠ»ΠΎΠ²Π° ΠΏΡΠΈ Π°Π½Π°Π»ΠΈΠ·Π΅ ΡΠ΅ΠΊΡΡΠΎΠ² Π½Π°Π·ΡΠ²Π°ΡΡ ΡΡΠΎΠΏ-ΡΠ»ΠΎΠ²Π°ΠΌΠΈ) ΠΠ΅ΡΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°ΡΡ ΡΠΏΠΈΡΠΎΠΊ ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠΉ, Π³Π΄Π΅ ΠΊΠ°ΠΆΠ΄ΠΎΠ΅ ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅ β ΡΡΠΎ ΡΠΏΠΈΡΠΎΠΊ ΠΎΡΡΠ°Π²ΡΠΈΡ
ΡΡ ΡΠ»ΠΎΠ² Π² Π½ΠΈΠΆΠ½Π΅ΠΌ ΡΠ΅Π³ΠΈΡΡΡΠ΅. */ //StopWords.Select(b=>b) public static List<List<string>> ParseSentences(string text) { var sb = new StringBuilder(text); var lstStr = sb.ToString() .Split('.', '!', '?', ';', ':', '(', ')')//ΡΠ°Π·Π΄Π΅Π»ΡΠ΅ΠΌ ΡΡΡΠΎΠΊΡ ΡΠΈΠΌΠ²ΠΎΠ»Π°ΠΌΠΈ ΡΠ΅ΠΌ ΡΠ°ΠΌΡΠΌ ΠΏΡΠ΅ΠΎΠ±ΡΠ°Π·ΡΠ΅ΡΡΡ Π΄ΠΎ ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠΉ .Select(a => a.Split(' ').Except(StopWords)//ΡΠ°Π·Π±ΠΈΠ²Π°Π΅ΠΌ ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΏΠΎ ΠΏΡΠΎΠ±Π΅Π»Ρ ΠΈ ΡΠ΄Π°Π»ΡΠ΅ΠΌ ΠΈΠ· ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²ΠΎ StopWords //ΠΈ ΠΏΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ ΡΠ²Π»ΡΠ΅ΡΡΡ Π»ΠΈ ΡΠΈΠΌΠ²ΠΎΠ» Π±ΡΠΊΠ²ΠΎΠΉ, Π² Π½ΠΈΠΆΠ½Π΅ΠΌ Π»ΠΈ ΡΠ΅Π³ΠΈΡΡΡΠ΅ Π±ΡΠΊΠ²Π° ΠΈΠ»ΠΈ ΡΠΈΠΌΠ²ΠΎΠ» Π°ΠΏΠΎΡΡΡΠΎΡΠ° .Where(b => b.Any(c=>char.IsLetter(c) && char.IsLower(c) || c=='`')) .Select(b => b).ToList()).ToList(); return new List<List<string>>(lstStr); } } }
LINQ? - Bulson