Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        private void LoadAffixesFile(string path)
        {
            StreamReader f = File.OpenText(path);
            string       s;

            char[]    sepChars     = new char[] { ' ', '\t' };
            AffixRule curAffixRule = null;

            affixRules       = new AffixRulesCollection();
            affixRulesLookup = new AffixRule['Z' + 1];
            tryCharacters    = "";
            replacePatterns  = new List <ReplacePattern> ();

            while ((s = f.ReadLine()) != null)
            {
                // ignore comment
                if (s.StartsWith("#"))
                {
                    continue;
                }

                string[] data = s.Split(sepChars, StringSplitOptions.RemoveEmptyEntries);
                if (data.Length == 0)
                {
                    continue;                                           // empty string
                }
                if (data[0] == "PFX" || data[0] == "SFX")
                {
                    if (data.Length == 4)
                    {
                        // add new rule
                        curAffixRule = AffixRule.Parse(data);
                        affixRules.Add(curAffixRule);
                        affixRulesLookup[curAffixRule.Name] = curAffixRule;
                    }
                    else if (curAffixRule != null)
                    {
                        // add affix
                        curAffixRule.ParseAndAddAffix(data);
                    }
                }
                else
                {
                    if (data[0] == "TRY")
                    {
                        tryCharacters = data[1];
                    }
                    else if (data[0] == "REP" && data.Length == 3)
                    {
                        replacePatterns.Add(new ReplacePattern(data[1], data[2]));
                    }

                    curAffixRule = null;
                }
            }

            f.Close();
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        private void LoadWordsFile(string path)
        {
            StreamReader f = File.OpenText(path);

            words = new Dictionary <string, SpellWord> ();
            string word;

            f.ReadLine();                       // read 1st line with words count
            while ((word = f.ReadLine()) != null)
            {
                int                  p         = word.IndexOf('/');
                SpellWord            spellWord = new SpellWord();
                AffixRulesCollection wordRules = new AffixRulesCollection();
                if (p != -1)
                {
                    int n = word.Length;
                    for (int i = p + 1; i < n; ++i)
                    {
                        char c = word[i];
                        if (c < affixRulesLookup.Length)
                        {
                            AffixRule rule = affixRulesLookup[c];
                            if (rule != null)
                            {
                                wordRules.Add(rule);
                            }
                        }
                    }
                    word = word.Substring(0, p);
                }
                spellWord.AffixRules = wordRules.ToArray <AffixRule>();

                try
                {
                    words.Add(word, spellWord);
                }
                catch (Exception)
                {
                }
            }

            f.Close();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        private void LoadWordsFile(string path)
        {
            StreamReader f = File.OpenText (path);
            words = new Dictionary<string, SpellWord> ();
            string word;

            f.ReadLine ();		// read 1st line with words count
            while ((word = f.ReadLine ()) != null)
            {
                int p = word.IndexOf ('/');
                SpellWord spellWord= new SpellWord();
                AffixRulesCollection wordRules = new AffixRulesCollection();
                if (p != -1)
                {
                    int n = word.Length;
                    for (int i = p+1; i < n; ++i)
                    {
                        char c = word[i];
                        if (c< affixRulesLookup.Length)
                        {
                            AffixRule rule= affixRulesLookup[c];
                            if (rule!= null)
                                wordRules.Add (rule);
                        }
                    }
                    word = word.Substring (0, p);
                }
                spellWord.AffixRules = wordRules.ToArray<AffixRule>();

                try
                {
                    words.Add (word, spellWord);
                }
                catch (Exception)
                {
                }
            }

            f.Close ();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        private void LoadAffixesFile(string path)
        {
            StreamReader f= File.OpenText (path);
            string s;
            char[] sepChars= new char[] {' ', '\t'};
            AffixRule curAffixRule = null;
            affixRules = new AffixRulesCollection ();
            affixRulesLookup = new AffixRule['Z'+1];
            tryCharacters = "";
            replacePatterns = new List<ReplacePattern> ();

            while ((s= f.ReadLine())!= null)
            {
                // ignore comment
                if (s.StartsWith ("#"))
                    continue;

                string[] data = s.Split (sepChars, StringSplitOptions.RemoveEmptyEntries);
                if (data.Length == 0)
                    continue;			// empty string

                if (data[0] == "PFX" || data[0] == "SFX")
                {
                    if (data.Length == 4)
                    {
                        // add new rule
                        curAffixRule = AffixRule.Parse (data);
                        affixRules.Add (curAffixRule);
                        affixRulesLookup[curAffixRule.Name] = curAffixRule;
                    }
                    else if (curAffixRule != null)
                    {
                        // add affix
                        curAffixRule.ParseAndAddAffix (data);
                    }
                }
                else
                {
                    if (data[0] == "TRY")
                        tryCharacters = data[1];
                    else if (data[0] == "REP" && data.Length == 3)
                        replacePatterns.Add (new ReplacePattern (data[1], data[2]));

                    curAffixRule = null;
                }
            }

            f.Close ();
        }