中文分词

1. 使用Stanford Word Segmenter进行中文分词,下载地址http://nlp.stanford.edu/software/segmenter.shtml

2. 版本Version1.6.7

3. 将seg.jar放入ClassPath下,data目录放在src目录下

4. 编写测试程序,根据Demo

import java.util.Properties;

import edu.stanford.nlp.ie.crf.CRFClassifier;

public class SegDemo {
	public static String doSegment(String data, CRFClassifier c) {
		String[] strs = (String[]) c.segmentString(data).toArray();

		StringBuffer buf = new StringBuffer();

		for (String s : strs) {
			buf.append(s + " ");
		}

		return buf.toString();
	}

	public static void main(String[] args) throws Exception {
		Properties props = new Properties();
		props.setProperty("sighanCorporaDict", "data");
		props.setProperty("serDictionary", "data/dict-chris6.ser.gz");
		props.setProperty("inputEncoding", "UTF-8");
		props.setProperty("sighanPostProcessing", "true");
		CRFClassifier classifier = new CRFClassifier(props);
		classifier.loadClassifierNoExceptions("data/ctb.gz", props);
		classifier.flags.setProperties(props);

		String sentence = "他和我在学校里常打桌球。";
		String ret = doSegment(sentence, classifier);
		System.out.println(ret);

	}

}

5. 加入VM运行参数 

-mx1g

6. 运行结果

serDictionary=data/dict-chris6.ser.gz
sighanCorporaDict=data
inputEncoding=UTF-8
sighanPostProcessing=true
Loading classifier from data/ctb.gz ... Loading Chinese dictionaries from 1 files:
  data/dict-chris6.ser.gz

loading dictionaries from data/dict-chris6.ser.gz...Done. Unique words in ChineseDictionary is: 423200
done [31.8 sec].
serDictionary=data/dict-chris6.ser.gz
sighanCorporaDict=data
inputEncoding=UTF-8
sighanPostProcessing=true
INFO: TagAffixDetector: useChPos=false | useCTBChar2=true | usePKChar2=false
INFO: TagAffixDetector: building TagAffixDetector from data/dict/character_list and data/dict/in.ctb
Loading character dictionary file from data/dict/character_list
Loading affix dictionary from data/dict/in.ctb
他 和 我 在 学校 里 常 打 桌球 。 

7. 其它要注意的细节http://www.cnblogs.com/XP007/archive/2011/10/27/2227158.html

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值