java 标注处理_java 处理人民日报98年语料库处理复合标注词

主要处理nz i l

public static void main(String[] args) {         // TODO Auto-generated method stub         StringBuffer sb = new StringBuffer();         String tempstr = null;         try {             FileWriter fp = new FileWriter("E:/text/destext.txt");             String path = "E:/text/srctext.txt";             File file = new File(path);             if (!file.exists())                 throw new FileNotFoundException();                          Pattern pattern1 = Pattern.compile("\\[.*?]n");             Pattern pattern0 = Pattern.compile("\\[.*?]i");             Pattern pattern2 = Pattern.compile("\\[.*?]l");                                                                    Pattern pattern3 = Pattern.compile("\\[.*?]nz");             FileInputStream fis = new FileInputStream(file);             BufferedReader br = new BufferedReader(new InputStreamReader(fis));             while ((tempstr = br.readLine()) != null) {                 String line = "";                 String line1 = "";                 // sb.append(tempstr);                 Matcher matcher = pattern1.matcher(tempstr);                 while (matcher.find()) {                                          String src = "";                     String tmp = "";                     for (int j = 0; j <= matcher.groupCount(); j++) {                         // System.out.print( matcher.group(j) +" ");                         src = matcher.group(j);                         tmp = matcher.group(j);                         tmp = tmp.replaceAll("/\\w+", "");                         tmp = tmp.replaceAll(" ", "");                         tmp = tmp.replaceAll("\\[", "");                         tmp = tmp.replaceAll("\\]", "/");                         System.out.println(tmp);                     }                     tempstr = tempstr.replace(src, tmp);                     System.out.println();                 }                 Matcher matcher1 = pattern0.matcher(tempstr);                 while (matcher1.find()) {                                          String src = "";                     String tmp = "";                     for (int j = 0; j <= matcher1.groupCount(); j++) {                                                  src = matcher1.group(j);                         tmp = matcher1.group(j);                         tmp = tmp.replaceAll("/\\w+", "");                         tmp = tmp.replaceAll(" ", "");                         tmp = tmp.replaceAll("\\[", "");                         tmp = tmp.replaceAll("\\]", "/");                         System.out.println(tmp);                     }                     tempstr =tempstr.replace(src, tmp);                         System.out.println();                 }                  Matcher matcher2 = pattern2.matcher(tempstr);                                  while (matcher2.find()) {                     String src="";                     String tmp ="";                     for (int j = 0; j <= matcher2.groupCount(); j++)                     {                     //    System.out.print( matcher.group(j) +" ");                         src = matcher2.group(j);                         tmp=  matcher2.group(j);                         tmp = tmp.replaceAll("/\\w+", "");                         tmp = tmp.replaceAll(" ", "");                         tmp = tmp.replaceAll("\\[", "");                         tmp = tmp.replaceAll("\\]", "/");                         System.out.println(tmp);                     }                     tempstr =tempstr.replace(src, tmp);                         System.out.println();                 }                                   fp.write(tempstr + "\n");                              }             fp.close();         } catch (IOException ex) {             System.out.println(ex.getStackTrace());         }     }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值