-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSentence.cs
72 lines (54 loc) · 2.28 KB
/
Sentence.cs
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace WhatsAppGroupAnalysis
{
class Sentence
{
private static readonly Regex CleanEmoji = new Regex(@"\p{Cs}", RegexOptions.Compiled);
private static readonly char[] DelimitersOne = { ' ', '\r', '\n'};
private static readonly char[] DelimitersTwo = { ' ', ' ', '\r', '\n', ';', '.', ',', '-', '–', '_', '¯', '?', '!', '\t', '/', '\\', '(', ')', '{', '}', '[', ']', '@', '=', '*', '\'', '"', '+', '“', '”', '>', '<', '`', };
public DateTime Moment { get; set; }
public string Who { get; set; }
public string What { get; set; }
public bool IsOnlyImage { get; private set; }
public int EmojiCount { get; private set; }
public void Calculate(string langString)
{
if (What.Equals(langString, StringComparison.CurrentCultureIgnoreCase))
{
IsOnlyImage = true;
Lenght = 0;
WordsCount = 0;
return;
}
var clean = CleanEmoji.Replace(What, string.Empty);
EmojiCount += (What.Length - clean.Length) / 2;
Lenght = clean.Length;
var resultsFirst = clean.ToLowerInvariant().Split(DelimitersOne, StringSplitOptions.RemoveEmptyEntries);
var l = new List<string>();
foreach (var item in resultsFirst)
{
if(item.StartsWith("http://"))
{
continue;
}
if (item.StartsWith("https://"))
{
continue;
}
foreach (var w in item.Split(DelimitersTwo, StringSplitOptions.RemoveEmptyEntries))
{
l.Add(w);
}
}
Words = l.ToArray();
WordsCount = Words.Length;
MomentCategory = Moment.GetCategory();
}
public int Lenght { get; private set; }
public string[] Words { get; private set; } = Array.Empty<string>();
public int WordsCount { get; private set; }
public MomentCategory MomentCategory { get; private set; }
}
}