在作文本分析,尤其是分詞的時候,我們需要把不需要的標點符號去除,防止在詞轉向量的時候,把中文符號添加進去。
"[\\pP+~$`^=|<>~`$^+=|<>¥×]"
"[\\p{P}+~$`^=|<>~`$^+=|<>¥×]"
我使用的是ansj分詞器,其5.x版本有提供Recognition接口,用於在分詞的時候剔除不需要的,比如剔除停用詞、標點符號,根據詞性剔除一批詞,也支持正則表達式,很強大。
我只寫了demo:
JSONObject jsonObject = JSONObject.parseObject(ss);
String content = jsonObject.getString("content");
FilterRecognition filterRecognition = new FilterRecognition();
filterRecognition.insertStopNatures("m","w");
filterRecognition.insertStopRegex("[\\pP+~$`^=|<>~`$^+=|<>¥×]");
filterRecognition.insertStopRegex("•");
Result parse = NlpAnalysis.parse(content.replaceAll("\\s+","")).recognition(filterRecognition);
Set<String> str = new HashSet<String>();