if (sns != null && coreDict != null && unknownDict != null && context != null) {
int i = 0;
String curWord = null;
for (; i < sns.size(); i++) {
SegNode sn = sns.get(i);
sn.setAllPos(null);
curWord = sn.getSrcWord();
int gbkID = sn.getGbkID();// dictLib.getGBKID(curWord);
// if (tagType == Utility.TAG_TYPE.TT_NORMAL ||
// !unknownDict.isExist(sn.getWord(), 44)) {
//
// }
if (tagType != Utility.TAG_TYPE.TT_NORMAL) {
// ��ȫ���ַ����ɰ�ǵ��ַ�
if (tagType == Utility.TAG_TYPE.TT_TRANS_PERSON && i > 0) {
String prevWord = sns.get(i - 1).getSrcWord();
if (Utility.charType(prevWord) == Utility.CT_CHINESE) {
if (".".equals(curWord))
curWord = "��";
else if ("-".equals(curWord))
curWord = "��";
}
}
if (sn.getPos() < 0) {
AdjoiningPos pos = new AdjoiningPos( 0 , 0);
sn.addPos(pos);
} else {
// ��unknownDict�ʵ���л�ȡ��ǰ�����д���
SegAtom sa = unknownDict.getSegAtom(curWord, gbkID);
for (int j = 0; sa != null && j < sa.getPosCount(); j++) {
Pos pos = sa.getPos(j);
double value = -Math.log((1 + pos.getFreq()));
value += Math.log((context.getFreq(pos.getTag()) + sa.getPosCount() + 1));
AdjoiningPos apos = new AdjoiningPos(pos , value);
sn.addPos(apos);
}
if (Utility.SENTENCE_BEGIN.equals(curWord))
sn.addPos(new AdjoiningPos( 100 , 0));
else if (Utility.SENTENCE_END.equals(curWord))
sn.addPos(new AdjoiningPos( 101 , 0));
else {
int freq = 0;
sa = coreDict.getSegAtom(curWord, gbkID);
if (sa != null) {
double value = -Math.log((double) (1 + freq));
value += Math.log((double) (context.getFreq(0) + sa.getPosCount()));
sn.addPos(new AdjoiningPos( 0 , value));
}
}
}
} else {
if (sn.getPos() > 0) {
int tag = sn.getPos();
double value = -Math.log(1 + sn.getFreq());
value += Math.log(1 + context.getFreq(tag));
if (value < 0)
value = 0;
sn.addPos(new AdjoiningPos( tag, value));
} else {
if (sn.getPos() < 0) {
sn.setPos(-sn.getPos());
sn.addPos(new AdjoiningPos( -sn.getPos(), sn.getFreq()));
}
SegAtom sa = coreDict.getSegAtom(curWord, gbkID);
if (sa != null) {
for (int j = 0; j < sa.getPosCount(); j++) {
Pos pos = sa.getPos(j);
double value = -Math.log(1 + pos.getFreq());
value += Math.log(context.getFreq(pos.getTag()) + sa.getPosCount());
sn.addPos(new AdjoiningPos(pos , value));
}
}
}
}
if (sn.getAllPos() == null)
guessPos(tagType, sn);
// ���һ���ʽڵ��Ӧ��allPosΪnull����˵�����������ɴ�
// ���Ĵ�������һ���ʵĴ���,���ǽ�����ʶ��ĩ##ĩ������
if (i - 1 >= 0 && sns.get(i - 1).getPosSize() == -1) {
if (sn.getPosSize() > 0) {
Pos pos = sn.getAllPos().get(0).getPos();
int ipos = pos.getTag() == POSTag.SEN_END ? POSTag.UNKNOWN : pos.getTag();
AdjoiningPos apos = new AdjoiningPos( ipos , 0);
sns.get(i - 1).addPos(apos);
}
}
}
// ���һ��������
SegNode last = sns.get(i - 1);
if (last != null) {
SegNode sn = new SegNode();
int tag = 0;
if (tagType != Utility.TAG_TYPE.TT_NORMAL)
tag = 101;
else
tag = 1;
AdjoiningPos pos = new AdjoiningPos( tag, 0);
sn.addPos(pos);
sns.add(sn);
}
}
}