示例#1
0
        protected override bool LoadDictionary(Stream instr, Uyghur.YEZIQ yeziq)
        {
            if (m_RootNode != null)
            {
                m_RootNode = null;
            }

            using (StreamReader sr = new StreamReader(instr, System.Text.Encoding.UTF8))
            {
                String line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] lineParts = line.Split(null);
                    if (lineParts.Length >= 2)
                    {
                        string key = lineParts[0];
                        if (yeziq == Uyghur.YEZIQ.ULY)
                        {
                            key = Uyghur.UEY2ULY(key).ToLower();
                        }
                        else if (yeziq == Uyghur.YEZIQ.USY)
                        {
                            key = Uyghur.UEY2USY(key).ToLower();
                        }
                        Int64 count;
                        if (Int64.TryParse(lineParts[1], out count))
                        {
                            Add(key, count);
                        }
                    }
                }
            }
            return(true);
        }
示例#2
0
        private bool _IsWordListed(UNode node, String szWord)
        {
            UNode curNode = node;

            szWord += '\0';
            int  len = szWord.Length;
            int  pos = 0;
            char Herp;
            bool ret = false;

            Herp = szWord[pos];
            while (curNode != null)
            {
                if (curNode.mHerp == Herp)
                {
                    if (curNode.mHerp == '\0')
                    {
                        ret = true;
                        break;
                    }
                    pos++;
                    Herp    = szWord[pos];
                    curNode = curNode.mNext;
                }
                else
                {
                    curNode = curNode.mAlter;
                }
            }
            return(ret);
        }
示例#3
0
        public int Add(String szWord)
        {
            if (szWord.Trim().Length == 0)
            {
                return(0);
            }
            szWord += '\0';
            if (m_RootNode == null)
            {
                m_RootNode       = new UNode();
                m_RootNode.mHerp = szWord[0];
                nodeCnt++;
            }

            UNode curNode = m_RootNode;
            int   pos     = 0;
            char  Herp    = szWord[pos];

            while (true)
            {
                if (curNode.mHerp == Herp)
                {
                    if (Herp == '\0')
                    {
                        if (curNode.mFreq < short.MaxValue)
                        {
                            curNode.mFreq++;
                        }
                        if (curNode.mFreq == 1)
                        {
                            m_SozSani++;
                        }
                        break;
                    }
                    pos++;
                    Herp = szWord[pos];
                    if (curNode.mNext == null)
                    {
                        curNode.mNext       = new UNode();
                        curNode.mNext.mHerp = Herp;
                        nodeCnt++;
                    }
                    curNode = curNode.mNext;
                }
                else
                {
                    if (curNode.mAlter == null)
                    {
                        curNode.mAlter       = new UNode();
                        curNode.mAlter.mHerp = Herp;
                        nodeCnt++;
                    }
                    curNode = curNode.mAlter;
                }
            }
            return(curNode.mFreq);
        }
示例#4
0
        public override Int64 Add(String soz, Int64 tekrar = 1)
        {
            string szWord = soz.Replace(Uyghur.Sozghuch, "").Trim().ToLower();

            if (szWord.Trim().Length == 0)
            {
                return(0);
            }
            szWord += '\0';
            if (m_RootNode == null)
            {
                m_RootNode       = new UNode();
                m_RootNode.mHerp = szWord[0];
                nodeCnt++;
            }

            UNode curNode = m_RootNode;
            int   pos     = 0;
            char  Herp    = szWord[pos];

            while (true)
            {
                if (curNode.mHerp == Herp)
                {
                    if (Herp == '\0')
                    {
                        if (curNode.mFreq == 0)
                        {
                            m_SozSani++;
                        }
                        curNode.mFreq = (curNode.mFreq + tekrar) < short.MaxValue?(short)(curNode.mFreq + tekrar):short.MaxValue;
                        break;
                    }
                    pos++;
                    Herp = szWord[pos];
                    if (curNode.mNext == null)
                    {
                        curNode.mNext       = new UNode();
                        curNode.mNext.mHerp = Herp;
                        nodeCnt++;
                    }
                    curNode = curNode.mNext;
                }
                else
                {
                    if (curNode.mAlter == null)
                    {
                        curNode.mAlter       = new UNode();
                        curNode.mAlter.mHerp = Herp;
                        nodeCnt++;
                    }
                    curNode = curNode.mAlter;
                }
            }
            return(curNode.mFreq);
        }
示例#5
0
 private void _GetWordCount(UNode curNode, ref int count)
 {
     if (curNode != null)
     {
         if (curNode.mHerp == 0x0)
         {
             count++;
         }
         _GetWordCount(curNode.mNext, ref count);
         _GetWordCount(curNode.mAlter, ref count);
     }
 }
示例#6
0
        public int Add(String szWord, short frq)
        {
            szWord += '\0';
            if (m_RootNode == null)
            {
                m_RootNode       = new UNode();
                m_RootNode.mHerp = szWord[0];
                nodeCnt++;
            }

            UNode curNode = m_RootNode;
            int   pos     = 0;
            char  Herp    = szWord[pos];

            while (true)
            {
                if (curNode.mHerp == Herp)
                {
                    if (Herp == '\0')
                    {
                        curNode.mFreq += frq;
                        if (curNode.mFreq == frq)
                        {
                            m_SozSani++;
                        }
                        break;
                    }
                    pos++;
                    Herp = szWord[pos];
                    if (curNode.mNext == null)
                    {
                        curNode.mNext       = new UNode();
                        curNode.mNext.mHerp = Herp;
                        nodeCnt++;
                    }
                    curNode = curNode.mNext;
                }
                else
                {
                    if (curNode.mAlter == null)
                    {
                        curNode.mAlter       = new UNode();
                        curNode.mAlter.mHerp = Herp;
                        nodeCnt++;
                    }
                    curNode = curNode.mAlter;
                }
            }
            return(curNode.mFreq);
        }
示例#7
0
 private void _SearchAll(UNode curNode, String Soz)
 {
     if (curNode != null)
     {
         if (curNode.mHerp == 0x0)
         {
             if (!tmpNam.Contains(Soz))
             {
                 tmpNam.Add(Soz);
             }
         }
         _SearchAll(curNode.mNext, Soz + curNode.mHerp);
         _SearchAll(curNode.mAlter, Soz);
     }
 }
示例#8
0
 void Save(UNode curNode, String Soz)
 {
     if (curNode != null)
     {
         if (curNode.mHerp == 0x0)
         {
             if (curNode.mFreq >= m_FrqTh)
             {
                 m_Out.WriteLine(Soz + "\t" + curNode.mFreq);
             }
             Save(curNode.mAlter, Soz);
         }
         else
         {
             Save(curNode.mNext, Soz + curNode.mHerp);
             Save(curNode.mAlter, Soz);
         }
     }
 }
示例#9
0
 private void GetBarliqSoz(UNode curNode, String Soz)
 {
     if (curNode != null)
     {
         if (curNode.mHerp == 0x0)
         {
             if (curNode.mFreq >= m_FrqTh)
             {
                 hemmeSoz.Add(Soz + "\t" + curNode.mFreq);
             }
             GetBarliqSoz(curNode.mAlter, Soz);
         }
         else
         {
             GetBarliqSoz(curNode.mNext, Soz + curNode.mHerp);
             GetBarliqSoz(curNode.mAlter, Soz);
         }
     }
 }
示例#10
0
        private void _GetSuggestions(UNode curNode, String Soz, int pos, String namzat)
        {
            if (curNode == null)
            {
                return;
            }
            char Herp = Soz[pos];

            if (curNode.mHerp == Herp || Herp == '?' || Herp == '*')
            {
                if (curNode.mHerp == 0x0 && Herp == '\0')
                {
                    if (!tmpNam.Contains(namzat))
                    {
                        tmpNam.Add(namzat);
                        NamzatQelip nm = new NamzatQelip();
                        nm.soz    = namzat;
                        nm.tekrar = curNode.mFreq;
                        _namzatlar.Add(nm);
                    }
                }
                else if (Herp == '*')
                {
                    _SearchAll(curNode, namzat);
                }
                else
                {
                    _GetSuggestions(curNode.mNext, Soz, pos + 1, namzat + curNode.mHerp);
                    _GetSuggestions(curNode.mAlter, Soz, pos, namzat);
                }
            }
            else
            {
                _GetSuggestions(curNode.mAlter, Soz, pos, namzat);
            }
        }