-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
61 lines (56 loc) · 1.59 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
56
57
58
59
60
61
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Keywords
{
class Program
{
static void Main(string[] args)
{
//1、获取文档输入
string[] docs = getInputDocs("test5.txt");
if (docs.Length < 1)
{
Console.WriteLine("没有文档输入");
Console.Read();
return;
}
//2、初始化TFIDF测量器,用来生产每个文档的TFIDF权重
string txt = "";
for (int i = 0; i < docs.Length; i++)
{
txt += docs[i];
}
Tokeniser tk = new Tokeniser();
tk.Partition(txt);
tk.OutputKeywords(10);
Console.Read();
}
/// <summary>
/// 获取文档输入
/// </summary>
/// <returns></returns>
private static string[] getInputDocs(string file)
{
List<string> ret = new List<string>();
try
{
using (StreamReader sr = new StreamReader(file, Encoding.Default))
{
string temp;
while ((temp = sr.ReadLine()) != null)
{
ret.Add(temp);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return ret.ToArray();
}
}
}