コード例 #1
0
		/// <summary>
		///     Copies the elements of an array at the end of this instance of 'PhoneticRuleCollection'.
		/// </summary>
		/// <param name='value'>
		///     An array of 'PhoneticRule' objects to add to the collection.
		/// </param>
		public void AddRange(PhoneticRule[] value) 
		{
			for (int Counter = 0; (Counter < value.Length); Counter = (Counter + 1)) 
			{
				this.Add(value[Counter]);
			}
		}
コード例 #2
0
		/// <summary>
		///     Initializes the dictionary by loading and parsing the
		///     dictionary file and the user file.
		/// </summary>
		public void Initialize()
		{
			// clean up data first
			_baseWords.Clear();
			_replaceCharacters.Clear();
			_prefixRules.Clear();
			_suffixRules.Clear();
			_phoneticRules.Clear();
			_tryCharacters = "";
			

			// the following is used to split a line by white space
			Regex _spaceRegx = new Regex(@"[^\s]+", RegexOptions.Compiled);
			MatchCollection partMatches;

			string currentSection = "";
			AffixRule currentRule = null;
			string dictionaryPath = Path.Combine(_dictionaryFolder, _dictionaryFile);

			TraceWriter.TraceInfo("Loading Dictionary:{0}", dictionaryPath);

			// open dictionary file
			FileStream fs = new FileStream(dictionaryPath, FileMode.Open, FileAccess.Read, FileShare.Read);
			StreamReader sr = new StreamReader(fs, Encoding.UTF8);
			
			// read line by line
			while (sr.Peek() >= 0) 
			{
				string tempLine = sr.ReadLine().Trim();
				if (tempLine.Length > 0)
				{
					// check for section flag
					switch (tempLine)
					{
						case "[Copyright]" :
						case "[Try]" : 
						case "[Replace]" : 
						case "[Prefix]" :
						case "[Suffix]" :
						case "[Phonetic]" :
						case "[Words]" :
							// set current section that is being parsed
							currentSection = tempLine;
							break;
						default :		
							// parse line and place in correct object
						switch (currentSection)
						{
							case "[Copyright]" :
								this.Copyright += tempLine + "\r\n";
								break;
							case "[Try]" : // ISpell try chars
								this.TryCharacters += tempLine;
								break;
							case "[Replace]" : // ISpell replace chars
								this.ReplaceCharacters.Add(tempLine);
								break;
							case "[Prefix]" : // MySpell prefix rules
							case "[Suffix]" : // MySpell suffix rules

								// split line by white space
								partMatches = _spaceRegx.Matches(tempLine);
									
								// if 3 parts, then new rule  
								if (partMatches.Count == 3)
								{
									currentRule = new AffixRule();
									
									// part 1 = affix key
									currentRule.Name = partMatches[0].Value;
									// part 2 = combine flag
									if (partMatches[1].Value == "Y") currentRule.AllowCombine = true;
									// part 3 = entry count, not used

									if (currentSection == "[Prefix]")
									{
										// add to prefix collection
										this.PrefixRules.Add(currentRule.Name, currentRule);
									}
									else 
									{
										// add to suffix collection
										this.SuffixRules.Add(currentRule.Name, currentRule);
									}
								}
									//if 4 parts, then entry for current rule
								else if (partMatches.Count == 4)
								{
									// part 1 = affix key
									if (currentRule.Name == partMatches[0].Value)
									{
										AffixEntry entry = new AffixEntry();

										// part 2 = strip char
										if (partMatches[1].Value != "0") entry.StripCharacters = partMatches[1].Value;
										// part 3 = add chars
										entry.AddCharacters = partMatches[2].Value;
										// part 4 = conditions
										AffixUtility.EncodeConditions(partMatches[3].Value, entry);

										currentRule.AffixEntries.Add(entry);
									}
								}	
								break;
							case "[Phonetic]" : // ASpell phonetic rules
								// split line by white space
								partMatches = _spaceRegx.Matches(tempLine);
								if (partMatches.Count >= 2)
								{
									PhoneticRule rule = new PhoneticRule();
									PhoneticUtility.EncodeRule(partMatches[0].Value, ref rule);
									rule.ReplaceString = partMatches[1].Value;
									_phoneticRules.Add(rule);
								}
								break;
							case "[Words]" : // dictionary word list
								// splits word into its parts
								string[] parts = tempLine.Split('/');
								Word tempWord = new Word();
								// part 1 = base word
								tempWord.Text = parts[0];
								// part 2 = affix keys
								if (parts.Length >= 2) tempWord.AffixKeys = parts[1];
								// part 3 = phonetic code
								if (parts.Length >= 3) tempWord.PhoneticCode = parts[2];
								
								this.BaseWords.Add(tempWord.Text, tempWord);
								break;
						} // currentSection swith
							break;
					} //tempLine switch
				} // if templine
			} // read line
			// close files
			sr.Close();
			fs.Close();

			TraceWriter.TraceInfo("Dictionary Loaded BaseWords:{0}; PrefixRules:{1}; SuffixRules:{2}; PhoneticRules:{3}",
				this.BaseWords.Count, this.PrefixRules.Count, this.SuffixRules.Count, this.PhoneticRules.Count);

			this.LoadUserFile();

			_initialized = true;
		}
コード例 #3
0
 /// <summary>
 ///     Adds a 'PhoneticRule' item with the specified value to the 'PhoneticRuleCollection'
 /// </summary>
 /// <param name='value'>
 ///     The 'PhoneticRule' to add.
 /// </param>
 /// <returns>
 ///     The index at which the new element was inserted.
 /// </returns>
 public int Add(PhoneticRule value)
 {
     return List.Add(value);
 }
コード例 #4
0
 /// <summary>
 ///     Initializes a new instance of 'PhoneticRuleCollection' with an array of 'PhoneticRule' objects.
 /// </summary>
 /// <param name='value'>
 ///     An array of 'PhoneticRule' objects with which to initialize the collection
 /// </param>
 public PhoneticRuleCollection(PhoneticRule[] value)
 {
     this.AddRange(value);
 }
コード例 #5
0
 /// <summary>
 ///     Removes a specific item from the 'PhoneticRuleCollection'.
 /// </summary>
 /// <param name='value'>
 ///     The item to remove from the 'PhoneticRuleCollection'.
 /// </param>
 public void Remove(PhoneticRule value)
 {
     List.Remove(value);
 }
コード例 #6
0
 /// <summary>
 ///     Inserts an existing 'PhoneticRule' into the collection at the specified index.
 /// </summary>
 /// <param name='index'>
 ///     The zero-based index where the new item should be inserted.
 /// </param>
 /// <param name='value'>
 ///     The item to insert.
 /// </param>
 public void Insert(int index, PhoneticRule value)
 {
     List.Insert(index, value);
 }
コード例 #7
0
 /// <summary>
 ///     Returns the index of a 'PhoneticRule' object in the collection.
 /// </summary>
 /// <param name='value'>
 ///     The 'PhoneticRule' object whose index will be retrieved.
 /// </param>
 /// <returns>
 ///     If found, the index of the value; otherwise, -1.
 /// </returns>
 public int IndexOf(PhoneticRule value)
 {
     return List.IndexOf(value);
 }
コード例 #8
0
 /// <summary>
 ///     Copies the 'PhoneticRuleCollection' values to a one-dimensional System.Array
 ///     instance starting at the specified array index.
 /// </summary>
 /// <param name='array'>
 ///     The one-dimensional System.Array that represents the copy destination.
 /// </param>
 /// <param name='index'>
 ///     The index in the array where copying begins.
 /// </param>
 public void CopyTo(PhoneticRule[] array, int index)
 {
     List.CopyTo(array, index);
 }
コード例 #9
0
 /// <summary>
 ///     Gets a value indicating whether the 'PhoneticRuleCollection' contains the specified value.
 /// </summary>
 /// <param name='value'>
 ///     The item to locate.
 /// </param>
 /// <returns>
 ///     True if the item exists in the collection; false otherwise.
 /// </returns>
 public bool Contains(PhoneticRule value)
 {
     return List.Contains(value);
 }
コード例 #10
0
		/// <summary>
		///     Converts the rule text in to a PhoneticRule class
		/// </summary>
		/// <param name="ruleText" type="string">
		///     <para>
		///         The text to convert
		///     </para>
		/// </param>
		/// <param name="rule" type="ref NetSpell.SpellChecker.Dictionary.Phonetic.PhoneticRule">
		///     <para>
		///         The object that will hold the conversion data
		///     </para>
		/// </param>
		public static void EncodeRule(string ruleText, ref PhoneticRule rule)
		{
			// clear the conditions array
			for (int i=0; i < rule.Condition.Length; i++)
			{
				rule.Condition[i] = 0;
			}

			bool group = false;  /* group indicator */
			bool end = false;   /* end condition indicator */

			char [] memberChars = new char[200];
			int numMember = 0;   /* number of member in group */

			foreach (char cond in ruleText)
			{
				switch (cond) 
				{
					case '(' :
						group = true;
						break;
					case ')' :
						end = true;
						break;
					case '^' :
						rule.BeginningOnly = true;
						break;
					case '$' :
						rule.EndOnly = true;
						break;
					case '-' :
						rule.ConsumeCount++;
						break;
					case '<' :
						rule.ReplaceMode = true;
						break;
					case '0' :
					case '1' :
					case '2' :
					case '3' :
					case '4' :
					case '5' :
					case '6' :
					case '7' :
					case '8' :
					case '9' :
						rule.Priority = int.Parse(cond.ToString(CultureInfo.CurrentUICulture));
						break;
					default :
						if (group)
						{
							// add chars to group
							memberChars[numMember] = cond;
							numMember++;
						}
						else
						{
							end = true;
						}
						break;
				} // switch

				if (end)
				{
					if (group)
					{
						// turn on chars in member group
						for (int j=0; j < numMember; j++) 
						{
							int charCode = (int)memberChars[j];
							rule.Condition[charCode] = rule.Condition[charCode] | (1 << rule.ConditionCount);
						}

						group = false;
						numMember = 0;
					}
					else
					{
						// turn on char
						int charCode = (int)cond;
						rule.Condition[charCode] = rule.Condition[charCode] | (1 << rule.ConditionCount);
					}
					end = false;
					rule.ConditionCount++;
				} // if end
			} // for each
		}
コード例 #11
0
        /// <summary>
        ///     Converts the rule text in to a PhoneticRule class
        /// </summary>
        /// <param name="ruleText" type="string">
        ///     <para>
        ///         The text to convert
        ///     </para>
        /// </param>
        /// <param name="rule" type="ref NetSpell.SpellChecker.Dictionary.Phonetic.PhoneticRule">
        ///     <para>
        ///         The object that will hold the conversion data
        ///     </para>
        /// </param>
        public static void EncodeRule(string ruleText, ref PhoneticRule rule)
        {
            // clear the conditions array
            for (int i = 0; i < rule.Condition.Length; i++)
            {
                rule.Condition[i] = 0;
            }

            bool group = false;             /* group indicator */
            bool end   = false;             /* end condition indicator */

            char [] memberChars = new char[200];
            int     numMember   = 0;         /* number of member in group */

            foreach (char cond in ruleText)
            {
                switch (cond)
                {
                case '(':
                    group = true;
                    break;

                case ')':
                    end = true;
                    break;

                case '^':
                    rule.BeginningOnly = true;
                    break;

                case '$':
                    rule.EndOnly = true;
                    break;

                case '-':
                    rule.ConsumeCount++;
                    break;

                case '<':
                    rule.ReplaceMode = true;
                    break;

                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    rule.Priority = int.Parse(cond.ToString(CultureInfo.CurrentUICulture));
                    break;

                default:
                    if (group)
                    {
                        // add chars to group
                        memberChars[numMember] = cond;
                        numMember++;
                    }
                    else
                    {
                        end = true;
                    }
                    break;
                }                 // switch

                if (end)
                {
                    if (group)
                    {
                        // turn on chars in member group
                        for (int j = 0; j < numMember; j++)
                        {
                            int charCode = (int)memberChars[j];
                            rule.Condition[charCode] = rule.Condition[charCode] | (1 << rule.ConditionCount);
                        }

                        group     = false;
                        numMember = 0;
                    }
                    else
                    {
                        // turn on char
                        int charCode = (int)cond;
                        rule.Condition[charCode] = rule.Condition[charCode] | (1 << rule.ConditionCount);
                    }
                    end = false;
                    rule.ConditionCount++;
                }         // if end
            }             // for each
        }
コード例 #12
0
 /// <summary>
 ///     Adds a 'PhoneticRule' item with the specified value to the 'PhoneticRuleCollection'
 /// </summary>
 /// <param name='value'>
 ///     The 'PhoneticRule' to add.
 /// </param>
 /// <returns>
 ///     The index at which the new element was inserted.
 /// </returns>
 public int Add(PhoneticRule value)
 {
     return(List.Add(value));
 }
コード例 #13
0
 /// <summary>
 ///     Removes a specific item from the 'PhoneticRuleCollection'.
 /// </summary>
 /// <param name='value'>
 ///     The item to remove from the 'PhoneticRuleCollection'.
 /// </param>
 public void Remove(PhoneticRule value)
 {
     List.Remove(value);
 }
コード例 #14
0
 /// <summary>
 ///     Inserts an existing 'PhoneticRule' into the collection at the specified index.
 /// </summary>
 /// <param name='index'>
 ///     The zero-based index where the new item should be inserted.
 /// </param>
 /// <param name='value'>
 ///     The item to insert.
 /// </param>
 public void Insert(int index, PhoneticRule value)
 {
     List.Insert(index, value);
 }
コード例 #15
0
 /// <summary>
 ///     Returns the index of a 'PhoneticRule' object in the collection.
 /// </summary>
 /// <param name='value'>
 ///     The 'PhoneticRule' object whose index will be retrieved.
 /// </param>
 /// <returns>
 ///     If found, the index of the value; otherwise, -1.
 /// </returns>
 public int IndexOf(PhoneticRule value)
 {
     return(List.IndexOf(value));
 }
コード例 #16
0
 /// <summary>
 ///     Gets a value indicating whether the 'PhoneticRuleCollection' contains the specified value.
 /// </summary>
 /// <param name='value'>
 ///     The item to locate.
 /// </param>
 /// <returns>
 ///     True if the item exists in the collection; false otherwise.
 /// </returns>
 public bool Contains(PhoneticRule value)
 {
     return(List.Contains(value));
 }