-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentencesParser.cs
More file actions
46 lines (41 loc) · 1.4 KB
/
SentencesParser.cs
File metadata and controls
46 lines (41 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Text;
namespace TextAnalysis
{
static class SentencesParser
{
public static List<string> AddWords(string snt)
{
var word = new StringBuilder();
var sentence = new List<string>();
for (var i = 0; i < snt.Length; i++)
{
if (Char.IsLetter(snt[i]) || snt[i] == '\'')
word.Append(snt[i]);
else if (word.ToString() != "")
{
sentence.Add(word.ToString().ToLower());
word = new StringBuilder();
}
}
if (word.ToString() != "")
sentence.Add(word.ToString().ToLower());
return sentence;
}
public static List<List<string>> ParseSentences(string text)
{
var sentencesList = new List<List<string>>();
char[] sentenceSeparators = {'.', '!', '?', ';', ':', '(', ')'};
var sentences = text.Split(sentenceSeparators);
foreach (var snt in sentences)
if (snt != "")
{
var sentence = AddWords(snt);
if(sentence.Count != 0)
sentencesList.Add(sentence);
}
return sentencesList;
}
}
}