?? atomseg.java
字號:
package org.ictclas4j.segment;
import java.util.ArrayList;
import org.ictclas4j.bean.Atom;
import org.ictclas4j.utility.GFString;
import org.ictclas4j.utility.Utility;
/**
* 原子分詞
* @author sinboy
* @since 2007.6.1
*/
public class AtomSeg {
private String str;
private ArrayList<Atom> atoms;
public AtomSeg(String src) {
this.str = src;
atoms = atomSplit();
}
/**
* <pre>
* 原子分詞,分成一個個的獨立字符,開始標志和結束標志做一個原子單位看等.
* 比如:始##始他說的確實在理末##末-->始##始 他 說 的 確 實 在 理 末##末
* </pre>
*
* @param str
* 源字符串
* @return
*/
private ArrayList<Atom> atomSplit() {
ArrayList<Atom> result = null;
if (str != null && str.length() > 0) {
String sAtom = "";
result = new ArrayList<Atom>();
String[] ss = GFString.atomSplit(str);
int index = str.indexOf(Utility.SENTENCE_BEGIN);
if (index == 0) {
Atom atom = new Atom();
atom.setWord(Utility.SENTENCE_BEGIN);
atom.setLen(Utility.SENTENCE_BEGIN.length());
atom.setPos(Utility.CT_SENTENCE_BEGIN);
result.add(atom);
index += Utility.SENTENCE_BEGIN.length();
}
if (index == -1)
index = 0;
for (int i = index; i < ss.length; i++) {
if (Utility.SENTENCE_END.equals(str.substring(i))) {
Atom atom = new Atom();
atom.setWord(Utility.SENTENCE_END);
atom.setLen(Utility.SENTENCE_END.length());
atom.setPos(Utility.CT_SENTENCE_END);
result.add(atom);
break;
}
String s = ss[i];
sAtom += s;
int curType = Utility.charType(s);
if (".".equals(s)
&& (i + 1 < ss.length && (Utility.charType(ss[i + 1]) == Utility.CT_NUM || GFString
.isNumeric(ss[i+1]))))
curType = Utility.CT_NUM;
// 如果是漢字、分隔符等
if (curType == Utility.CT_CHINESE || curType == Utility.CT_INDEX || curType == Utility.CT_DELIMITER
|| curType == Utility.CT_OTHER) {
Atom atom = new Atom();
atom.setWord(s);
atom.setLen(s.length());
atom.setPos(curType);
result.add(atom);
sAtom = "";
}
// 如果是數字、字母、單字節符號,則把相鄰的這些做為一個原子。比如:三星SHX-123型號的手機,則其中的SHX-123就是一個原子
else {
int nextType = 255;// 下一個字符的類型
if (i < ss.length - 1)
nextType = Utility.charType(ss[i + 1]);
if (nextType != curType || i == ss.length - 1) {
Atom atom = new Atom();
atom.setWord(sAtom);
atom.setLen(sAtom.length());
atom.setPos(curType);
result.add(atom);
sAtom = "";
}
}
}
}
return result;
}
public ArrayList<Atom> getAtoms() {
return atoms;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -