commit
f0c01cb49d
@ -0,0 +1,35 @@
|
||||
package com.example.cmknowledgegraph;
|
||||
|
||||
import com.hankcs.hanlp.HanLP;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class HanlpSearch {
|
||||
public static void main(String[] args) {
|
||||
Scanner content = new Scanner(System.in);
|
||||
String key = content.nextLine();
|
||||
if(key.indexOf("吃")==-1) {
|
||||
List result = HanLP.segment(key);
|
||||
System.out.println(result);
|
||||
for(int i=0;i<result.size();i++) {
|
||||
String pattern = "(.*?)/[n|a]$";
|
||||
Pattern template = Pattern.compile(pattern);
|
||||
Matcher mc = template.matcher(String.valueOf(result.get(i)));
|
||||
if (mc.find()) {
|
||||
String[] splitstr = mc.group().split("\\/");
|
||||
System.out.println(splitstr[0]);
|
||||
} else {
|
||||
result = HanLP.extractKeyword(key, 1);
|
||||
System.out.println(result.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
List<String> result = HanLP.extractKeyword(key,2);
|
||||
System.out.println(result.get(0));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue