java分析公司名称:AI智能工具助力提取地名、品牌名、行业名
一、java智能提取地名
public void getPlace4() throws Exception{String r1 = "武汉";String fileName2 = "D:\\Personal\\Desktop\\txt\\pca2.txt";String f1 = fileUtil.readFile(fileName2);String f2[] = f1.split("\r\n");String res3 = "";for (String s3: f2) {if (s3.contains(r1)) {System.out.println(s3.replaceAll(",",""));break;}}}public void getPlace3() throws Exception{String fileName1 = "D:\\Personal\\Desktop\\txt\\pca.txt";String fileName2 = "D:\\Personal\\Desktop\\txt\\pca2.txt";String f1 = fileUtil.readFile(fileName1);String f2[] = f1.split("\r\n");String res3 = "";for (String s3: f2) {if (!s3.equals("")) {String s5[] = s3.split(",");if(s5.length == 6){res3+=s5[1]+","+s5[2]+","+s5[3]+"\r\n";}}}fileUtil.writeTxtFile(fileName2, res3);}public void getPlace2(){String res = "武汉海明智业电子商务有限公司";String fileName1 = "D:\\Personal\\Desktop\\txt\\place1.txt";String f1 = fileUtil.readFile(fileName1);String f2[] = f1.split("\r\n");for (String s3: f2) {if (!s3.equals("")) {if (res.contains(s3)) {System.out.println(s3);break;}}}}public void getPlace1(){String res = "武汉海明智业电子商务有限公司";String[] testCase = new String[]{res};List<String> list = new ArrayList<>();Segment segment = HanLP.newSegment().enablePlaceRecognize(true);for (String sentence : testCase) {List<Term> termList = segment.seg(sentence);for (Term term : termList) {if(term.nature.toString().equals("ns")){list.add(term.word);}}}for (String str: list){System.out.println(str);}}
二、java智能提取品牌名
String res = "武汉海明智业电子商务有限公司";String[] testCase = new String[]{res};Segment segment = HanLP.newSegment().enablePlaceRecognize(true);String res2 = "";for (String sentence : testCase) {List<Term> termList = segment.seg(sentence);
for (Term term : termList) {if(!term.nature.toString().equals("ns") ){if(!term.nature.toString().equals("n") && !term.word.toString().equals("分")){res2+=term.word;}}}}System.out.println(res2);
三、java智能提取行业名
public static void main(String[] args) throws Exception {String sentence = "常州途畅互联网科技有限公司合肥分公司";Segment segment = HanLP.newSegment();List<Term> termList = segment.seg(sentence);String fileName1 = "D:\\Personal\\Desktop\\txt\\trade.txt";String f1 = fileUtil.readFile(fileName1);String f2[] = f1.split("\r\n");String res3 = "";for (Term term : termList) {for (String s3: f2) {String res = term.word;if (!s3.equals("")) {if (res.contains(s3)) {res3 += s3;}}}}System.out.println(res3);}public void get1(){String res = "昆明享亚教育信息咨询有限公司";String fileName1 = "D:\\Personal\\Desktop\\txt\\trade.txt";String f1 = fileUtil.readFile(fileName1);String f2[] = f1.split("\r\n");String res3 = "";for (String s3: f2) {if (!s3.equals("")) {if (res.contains(s3)) {res3+=s3;}}}System.out.println(res3);}