使用不同的分詞器科領(lǐng)摳像拍照軟件,最終的關(guān)鍵詞不同關(guān)鍵詞分詞器綠色版照片轉(zhuǎn)手繪軟件(SoftOrbits Sketch Drawer),所需的時(shí)間也不同
用中文分詞是個(gè)不錯(cuò)的選擇,但是對(duì)比時(shí)間關(guān)鍵詞分詞器綠色版devCad(CAD建模軟件),在我的電腦上分詞大約需要800+ms
標(biāo)記器工作流程:
輸入文字(你叫什么名字?)
→關(guān)鍵詞劃分(What's ; your ; name),不同的分詞器對(duì)不同的分詞方法不同
→刪除停用詞()
→形式恢復(fù)(什么 -> 什么)
→轉(zhuǎn)換為小寫(What -> what)
private long stime;
private long etime;
private Analyzer analyzer;
@Before
public void s(){
stime = System.currentTimeMillis();
}
@After
public void e(){
etime = System.currentTimeMillis();
System.out.println("使用" + analyzer.getClass().getName() + "分詞, 耗時(shí)" + (etime - stime) + "ms");
}
@Test
public void test() throws Exception {
//analyzer = new SimpleAnalyzer(Version.LUCENE_35);
//analyzer = new StandardAnalyzer(Version.LUCENE_35);
analyzer = new IKAnalyzer();
analyze(analyzer, "hTTp://www.baidu.com/s?wd=Lucene中文分詞");
}
private void analyze(Analyzer analyzer, String text) throws Exception {
TokenStream tokens = analyzer.reusableTokenStream("content", new StringReader(text));
OffsetAttribute offsetAttr = tokens.getAttribute(OffsetAttribute.class);
CharTermAttribute charTermAttr = tokens.getAttribute(CharTermAttribute.class);
while (tokens.incrementToken()) {
char[] charBuf = charTermAttr.buffer();
String term = new String(charBuf, 0, offsetAttr.endOffset() - offsetAttr.startOffset());
System.out.println(term + ", " + offsetAttr.startOffset() + ", " + offsetAttr.endOffset());
}
tokens.close();
// while (ts.incrementToken()) {//過時(shí)
// TermAttribute ta = ts.getAttribute(TermAttribute.class);
// System.out.println(ta.term());
// }
}