Lac是百度开源的一款中文词法分析工具,可以完成中文分词、词性标注等任务。本库还支持自定义词库。
包名 💼 | 版本号 📌 | 描述 📚 |
---|---|---|
Sdcb.PaddleNLP.Lac | 分词主库 | |
Sdcb.PaddleNLP.Lac.Model | 模型与资源 |
- Sdcb.PaddleNLP.Lac
- Sdcb.PaddleInference
- Sdcb.PaddleInference.runtime.win64.mkl
string input = "我是中国人,我爱我的祖国。";
using ChineseSegmenter segmenter = new();
string[] result = segmenter.Segment(input);
Console.WriteLine(string.Join(",", result)); // 我,是,中国,人,,,我,爱,我的祖国,。
string input = "我爱北京天安门";
using ChineseSegmenter segmenter = new();
WordAndTag[] result = segmenter.Tagging(input);
string labels = string.Join(",", result.Select(x => x.Label));
string words = string.Join(",", result.Select(x => x.Word));
string tags = string.Join(",", result.Select(x => x.Tag));
Console.WriteLine(words); // 我,爱,北京,天安门
Console.WriteLine(labels); // r,v,LOC,LOC
Console.WriteLine(tags); // Pronoun,Verb,LocationName,LocationName
string input = "我爱北京天安门";
using ChineseSegmenter segmenter = new(new ()
{
CustomDictionary = new()
{
{ "北京天安门", WordTag.LocationName },
}
});
WordAndTag[] result = segmenter.Tagging(input);
string labels = string.Join(",", result.Select(x => x.Label));
string words = string.Join(",", result.Select(x => x.Word));
string tags = string.Join(",", result.Select(x => x.Tag));
Console.WriteLine(words); // 我,爱,北京天安门
Console.WriteLine(labels); // r,v,LOC
Console.WriteLine(tags); // Pronoun,Verb,LocationName