-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
55 lines (46 loc) · 1.64 KB
/
Program.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
namespace textAnalyzer
{
class Program
{
const string dataPath = "..\\data";
const string resultPath = "..\\data\\result\\result";
static void Main(string[] args)
{
DataAnalyzer da = new DataAnalyzer();
foreach (string fileName in Directory.GetFiles(dataPath))
{
FileAnalyzer fa = new FileAnalyzer();
fa.ReadFile(fileName);
fa.Analyze();
da.AddResult(fa);
}
da.ComputeGlobalStats();
StatsPresenter statsPresenter = new StatsPresenter();
statsPresenter.chars = da.chars.Values.OrderByDescending(x => x.Count);
statsPresenter.bigrams = da.bigrams.Values.OrderByDescending(x => x.Count);
statsPresenter.trigrams = da.trigrams.Values.OrderByDescending(x => x.Count);
using (StreamWriter w = new StreamWriter(resultPath + ".json"))
{
w.Write(JsonConvert.SerializeObject(statsPresenter));
}
ToCsv(statsPresenter.chars,"chars");
ToCsv(statsPresenter.bigrams,"bigrams");
ToCsv(statsPresenter.trigrams,"trigrams");
}
static void ToCsv(IEnumerable<Stats> list, string name)
{
using (StreamWriter w = new StreamWriter($"{resultPath}_{name}.csv"))
{
foreach (Stats s in list)
{
w.WriteLine($"\"{s.Value}\";{s.Percentage}");
}
}
}
}
}