-
Notifications
You must be signed in to change notification settings - Fork 14
/
ZhSegment.cs
48 lines (43 loc) · 1.39 KB
/
ZhSegment.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
using JiebaNet.Segmenter;
using System;
using System.Collections.Generic;
namespace OpenCCNET
{
public static partial class ZhConverter
{
public static class ZhSegment
{
/// <summary>
/// 语句分词
/// </summary>
public static Func<string, IEnumerable<string>> Segment = SegmentByJieba;
/// <summary>
/// jieba.NET分词
/// </summary>
public static JiebaSegmenter Jieba = new JiebaSegmenter();
public static void Initialize(string jiebaResourceDirectory = "JiebaResource")
{
ConfigManager.ConfigFileBaseDir = jiebaResourceDirectory;
// 通过调用一次jieba分词来提前加载所需资源
Jieba.Cut(string.Empty);
}
/// <summary>
/// 利用jieba.NET分词
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
private static IEnumerable<string> SegmentByJieba(string text)
{
return Jieba.Cut(text);
}
/// <summary>
/// 重置分词所用方法
/// </summary>
public static void ResetSegment()
{
Segment = SegmentByJieba;
Jieba = new JiebaSegmenter();
}
}
}
}