/// <summary>
 /// Creates a word feature suffix table with given file path.
 /// </summary>
 /// <param name="filePath">The location of the suffix file to load left.</param>
 /// <returns>A new instance of WordFeatureSuffix Table loaded from file.</returns>
 public static WordFeatureSuffixTable Read(string filePath)
 {
     WordFeatureSuffixTable table = new WordFeatureSuffixTable();
     table.Load(filePath);
     return table;
 }
        /// <summary>
        /// Compiles suffix table into binary stream.
        /// </summary>
        /// <param name="wordFeatureSuffixTable">The instance of suffix table.</param>
        /// <param name="outputStream">The instance of output binary stream.</param>
        /// <returns>Any error found during the compilation.</returns>
        public static ErrorSet Compile(WordFeatureSuffixTable wordFeatureSuffixTable, Stream outputStream)
        {
            if (wordFeatureSuffixTable == null)
            {
                throw new ArgumentNullException("wordFeatureSuffixTable");
            }

            if (outputStream == null)
            {
                throw new ArgumentNullException("outputStream");
            }

            ErrorSet errorSet = new ErrorSet();
            if (wordFeatureSuffixTable.NounItems.Count == 0)
            {
                errorSet.Add(WordFeatureSuffixCompilerError.EmptyData, "Empty noun suffix.");
            }

            if (wordFeatureSuffixTable.AdjItems.Count == 0)
            {
                errorSet.Add(WordFeatureSuffixCompilerError.EmptyData, "Empty adjective suffix.");
            }

            if (wordFeatureSuffixTable.VerbItems.Count == 0)
            {
                errorSet.Add(WordFeatureSuffixCompilerError.EmptyData, "Empty verb suffix.");
            }

            if (wordFeatureSuffixTable.SeparatorItems.Count == 0)
            {
                errorSet.Add(WordFeatureSuffixCompilerError.EmptyData, "Empty separator character.");
            }

            BinaryWriter writer = new BinaryWriter(outputStream);
            writer.Write((uint)wordFeatureSuffixTable.Language);

            // write the size of the structure for verification purchase
            writer.Write(((uint)Marshal.SizeOf(typeof(SuffixData))));

            writer.Write((uint)wordFeatureSuffixTable.NounItems.Count);
            foreach (var item in wordFeatureSuffixTable.NounItems)
            {
                SuffixData suffixdata = new SuffixData(item.Text);
                writer.Write(Helper.ToBytes(suffixdata));
            }

            writer.Write((uint)wordFeatureSuffixTable.AdjItems.Count);
            foreach (var item in wordFeatureSuffixTable.AdjItems)
            {
                SuffixData suffixdata = new SuffixData(item.Text);
                writer.Write(Helper.ToBytes(suffixdata));
            }

            writer.Write((uint)wordFeatureSuffixTable.VerbItems.Count);
            foreach (var item in wordFeatureSuffixTable.VerbItems)
            {
                SuffixData suffixdata = new SuffixData(item.Text);
                writer.Write(Helper.ToBytes(suffixdata));
            }

            writer.Write((uint)wordFeatureSuffixTable.SeparatorItems.Count);
            foreach (var item in wordFeatureSuffixTable.SeparatorItems)
            {
                SuffixData suffixdata = new SuffixData(item.Text);
                writer.Write(Helper.ToBytes(suffixdata));
            }

            return errorSet;
        }