中文分词之基本分词

       中文分词之评价基本分词

一、      大纲步骤:

  评价对象的抽取分为:基本分词,候选词的获取,特殊词的过滤,完整性算法,稳定性算法

二、      基本分词

先利用IC对文章进行基本的分词,分词的依据是IC本身自带的词典。该词典只有普通分词,例如/n ,/v, /q,/ns,/w等。

 

import java.io.BufferedReader;
importjava.io.BufferedWriter;
importjava.io.File;
import java.io.FileOutputStream;
importjava.io.OutputStream;
import java.io.OutputStreamWriter;
importjava.util.ArrayList;
 
importcom.myretrieve.config.ConstantString;
 
importICTCLAS.I3S.AC.ICTCLAS50;
 
public classIctclasUtils {
   
    /**
     * 根据字符串进行分词,返回分词的结果。
     * @param str
     * @return
     */
    public static StringictclasSpilt(String str){
        String result = null;
        try
        {
            ICTCLAS50 testICTCLAS50 = newICTCLAS50();
            String argu = ".";
            //初始化
            if(testICTCLAS50.ICTCLAS_Init(argu.getBytes("GB2312")) == false)
            {
                System.out.println("InitFail!");
                return result;
            }
 
 
            //设置词性标注集(0 计算所二级标注集,1 计算所一级标注集,2 北大二级标注集,3 北大一级标注集)
            testICTCLAS50.ICTCLAS_SetPOSmap(2);
            //导入用户词典前分词
            bytenativeBytes[] = testICTCLAS50.ICTCLAS_ParagraphProcess(str.getBytes("GB2312"), 0, 1);//分词处理
             result = newString(nativeBytes, 0, nativeBytes.length, "GB2312");
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    return result;
 
    }
   
    /**
     * 循环读出路径下所有的文件,然后分词,写入到输出路径中
     * @paraminputPath
     * @paramoutputPath
     * @throwsException
     */
    public static voidspiltWord2File(String inputPath,String outputPath) throwsException{
        if(StringUtil.isEmpty(inputPath)){
            throw newException("the inputPath is NULL");
           
        };
        File outputDir = newFile(outputPath);
        if(!outputDir.exists()){
            outputDir.mkdirs();
            }
        OutputStream out;
        BufferedWriter bw = null;
       
        ArrayList<String> fileLists = newStringUtil().getAllPath(inputPath);
        for(String p: fileLists ){
            String content = StringUtil.getContent(p);
           
            String result = ictclasSpilt(content);
            System.out.println(result);
            String name = StringUtil.getNameFromPath(p);
            String outputFile =outputPath+ConstantString.spilePath+name+ConstantString.postText;
            StringUtil.String2File(result,outputFile);
           
        }
    }
   
}

分词前:




分词后:




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值