/// <summary> /// 人名和前面的词词性匹配 /// </summary> /// <param name="nextStr"></param> /// <returns></returns> public bool MatchNameInTail(String preStr) { bool isReg; T_INNER_POS[] preList = m_POS.GetPos(preStr, out isReg); if (preList.Length == 0) { return(false); } foreach (T_INNER_POS pre in preList) { if (pre == T_INNER_POS.POS_UNK) { continue; } T_POSBin posBin = new T_POSBin(pre, T_INNER_POS.POS_D_N); if (m_PosBinTbl[posBin.HashCode] != null) { return(true); } posBin = new T_POSBin(pre, T_INNER_POS.POS_A_NR); if (m_PosBinTbl[posBin.HashCode] != null) { return(true); } } return(false); }
public void Traffic(List <String> words) { for (int i = 0; i < words.Count - 1; i++) { bool isReg; T_INNER_POS[] curPos = m_POS.GetPos((String)words[i], out isReg); T_INNER_POS[] nextPos = m_POS.GetPos((String)words[i + 1], out isReg); //ArrayList curList = m_POS.GetPosList(curPos); if (curPos.Length != 1) { continue; } T_INNER_POS pos1 = curPos[0]; if (pos1 == T_INNER_POS.POS_UNK) { continue; } //ArrayList nextList = m_POS.GetPosList(nextPos); if (nextPos.Length != 1) { continue; } T_INNER_POS pos2 = (T_INNER_POS)nextPos[0]; if (pos2 == T_INNER_POS.POS_UNK) { continue; } T_POSBin bin = new T_POSBin(pos1, pos2); Hit(bin); } }
public int ProcRule(List <String> preWords, int index, List <String> retWords) { String word = (String)preWords[index]; bool isReg; int pos = CPOS.GetPosFromInnerPosList(m_POS.GetPos(word, out isReg)); String num; if ((pos & (int)T_POS.POS_A_M) == (int)T_POS.POS_A_M) { num = word; int i = 0; for (i = index + 1; i < preWords.Count; i++) { String next = (String)preWords[i]; int nextPos = CPOS.GetPosFromInnerPosList(m_POS.GetPos(next, out isReg)); if ((nextPos & (int)T_POS.POS_A_M) == (int)T_POS.POS_A_M) { num += next; } else { break; } } if (num == word) { return(-1); } else { retWords.Add(num); return(i); } } else { return(-1); } }
/// <summary> /// 匹配姓位于单词尾部的情况 /// </summary> /// <param name="preWords"></param> /// <param name="index"></param> /// <param name="retWords"></param> /// <returns></returns> private int MatchFamilyNameInTail(List <String> preWords, int index, List <String> retWords) { if (retWords.Count < 1) { return(-1); } String curWord = (String)retWords[retWords.Count - 1]; if (curWord.Length < 2) { return(-1); } String nextWord = (String)preWords[index]; if (nextWord.Length > 2) { return(-1); } String familyName; //单姓 familyName = curWord[curWord.Length - 1].ToString(); if (m_FamilyNameTbl[familyName] == null) { familyName = curWord.Substring(curWord.Length - 2, 2); if (m_FamilyNameTbl[familyName] == null) { return(-1); } } String remain = curWord.Substring(0, curWord.Length - familyName.Length); if (retWords.Count > 0) { //重新组合前面的词,并判断词性匹配 String newWord = null; bool isReg; if (retWords.Count > 1) { newWord = retWords[retWords.Count - 2] + remain; m_Pos.GetPos(newWord, out isReg); if (!isReg) { newWord = null; } else { if (!m_PosBinRule.MatchNameInTail(newWord)) { newWord = null; } } if (newWord != null) { retWords.RemoveAt(retWords.Count - 1); retWords.RemoveAt(retWords.Count - 1); } } if (newWord == null) { newWord = remain; m_Pos.GetPos(newWord, out isReg); if (!isReg) { if (retWords.Count > 1) { newWord = retWords[retWords.Count - 2] + remain; retWords.RemoveAt(retWords.Count - 1); } } else { if (!m_PosBinRule.MatchNameInTail(newWord)) { newWord = null; } } if (newWord != null) { retWords.RemoveAt(retWords.Count - 1); } } if (newWord != null) { retWords.Add(newWord); } else { return(-1); } } String name = familyName + nextWord; if (name.Length - familyName.Length == 1) { //单字名 还要尝试是否是双字名 if (index < preWords.Count - 1) { String nnext = name + (String)preWords[index + 1]; nnext = nnext.Substring(familyName.Length, nnext.Length - familyName.Length); if (nnext.Length <= 2) { if (!m_PosBinRule.MatchNameInHead(nnext)) { name = name + (String)preWords[index + 1]; retWords.Add(name); return(index + 2); } } } } retWords.Add(name); return(index + 1); }