使用Word进行分词及词性标注

1、下载Jar或源码
https://github.com/ysc/word/

2、写一些代码

public static void tag(String sentence) throws Exception {
        List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.BidirectionalMaximumMatching);
        PartOfSpeechTagging.process(words);
        System.out.println(words);
    	/*
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.BidirectionalMaximumMinimumMatching);
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.BidirectionalMinimumMatching);
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.FullSegmentation);
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.MaximumMatching);
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.MaxNgramScore);
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.MinimalWordCount);
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.MinimumMatching);
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.PureEnglish);
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.ReverseMaximumMatching);
    	List<Word> words = WordSegmenter.segWithStopWords(sentence, SegmentationAlgorithm.ReverseMinimumMatching);
    	*/
    }

4、输入
zh.txt

别让别人告诉你你成不了才,即使是我也不行。
如果你有梦想的话,就要去捍卫它。
那些一事无成的人想告诉你你也成不了大器。
如果你有理想的话,就要去努力实现。
就这样。

5、输出
zhout.txt

[别让/i, 别人/r, 告诉/v, 你/r, 你/r, 成不了/l, 才/d, 即使/c, 是/v, 我/r, 也/d, 不行/v, 如果/c, 你/r, 有/v, 梦想/n, 的话/u, 就要/d, 去/v, 捍卫/v, 它/r, 那些/r, 一事无成/l, 的/uj, 人/n, 想/v, 告诉/v, 你/r, 你/r, 也/d, 成不了/l, 大器/n, 如果/c, 你/r, 有理想/i, 的话/u, 就要/d, 去/v, 努力实现/nr, 就这样/i]

Leave a Reply

Your email address will not be published. Required fields are marked *

*