Got a quite huge problem. My task is to split the input text into sentences,then to split sentences into words. Here comes the code :
using System.Collections.Generic; using System.Linq;
namespace TextAnalysis { static class SentencesParserTask { public static List> ParseSentences(string text) { var sentencesList = new List>();
var splittedText = text.Split('.', '!', '?', ';', ':', '(', ')');
List<string>[] mas = new List<string>[splittedText.Length];
for (int i = 0; i < splittedText.Length; i++)
{
mas[i] = new List<string>();
}
for (int j = 0; j < splittedText.Length; j++)
{
mas[j]= GetWordsOutOfTheSentence(splittedText);
bool isEmpty = !(mas[j]).Any();
if(!isEmpty)
sentencesList.Add(mas[j]);
}
return sentencesList;
}
private static List<string> GetWordsOutOfTheSentence(string[] splittedText)
{
var wordList = new List<string>();
foreach (var sentence in splittedText)
{
var wordsArray = sentence.Split('^', '#', '$', '-', '+', '1', '=', ' ', '\t', '\n', '\r',',');
for (int i = 0; i < wordsArray.Length; i++)
{
if (wordsArray[i] != string.Empty)
{
var fineWord = wordsArray[i];
wordList.Add(fineWord.ToLower());
}
}
}
return wordList;
}
}
}
The main problem is on test 1) Failed : TextAnalysis.SentencesParser_Tests.CorrectlyParse_SentenceDelimiters Input text: [a.b!c?d:e;f(g)h;i] Sentence #0 is wrong Expected is with 9 elements Values differ at index [1] Extra: < "b", "c", "d"... > My code just continue adding new words in list and then add that lists in main list.What should i do?
Aucun commentaire:
Enregistrer un commentaire