Android中使用Hanlp对文本进行分词以及提取关键词
一、引入依赖
dependencies {
implementation 'com.hankcs:hanlp:portable-1.7.8'
}
二、使用方法
1.使用方法
String text = "请帮我找出和nujNplaib有关的衣服";
List<Term> termList = HanLP.segment(text);
for (Term keyword : termList) {
Log.d("fxHou分词","---------------------------------------------------------");
Log.d("fxHou词语",keyword.word);
Log.d("fxHou词性",keyword.nature.toString());
}
List<String> keywordList = HanLP.extractKeyword(text, 5);
for (String keyword : keywordList) {
Log.d("fxHou关键词","---------------------------------------------------------");
Log.d("fxHou关键词",keyword);
}
2.数据结果
2022-09-09 21:04:13.887 20673-20673 fxHou分词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.887 20673-20673 fxHou词语 com.example.hanlptest D 请
2022-09-09 21:04:13.887 20673-20673 fxHou词性 com.example.hanlptest D v
2022-09-09 21:04:13.888 20673-20673 fxHou分词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.888 20673-20673 fxHou词语 com.example.hanlptest D 帮
2022-09-09 21:04:13.888 20673-20673 fxHou词性 com.example.hanlptest D v
2022-09-09 21:04:13.888 20673-20673 fxHou分词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.888 20673-20673 fxHou词语 com.example.hanlptest D 我
2022-09-09 21:04:13.888 20673-20673 fxHou词性 com.example.hanlptest D r
2022-09-09 21:04:13.888 20673-20673 fxHou分词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.888 20673-20673 fxHou词语 com.example.hanlptest D 找出
2022-09-09 21:04:13.888 20673-20673 fxHou词性 com.example.hanlptest D v
2022-09-09 21:04:13.888 20673-20673 fxHou分词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.888 20673-20673 fxHou词语 com.example.hanlptest D 和
2022-09-09 21:04:13.888 20673-20673 fxHou词性 com.example.hanlptest D c
2022-09-09 21:04:13.888 20673-20673 fxHou分词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.888 20673-20673 fxHou词语 com.example.hanlptest D nujNplaib
2022-09-09 21:04:13.888 20673-20673 fxHou词性 com.example.hanlptest D nx
2022-09-09 21:04:13.888 20673-20673 fxHou分词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.888 20673-20673 fxHou词语 com.example.hanlptest D 有关
2022-09-09 21:04:13.888 20673-20673 fxHou词性 com.example.hanlptest D vn
2022-09-09 21:04:13.888 20673-20673 fxHou分词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.888 20673-20673 fxHou词语 com.example.hanlptest D 的
2022-09-09 21:04:13.888 20673-20673 fxHou词性 com.example.hanlptest D uj
2022-09-09 21:04:13.888 20673-20673 fxHou分词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.888 20673-20673 fxHou词语 com.example.hanlptest D 衣服
2022-09-09 21:04:13.888 20673-20673 fxHou词性 com.example.hanlptest D n
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D 请
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D 衣服
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D 帮
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D nujNplaib
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D ---------------------------------------------------------
2022-09-09 21:04:13.904 20673-20673 fxHou关键词 com.example.hanlptest D 找出