Example #1
0
  }//ConfigurationXml	 

  /// <summary>Scripture Reference URI.</summary>
  /// <param name="databaseConnectionString">The database connection string.</param>
  /// <param name="filenameConfigurationXml">The filename configuration Xml.</param>
  /// <param name="exceptionMessage">The exception message.</param>  
  /// <param name="dataSet">The dataset.</param>
  public static void ScriptureReferenceURI
  (
       string  databaseConnectionString,
       string  filenameConfigurationXml,
   ref string  exceptionMessage,
   ref DataSet dataSet
  )
  {
   bool                                         boolView                                  = false;
   
   int                                          columnIndexScriptureReference             = -1;
   
   string                                       dataColumnName                            = null;
   string                                       scriptureReferenceColumnValue             = null;
   string                                       scriptureReferenceColumnName              = null;
   string                                       scriptureReferenceColumnNameURI           = null;
   string                                       scriptureReferenceURI                     = null;   
   string[][]                                   scriptureReferenceArray                   = null;    
   string                                       columnNamePrimary                         = null;
   string                                       columnValuePrimary                        = null; 
   string                                       tableName                                 = null;
   
   ArrayList                                    scriptureReferenceSet                     = null;
   ArrayList                                    scriptureReferenceURISet                  = null;
   ScriptureReferenceBookChapterVersePrePost[]  scriptureReferenceBookChapterVersePrePost = null;
   StringBuilder                                columnSet                                 = null;   
   StringBuilder                                uriCrosswalkXml                           = null;
   StringBuilder                                uriCrosswalkHtml                          = null;   
   StringBuilder                                SQLStatement                              = null;      
   OleDbConnection                              oleDbConnection                           = null;
   XmlNodeList                                  scriptureReferenceColumnSet               = null;

   scriptureReferenceColumnSet = UtilityXml.SelectNodes
   (
        filenameConfigurationXml,
    ref exceptionMessage,
        XPathColumnScriptureReference
   );
   try
   {
    oleDbConnection = UtilityDatabase.DatabaseConnectionInitialize
    (
         databaseConnectionString,
     ref exceptionMessage
    ); 

    foreach ( DataTable dataTable in dataSet.Tables )
    {
   
     columnIndexScriptureReference = UtilityDatabase.DataTableColumnIndex
     (
      dataTable,
      "ScriptureReference"
     ); 
     
     if ( columnIndexScriptureReference < 0 )
     {
      continue;
     }           	
    	
     tableName                = dataTable.TableName;
     scriptureReferenceSet    = new ArrayList();
     scriptureReferenceURISet = new ArrayList();
     SQLStatement = new StringBuilder();
     
     if ( tableName.IndexOf("View" ) < 0 )
     {
      boolView = false;
      SQLStatement.AppendFormat
      (
       InformationSchemaColumnNamePrimaryColumnSQL,
       tableName
      );
     }
     else
     {
      boolView = true;	
      SQLStatement.AppendFormat
      (
       InformationSchemaColumnNamePrimaryColumnSQL,
       tableName.Substring(4)
      );
     }

      #if (DEBUG)
       System.Console.WriteLine("SQLStatement: {0}", SQLStatement);
      #endif
     
     columnNamePrimary = (string) UtilityDatabase.DatabaseQuery
     (
          databaseConnectionString,
      ref exceptionMessage,
          SQLStatement.ToString(),
          CommandType.Text
     );
     
     if ( boolView == true )
     {
      columnNamePrimary = String.Concat( tableName.Substring(4), columnNamePrimary );	
     }	 

     #if (DEBUG)
      System.Console.WriteLine("ColumnNamePrimary: {0}", columnNamePrimary);
     #endif
     
     foreach ( DataColumn dataColumn in dataTable.Columns )
     {
      dataColumnName = dataColumn.ColumnName.Trim();
      /*
      #if (DEBUG)
       System.Console.WriteLine("Table Name: {0} | ColumnName: {1}", tableName, dataColumnName);
      #endif
      */
      if ( dataColumnName.IndexOf( ScriptureReferenceURIColumnNamePostfix ) >= 0 )
      {
       continue;
      }
      if ( dataColumnName.IndexOf( ScriptureReferenceColumnNamePostfix ) >= 0 )
      {
       scriptureReferenceSet.Add( dataColumnName );
       scriptureReferenceColumnName    = dataColumnName;
       scriptureReferenceColumnNameURI = scriptureReferenceColumnName + "URI";
       if ( dataTable.Columns.Contains( scriptureReferenceColumnNameURI ) == false )
       {
        /*
        #if (DEBUG)
         System.Console.WriteLine("Table Name: {0} | ColumnName: {1}", tableName, scriptureReferenceColumnNameURI);
        #endif
        */
        scriptureReferenceURISet.Add( scriptureReferenceColumnNameURI );
       }//if dataTable.Columns.Contains( scriptureReferenceColumnNameURI ) == false )
      }//if ( dataColumnName.IndexOf( ScriptureReferenceColumnNamePostfix ) >= 0 )
     }//foreach ( DataColumn dataColumn in dataTable.Columns )

     foreach ( object columnName in scriptureReferenceURISet )
     {
      scriptureReferenceColumnNameURI = columnName.ToString().Trim();
      dataTable.Columns.Add( scriptureReferenceColumnNameURI );
     }

     foreach ( DataColumn dataColumn in dataTable.Columns )
     {
      dataColumnName = dataColumn.ColumnName.Trim();
      /*
       #if (DEBUG)
        System.Console.WriteLine("Table Name: {0} | ColumnName: {1}", tableName, dataColumnName);
       #endif
      */ 
     }//foreach ( DataColumn dataColumn in dataTable.Columns )

     foreach ( DataRow dataRow in dataTable.Rows )
     {
      columnValuePrimary = dataRow[columnNamePrimary].ToString().Trim();
      columnSet = new StringBuilder();
      /*
       #if (DEBUG)
        System.Console.WriteLine("ColumnValuePrimary: {0}", columnValuePrimary);
       #endif
      */ 
      foreach ( object columnName in scriptureReferenceSet )
      {
       #if (DEBUG)
        System.Console.WriteLine("ColumnName: {0}", columnName);
       #endif
       scriptureReferenceColumnName  = columnName.ToString().Trim();
       scriptureReferenceColumnValue = dataRow[scriptureReferenceColumnName].ToString().Trim();
     
       #if (DEBUG)
        System.Console.WriteLine
        (
         "Scripture Reference Column Name: {0} | Value: {1}", 
         scriptureReferenceColumnName,
         scriptureReferenceColumnValue
        );
       #endif
       scriptureReferenceColumnNameURI = scriptureReferenceColumnName + "URI";
       if ( scriptureReferenceColumnValue != null && scriptureReferenceColumnValue != string.Empty )
       {
        ScriptureReference.ScriptureReferenceParser
        (
             new string[] { scriptureReferenceColumnValue },
             databaseConnectionString,
         ref exceptionMessage,
         ref scriptureReferenceBookChapterVersePrePost,
         ref scriptureReferenceArray,
         ref uriCrosswalkHtml,
         ref uriCrosswalkXml
        );//ScriptureReference.ScriptureReferenceParser()
        scriptureReferenceURI = uriCrosswalkHtml.ToString();
        if ( UtilityDatabase.DataSetTableColumnContains( dataSet, tableName, scriptureReferenceColumnNameURI ) == false )
        {
         UtilityDatabase.DataSetTableColumnAdd( dataSet, tableName, scriptureReferenceColumnNameURI );	
         dataRow[scriptureReferenceColumnNameURI] = scriptureReferenceURI;
         continue;
        }//if ( DataSetTableColumnContains( dataSet, dataTable, scriptureReferenceColumnNameURI ) )	
        dataRow[scriptureReferenceColumnNameURI] = scriptureReferenceURI;
        if ( scriptureReferenceURISet.IndexOf( scriptureReferenceColumnNameURI ) >= 0 )
        {
         continue;
        }

        if ( columnSet.Length != 0 )
        {
         columnSet.Append(',');
        }
        columnSet.AppendFormat
        (
         UtilityDatabase.DatabaseTemplateSQLSet,
         scriptureReferenceColumnNameURI,
         scriptureReferenceURI
        ); 
        /*
        #if (DEBUG)
         System.Console.WriteLine("columnSet: {0}", columnSet);      
        #endif
        */
        SQLStatement = new StringBuilder();
        SQLStatement.AppendFormat
        (
         UtilityDatabase.DatabaseTemplateSQLUpdateScriptureReferenceURISet,
         tableName,
         columnSet,
         columnNamePrimary,
         columnValuePrimary
        );   
        #if (DEBUG)
         System.Console.WriteLine("SQL Statement: {0}", SQLStatement.ToString() );      
        #endif
        UtilityDatabase.DatabaseNonQuery
        (
             oleDbConnection,
         ref exceptionMessage,
             SQLStatement.ToString()
        );
       }//if ( scriptureReferenceColumnValue != null && scriptureReferenceColumnValue != string.Empty )
      }//foreach ( object columnName in dataTableColumnName )
     }//foreach ( DataRow dataRow in dataTable )
    }//foreach ( DataTable dataTable in dataSet ) 
    UtilityDatabase.DatabaseConnectionHouseKeeping
    (
         oleDbConnection,
     ref exceptionMessage
    );
   }//try
   catch (OleDbException exception)
   {
    //exceptionMessage = exception.Message;
    exceptionMessage = UtilityEventLog.WriteEntryOleDbErrorCollection( exception );
    System.Console.WriteLine("OleDbException: {0}", exceptionMessage);
   }//catch (OleDbException exception)
   catch (SecurityException exception)
   {
    exceptionMessage = exception.Message;
    System.Console.WriteLine( "SecurityException: {0}", exception.Message );
   }//catch (SecurityException exception)
   catch (SystemException exception)
   {
    exceptionMessage = exception.Message;
    System.Console.WriteLine( "SystemException: {0}", exception.Message );
   }//catch (SystemException exception)
   catch (Exception exception)
   {
    exceptionMessage = exception.Message;   
    System.Console.WriteLine( "Exception: {0}", exception.Message );
   }//catch (Exception exception)
  }//public static void ScriptureReferenceURI()
Example #2
0
        }//main()

        ///<summary>Stub.</summary>
        public static void FileImport
        (
            ref String databaseConnectionString,
            ref AccountChartArgument accountChartArgument,
            ref String exceptionMessage
        )
        {
            int dataFileIndex = 0;
            int sQLStatementAttributeIndex        = -1;
            int sQLStatementAttributeIndexCurrent = -1;
            int streamRecordIndex = 0;

            String databaseStatementUpdate   = null;
            String databaseStatementTruncate = null;

            String directoryNameRoot = null;
            String fileNameCurrent   = null;
            String fileNamePattern   = null;
            String streamColumn      = null;
            String streamRecord      = null;


            StringBuilder[] stringBuilderStreamColumn = null;

            ArrayList arrayListDirectoryName = null;
            ArrayList arrayListFileName      = null;

            OleDbConnection oleDbConnection = null;

            stringBuilderStreamColumn = new StringBuilder[SQLStatementAttribute.Length];

            oleDbConnection = UtilityDatabase.DatabaseConnectionInitialize
                              (
                databaseConnectionString,
                ref exceptionMessage
                              );

            if (accountChartArgument.TableTruncate)
            {
                databaseStatementTruncate = String.Format
                                            (
                    SQLStatementTruncate,
                    SQLStatementClass
                                            );

                UtilityDebug.Write(databaseStatementTruncate);

                UtilityDatabase.DatabaseNonQuery
                (
                    oleDbConnection,
                    ref exceptionMessage,
                    databaseStatementTruncate
                );
            }//if ( accountChartArgument.TableTruncate )

            try
            {
                for (dataFileIndex = 0; dataFileIndex < accountChartArgument.dataFile.Length; ++dataFileIndex)
                {
                    UtilityDirectory.Dir
                    (
                        ref accountChartArgument.dataFile[dataFileIndex],
                        ref directoryNameRoot,
                        ref fileNamePattern,
                        ref arrayListDirectoryName,
                        ref arrayListFileName
                    );

                    UtilityDebug.Write
                    (
                        String.Format
                        (
                            "accountChartArgument.dataFile[{0}]: {1}",
                            dataFileIndex,
                            accountChartArgument.dataFile[dataFileIndex]
                        )
                    );

                    foreach (object fileNameObject in arrayListFileName)
                    {
                        fileNameCurrent = fileNameObject.ToString();

                        UtilityDebug.Write
                        (
                            String.Format
                            (
                                "fileNameCurrent: {0}",
                                fileNameCurrent
                            )
                        );

                        // Create an instance of StreamReader to read from a file.
                        // The using statement also closes the StreamReader.
                        using (StreamReader streamReader = new StreamReader(fileNameCurrent))
                        {
                            while (true)
                            {
                                //Read and display lines from the file until the end of the file is reached.
                                streamRecord = streamReader.ReadLine();

                                if (streamRecord == null)
                                {
                                    break;
                                }//if ( streamRecord == null )

                                /*
                                 * UtilityDebug.Write
                                 * (
                                 * String.Format
                                 * (
                                 * "streamRecord: {0}",
                                 * streamRecord
                                 * )
                                 * );
                                 */

                                for
                                (
                                    sQLStatementAttributeIndex = 0;
                                    sQLStatementAttributeIndex < SQLStatementAttribute.Length;
                                    ++sQLStatementAttributeIndex
                                )
                                {
                                    streamRecordIndex = streamRecord.IndexOf
                                                        (
                                        SQLStatementAttribute[sQLStatementAttributeIndex][SQLStatementAttributeRankName]
                                                        );

                                    if (streamRecordIndex == 0)
                                    {
                                        sQLStatementAttributeIndexCurrent = sQLStatementAttributeIndex;
                                        break;
                                    } //if ( streamRecordIndex == 0 )
                                }     //for

                                if (sQLStatementAttributeIndexCurrent == -1)
                                {
                                    continue;
                                }//if ( sQLStatementAttributeIndexCurrent == -1 )

                                streamRecord = streamRecord.Trim();

                                streamRecord = streamRecord.Replace("'", "''");

                                if (sQLStatementAttributeIndex < SQLStatementAttribute.Length)
                                {
                                    streamColumn = streamRecord.Substring(SQLStatementAttribute[sQLStatementAttributeIndexCurrent][SQLStatementAttributeRankName].Length + 1);
                                    streamColumn = streamColumn.Trim();
                                    stringBuilderStreamColumn[sQLStatementAttributeIndexCurrent] = new StringBuilder(streamColumn);
                                }
                                else
                                {
                                    streamColumn = streamRecord.Trim();
                                    stringBuilderStreamColumn[sQLStatementAttributeIndexCurrent].Append(streamColumn);
                                }

                                /*
                                 * UtilityDebug.Write
                                 * (
                                 * String.Format
                                 * (
                                 * "Name: {0} | Value: {1}",
                                 * SQLStatementAttribute[ sQLStatementAttributeIndexCurrent ][ SQLStatementAttributeRankName ],
                                 * stringBuilderStreamColumn[ sQLStatementAttributeIndexCurrent ]
                                 * )
                                 * );
                                 */

                                if (sQLStatementAttributeIndexCurrent != SQLStatementAttribute.Length - 1)
                                {
                                    continue;
                                }//if ( sQLStatementAttributeIndexCurrent < SQLStatementAttribute.Length - 1 )

                                databaseStatementUpdate = String.Format
                                                          (
                                    SQLStatementUpdate,
                                    SQLStatementClass,
                                    stringBuilderStreamColumn[SQLStatementAttributeIndexAccountNumber],
                                    SQLStatementAttribute[SQLStatementAttributeIndexAccountTitle][SQLStatementAttributeRankAlias],
                                    SQLStatementAttribute[SQLStatementAttributeIndexAccountNumber][SQLStatementAttributeRankAlias],
                                    SQLStatementAttribute[SQLStatementAttributeIndexNormalBalance][SQLStatementAttributeRankAlias],
                                    SQLStatementAttribute[SQLStatementAttributeIndexDefinition][SQLStatementAttributeRankAlias],
                                    stringBuilderStreamColumn[SQLStatementAttributeIndexAccountTitle],
                                    stringBuilderStreamColumn[SQLStatementAttributeIndexNormalBalance],
                                    stringBuilderStreamColumn[SQLStatementAttributeIndexDefinition]
                                                          );

                                /*
                                 * UtilityDebug.Write( databaseStatementUpdate );
                                 */

                                UtilityDatabase.DatabaseNonQuery
                                (
                                    oleDbConnection,
                                    ref exceptionMessage,
                                    databaseStatementUpdate
                                );

                                if (exceptionMessage != null)
                                {
                                    UtilityDebug.Write
                                    (
                                        String.Format
                                        (
                                            "databaseStatementUpdate: {0}",
                                            databaseStatementUpdate
                                        )
                                    );
                                }
                            } //while ( true )
                        }     //using (StreamReader streamReader = new StreamReader(fileNameCurrent))
                    }         //foreach ( object fileNameCurrent in arrayListFileName )
                }             //for ( dataFileIndex = 0; dataFileIndex < accountChartArgument.dataFile.Length; ++dataFileIndex )
            }                 //try
            catch (Exception exception)
            {
                UtilityDebug.Write
                (
                    String.Format
                    (
                        "Exception: {0}",
                        exception.Message
                    )
                );
            }//catch ( Exception exception )

            UtilityDatabase.DatabaseConnectionHouseKeeping
            (
                oleDbConnection,
                ref exceptionMessage
            );
        }//public static void FileImport()
        }//main()

        /// <summary>The dictionary text file.</summary>
        /// <param name="directorynameSource">The directory name, source, for example, ..\\ProjectGutenberg.</param>
        /// <param name="fileSearchPattern">The file search pattern, for example. *.txt.</param>
        public static void DictionaryTextFile
        (
            String directorynameSource,
            String fileSearchPattern
        )
        {
            int    lineMaximumEnglish = -1;
            int    lineNumber         = 0;
            int    sequenceOrderId    = 0;
            String filenameDictionary = null;
            String exceptionMessage   = null;
            String line = null;

            StringBuilder sbDictionary           = null;
            StringBuilder SQLStatement           = null;
            ArrayList     arrayListDirectoryname = null;
            ArrayList     arrayListFilename      = null;

            System.Collections.IEnumerator enumeratorFilename = null;

            OleDbConnection oleDbConnection = null;

            oleDbConnection = UtilityDatabase.DatabaseConnectionInitialize
                              (
                DatabaseConnectionString,
                ref exceptionMessage
                              );

            UtilityDatabase.DatabaseNonQuery
            (
                oleDbConnection,
                ref exceptionMessage,
                SQLStatementDictionaryTruncate
            );

            UtilityDirectory.Dir
            (
                ref DirectorynameSource,
                ref fileSearchPattern,
                ref arrayListDirectoryname,
                ref arrayListFilename
            );//UtilityDirectory.Dir

            enumeratorFilename = arrayListFilename.GetEnumerator();

            while (enumeratorFilename.MoveNext())
            {
                filenameDictionary = (String)enumeratorFilename.Current;
                System.Console.WriteLine("{0}", filenameDictionary);
                sbDictionary = new StringBuilder();

                try
                {
                    // Create an instance of StreamReader to read from a file.
                    // The using statement also closes the StreamReader.
                    using (StreamReader sr = new StreamReader(filenameDictionary))
                    {
                        bool nonEnglish    = false;
                        bool wordTranslate = false;

                        int indexEnglishAlphabet = -1;
                        int lineLength           = -1;
                        int linePosition         = -1;

                        String charCurrent = null;

                        StringBuilder wordEnglish = null;
                        StringBuilder wordKorean  = null;

                        UnicodeCategory unicodeCategoryCurrent;
                        // Read and display lines from the file until the end of
                        // the file is reached.
                        while ((line = sr.ReadLine()) != null)
                        {
                            ++lineNumber;

                            /*
                             #if (DEBUG)
                             * System.Console.WriteLine
                             * (
                             * "Line #: {0} | {1}",
                             * lineNumber,
                             * line
                             * );
                             #endif
                             */

                            line       = line.Trim();
                            lineLength = line.Length;
                            if (lineLength == 0)
                            {
                                continue;
                            }

                            if (Array.IndexOf(PunctuationSymbolAnyOf, line[0]) >= 0)
                            {
                                continue;
                            }
                            else if (line[0] == ' ')
                            {
                                continue;
                            }
                            else if (Char.IsLetter(line[0]))
                            {
                                continue;
                            }
                            else if (line[1] == '.' || line[2] == '.')
                            {
                                continue;
                            }
       #if (DEBUG)
                            System.Console.WriteLine
                            (
                                "Char.IsLetterOrDigit\nLine #: {0} | {1}",
                                lineNumber,
                                line
                            );
       #endif

                            indexEnglishAlphabet = line.IndexOfAny(EnglishAlphabetAnyOf);

                            if (indexEnglishAlphabet < 1)
                            {
                                continue;
                            }

       #if (DEBUG)
                            System.Console.WriteLine("indexEnglishAlphabet: {0}", indexEnglishAlphabet);
       #endif

                            if (indexEnglishAlphabet < 1)
                            {
                                continue;
                            }

                            nonEnglish             = false;
                            unicodeCategoryCurrent = Char.GetUnicodeCategory(line, 0);

                            switch (unicodeCategoryCurrent)
                            {
                            case UnicodeCategory.DecimalDigitNumber:
                                break;

                            case UnicodeCategory.LowercaseLetter:
                                break;

                            case UnicodeCategory.UppercaseLetter:
                                break;

                            default:
                                nonEnglish = true;
                                break;
                            }

       #if (DEBUG)
                            System.Console.WriteLine("if ( nonEnglish == false )");
       #endif

                            if (nonEnglish == false)
                            {
                                continue;
                            }

                            wordEnglish = new StringBuilder();
                            wordKorean  = new StringBuilder();

                            wordKorean.Append(line.Substring(0, indexEnglishAlphabet - 1));
                            wordEnglish.Append(line.Substring(indexEnglishAlphabet));
                            wordEnglish = wordEnglish.Replace("'", "''");

                            if (wordEnglish.Length > lineMaximumEnglish)
                            {
                                lineMaximumEnglish = lineLength;
                            }

                            /*
                             * wordEnglish   = new StringBuilder();
                             * wordKorean    = new StringBuilder();
                             * wordTranslate = false;
                             *
                             * for ( linePosition = 0; linePosition < lineLength; ++linePosition )
                             * {
                             * charCurrent = line.Substring( linePosition, 1 );
                             *
                             * if ( KoreanConsonant.Contains( line.Substring( linePosition, 2 ) )
                             * {
                             ++linePosition;
                             * }
                             *
                             * unicodeCategoryCurrent = Char.GetUnicodeCategory(line, linePosition);
                             *
                             * switch ( unicodeCategoryCurrent )
                             * {
                             * case UnicodeCategory.DecimalDigitNumber:
                             * wordTranslate = true;
                             * break;
                             *
                             * case UnicodeCategory.LowercaseLetter:
                             * wordTranslate = true;
                             * break;
                             *
                             * case UnicodeCategory.UppercaseLetter:
                             * wordTranslate = true;
                             * break;
                             * }
                             *
                             * if ( wordTranslate == false )
                             * {
                             * wordKorean.Append( charCurrent );
                             * }
                             * else
                             * {
                             * wordEnglish.Append( charCurrent );
                             * }
                             *
                             * }//for ( linePosition = 0; linePosition < lineLength; ++linePosition )
                             */

                            if (wordKorean.Length == 0 || wordEnglish.Length == 0)
                            {
                                continue;
                            }

                            ++sequenceOrderId;

       #if (DEBUG)
                            System.Console.WriteLine
                            (
                                "SequenceOrderId: {0} | Korean: {1} | English: {2}",
                                sequenceOrderId,
                                wordKorean,
                                wordEnglish
                            );
       #endif

                            SQLStatement = new StringBuilder();
                            SQLStatement.AppendFormat
                            (
                                SQLStatementDictionaryInsert,
                                sequenceOrderId,
                                wordKorean,
                                wordEnglish
                            );

                            /*
                             #if (DEBUG)
                             * System.Console.WriteLine("SQL Statement: {0}", SQLStatement.ToString() );
                             #endif
                             */

                            UtilityDatabase.DatabaseNonQuery
                            (
                                oleDbConnection,
                                ref exceptionMessage,
                                SQLStatement.ToString()
                            );
                        } //while ((line = sr.ReadLine()) != null)
                    }     //using (StreamReader sr = new StreamReader("TestFile.txt"))
                }         //try
                catch (Exception e)
                {
                    System.Console.WriteLine
                    (
                        "Line #:{0} | Line: {1} | Exception: {2}",
                        lineNumber,
                        line,
                        e.Message
                    );
                } //catch (Exception e)
            }     //while ( enumeratorFilename.MoveNext() )

            UtilityDatabase.DatabaseConnectionHouseKeeping
            (
                oleDbConnection,
                ref exceptionMessage
            );

   #if (DEBUG)
            System.Console.WriteLine
            (
                "Line Maximum: {0}",
                lineMaximumEnglish
            );
   #endif
        }//DictionaryTextFile()
Example #4
0
        }//main()

        /// <summary>The dictionary text file.</summary>
        /// <param name="directorynameSource">The directory name, source, for example, ..\\ProjectGutenberg.</param>
        /// <param name="fileSearchPattern">The file search pattern, for example. *.txt.</param>
        public static void DictionaryTextFile
        (
            string directorynameSource,
            string fileSearchPattern
        )
        {
            Boolean dictionaryBeginFlag = false;
            Boolean dictionaryEndFlag   = false;

            int dictionaryId = 0;
            int indexDigit   = -1;
            int referenceId  = -1;
            int thesaurusId  = -1;

            double referenceDouble = 0;

            object commandReturn = null;

            string dictionaryWord     = null;
            string exceptionMessage   = null;
            string filenameDictionary = null;
            string referenceWord      = null;

            string[] thesaurusWord            = null;
            string   thesaurusWordCombination = null;
            string   thesaurusWordCurrentTrim = null;

            StringBuilder sbDictionary           = null;
            StringBuilder SQLStatement           = null;
            ArrayList     arrayListDirectoryname = null;
            ArrayList     arrayListFilename      = null;

            System.Collections.IEnumerator enumeratorFilename = null;

            OleDbConnection oleDbConnection = null;

            oleDbConnection = UtilityDatabase.DatabaseConnectionInitialize
                              (
                DatabaseConnectionString,
                ref exceptionMessage
                              );

            UtilityDatabase.DatabaseNonQuery
            (
                oleDbConnection,
                ref exceptionMessage,
                SQLStatementDictionaryTruncate
            );

            UtilityDirectory.Dir
            (
                ref DirectorynameSource,
                ref fileSearchPattern,
                ref arrayListDirectoryname,
                ref arrayListFilename
            );//UtilityDirectory.Dir

            enumeratorFilename = arrayListFilename.GetEnumerator();

            while (enumeratorFilename.MoveNext())
            {
                filenameDictionary = (string)enumeratorFilename.Current;
                System.Console.WriteLine("{0}", filenameDictionary);
                sbDictionary = new StringBuilder();

                try
                {
                    // Create an instance of StreamReader to read from a file.
                    // The using statement also closes the StreamReader.
                    using (StreamReader sr = new StreamReader(filenameDictionary))
                    {
                        String line;
                        // Read and display lines from the file until the end of
                        // the file is reached.
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line.Trim().Length == 0)
                            {
                                continue;
                            }
                            if (dictionaryBeginFlag == false)
                            {
                                if (String.Compare(line.Trim(), DictionaryBegin) == 0)
                                {
                                    dictionaryBeginFlag = true;
                                }
                                continue;
                            }
                            else if (dictionaryBeginFlag == true && String.Compare(line.Trim(), DictionaryEnd) == 0)
                            {
                                dictionaryEndFlag = true;
                                break;
                            }
                            if (line[0] != ' ')
                            {
                                dictionaryWord = line.Trim();
                                dictionaryWord = dictionaryWord.Replace("'", "''");
                                SQLStatement   = new StringBuilder();
                                SQLStatement.AppendFormat
                                (
                                    SQLStatementDictionaryInsertWord,
                                    dictionaryWord
                                );
        #if (DEBUG)
                                System.Console.WriteLine("SQL Statement: {0}", SQLStatement.ToString());
        #endif
                                commandReturn = UtilityDatabase.DatabaseQuery
                                                (
                                    oleDbConnection,
                                    ref exceptionMessage,
                                    SQLStatement.ToString(),
                                    CommandType.Text
                                                );
                                if (commandReturn == DBNull.Value)
                                {
                                    dictionaryId = -1;
                                }//if ( commandReturn == DBNull.Value )
                                else
                                {
                                    dictionaryId = System.Convert.ToInt32(commandReturn);
                                } //else if ( commandReturn != DBNull.Value )
                            }     //if ( line[0] != ' ' )
                            else
                            {
                                line       = line.Trim();
                                indexDigit = line.IndexOfAny(DigitsAnyOf);
                                if (indexDigit < 0)
                                {
                                    continue;
                                }
                                referenceWord   = line.Substring(indexDigit);
                                referenceDouble = System.Convert.ToDouble(referenceWord);
                                referenceId     = System.Convert.ToInt32(referenceDouble);

                                thesaurusWordCombination = line.Substring(0, indexDigit - 1);
                                thesaurusWordCombination = thesaurusWordCombination.Trim();
                                thesaurusWord            = thesaurusWordCombination.Split(ThesaurusCombinationDelimiterArray);
                                foreach (String thesaurusWordCurrent in thesaurusWord)
                                {
                                    thesaurusWordCurrentTrim = thesaurusWordCurrent.Trim();
                                    SQLStatement             = new StringBuilder();
                                    SQLStatement.AppendFormat
                                    (
                                        SQLStatementDictionaryInsertWord,
                                        thesaurusWordCurrent.Trim()
                                    );
         #if (DEBUG)
                                    System.Console.WriteLine("SQL Statement: {0}", SQLStatement.ToString());
         #endif

                                    commandReturn = UtilityDatabase.DatabaseQuery
                                                    (
                                        oleDbConnection,
                                        ref exceptionMessage,
                                        SQLStatement.ToString(),
                                        CommandType.Text
                                                    );

                                    if (commandReturn == DBNull.Value)
                                    {
                                        thesaurusId = -1;
                                    }//if ( commandReturn == DBNull.Value )
                                    else
                                    {
                                        thesaurusId = System.Convert.ToInt32(commandReturn);
                                    }//else if ( commandReturn != DBNull.Value )

                                    SQLStatement = new StringBuilder();
                                    SQLStatement.AppendFormat
                                    (
                                        SQLStatementDictionaryInsertReference,
                                        dictionaryId,
                                        thesaurusId,
                                        referenceId
                                    );
         #if (DEBUG)
                                    System.Console.WriteLine("SQL Statement: {0}", SQLStatement.ToString());
         #endif
                                    UtilityDatabase.DatabaseNonQuery
                                    (
                                        oleDbConnection,
                                        ref exceptionMessage,
                                        SQLStatement.ToString()
                                    );
                                } //foreach ( String thesaurusWordCurrent in thesaurusWord )
                            }     //else
                        }         //while ((line = sr.ReadLine()) != null)
                    }             //using (StreamReader sr = new StreamReader("filenameDictionary"))
                }                 //try
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                } //catch (Exception e)
            }     //while ( enumeratorFilename.MoveNext() )

            UtilityDatabase.DatabaseConnectionHouseKeeping
            (
                oleDbConnection,
                ref exceptionMessage
            );
        }//DictionaryTextFile()
Example #5
0
        }//main()

        ///<summary>Stub.</summary>
        public static void FileImport
        (
            ref String databaseConnectionString,
            ref InternetDictionaryProjectIDPArgument internetDictionaryProjectIDPArgument,
            ref String exceptionMessage
        )
        {
            bool[] databaseTruncate = null;

            int dataFileIndex = 0;

            int dictionaryCommentaryIndex     = -1;
            int dictionaryLanguageIndex       = -1;
            int dictionaryLanguageIndexFirst  = -1;
            int dictionaryLanguageIndexSecond = -1;

            int dictionaryLanguageIndexPosition       = -1;
            int dictionaryLanguageIndexPositionFirst  = -1;
            int dictionaryLanguageIndexPositionSecond = -1;

            String databaseStatementUpdate   = null;
            String databaseStatementTruncate = null;

            String dictionaryWord       = null;
            String dictionaryCommentary = null;

            String directoryNameRoot = null;
            String fileNameCurrent   = null;
            String fileNamePattern   = null;
            String streamRecord      = null;

            ArrayList arrayListDirectoryName = null;
            ArrayList arrayListFileName      = null;

            OleDbConnection oleDbConnection = null;

            databaseTruncate = new bool[DictionaryLanguage.Length];

            oleDbConnection = UtilityDatabase.DatabaseConnectionInitialize
                              (
                databaseConnectionString,
                ref exceptionMessage
                              );

            try
            {
                for (dataFileIndex = 0; dataFileIndex < internetDictionaryProjectIDPArgument.dataFile.Length; ++dataFileIndex)
                {
                    UtilityDirectory.Dir
                    (
                        ref internetDictionaryProjectIDPArgument.dataFile[dataFileIndex],
                        ref directoryNameRoot,
                        ref fileNamePattern,
                        ref arrayListDirectoryName,
                        ref arrayListFileName
                    );

                    foreach (object fileNameObject in arrayListFileName)
                    {
                        fileNameCurrent = fileNameObject.ToString();

                        dictionaryLanguageIndexFirst         = -1;
                        dictionaryLanguageIndexPositionFirst = 0;

                        dictionaryLanguageIndexSecond         = -1;
                        dictionaryLanguageIndexPositionSecond = 0;

                        for (dictionaryLanguageIndex = 0; dictionaryLanguageIndex < DictionaryLanguage.Length; ++dictionaryLanguageIndex)
                        {
                            dictionaryLanguageIndexPosition = fileNameCurrent.IndexOf(DictionaryLanguage[dictionaryLanguageIndex]);

                            if (dictionaryLanguageIndexPosition < 0)
                            {
                                continue;
                            }//if ( dictionaryLanguageIndexPosition < 0 )
                            else if (dictionaryLanguageIndexFirst <= -1)
                            {
                                dictionaryLanguageIndexPositionFirst = dictionaryLanguageIndexPosition;
                                dictionaryLanguageIndexFirst         = dictionaryLanguageIndex;
                            }//else if ( dictionaryLanguageIndexFirst <= -1 )
                            else if (dictionaryLanguageIndexPosition < dictionaryLanguageIndexPositionFirst)
                            {
                                dictionaryLanguageIndexPositionSecond = dictionaryLanguageIndexPositionFirst;
                                dictionaryLanguageIndexPositionFirst  = dictionaryLanguageIndexPosition;

                                dictionaryLanguageIndexSecond = dictionaryLanguageIndexFirst;
                                dictionaryLanguageIndexFirst  = dictionaryLanguageIndex;
                            }//else if ( dictionaryLanguageIndexPositionFirst < 0 )
                            else
                            {
                                dictionaryLanguageIndexPositionSecond = dictionaryLanguageIndexPosition;
                                dictionaryLanguageIndexSecond         = dictionaryLanguageIndex;
                            } //else
                        }     //for ( dictionaryLanguageIndex = 0; dictionaryLanguageIndex <= DictionaryLanguage.Length; ++dictionaryLanguageIndex )

                        /*
                         * UtilityDebug.Write
                         * (
                         * String.Format
                         * (
                         * "Language First: {0} | Second: {1} | First Position: {2} | Second Position: {3}",
                         * DictionaryLanguage[dictionaryLanguageIndexFirst],
                         * DictionaryLanguage[dictionaryLanguageIndexSecond],
                         * dictionaryLanguageIndexPositionFirst,
                         * dictionaryLanguageIndexPositionSecond
                         * )
                         * );
                         */

                        if (internetDictionaryProjectIDPArgument.TableTruncate && databaseTruncate[dictionaryLanguageIndexFirst] == false)
                        {
                            databaseTruncate[dictionaryLanguageIndexFirst] = true;

                            databaseStatementTruncate = String.Format
                                                        (
                                SQLStatementDictionaryTruncate,
                                DictionaryLanguage[dictionaryLanguageIndexFirst] + "Dictionary"
                                                        );

                            UtilityDebug.Write(databaseStatementTruncate);

                            UtilityDatabase.DatabaseNonQuery
                            (
                                oleDbConnection,
                                ref exceptionMessage,
                                databaseStatementTruncate
                            );
                        }
                        ;//if ( internetDictionaryProjectIDPArgument.TableTruncate )

                        // Create an instance of StreamReader to read from a file.
                        // The using statement also closes the StreamReader.
                        using (StreamReader streamReader = new StreamReader(fileNameCurrent))
                        {
                            while (true)
                            {
                                //Read and display lines from the file until the end of the file is reached.
                                streamRecord = streamReader.ReadLine();

                                if (streamRecord == null)
                                {
                                    break;
                                }//if ( streamRecord == null )

                                UtilityDebug.Write
                                (
                                    String.Format
                                    (
                                        "streamRecord: {0}",
                                        streamRecord
                                    )
                                );

                                if (streamRecord[0] == '#')
                                {
                                    continue;
                                }//if ( streamRecord[0] == '#' )

                                dictionaryCommentaryIndex = streamRecord.IndexOf('\t');

                                if (dictionaryCommentaryIndex <= -1)
                                {
                                    continue;
                                }//if ( dictionaryCommentaryIndex <= -1 )

                                dictionaryWord       = streamRecord.Substring(0, dictionaryCommentaryIndex);
                                dictionaryCommentary = (streamRecord.Substring(dictionaryCommentaryIndex)).Trim();

                                databaseStatementUpdate = String.Format
                                                          (
                                    SQLStatementDictionaryUpdate,
                                    DictionaryLanguage[dictionaryLanguageIndexFirst] + "Word",
                                    DictionaryLanguage[dictionaryLanguageIndexFirst] + "Dictionary",
                                    dictionaryWord,
                                    DictionaryLanguage[dictionaryLanguageIndexSecond] + "Commentary",
                                    dictionaryCommentary
                                                          );

                                UtilityDebug.Write(databaseStatementUpdate);

                                UtilityDatabase.DatabaseNonQuery
                                (
                                    oleDbConnection,
                                    ref exceptionMessage,
                                    databaseStatementUpdate
                                );
                            } //while ( true )
                        }     //using (StreamReader streamReader = new StreamReader(fileNameCurrent))
                    }         //foreach ( object fileNameCurrent in arrayListFileName )
                }             //for ( dataFileIndex = 0; dataFileIndex < internetDictionaryProjectIDPArgument.dataFile.Length; ++dataFileIndex )
            }                 //try
            catch (Exception exception)
            {
                UtilityDebug.Write
                (
                    String.Format
                    (
                        "Exception: {0}",
                        exception.Message
                    )
                );
            }//catch ( Exception exception )

            UtilityDatabase.DatabaseConnectionHouseKeeping
            (
                oleDbConnection,
                ref exceptionMessage
            );
        }//public static void FileImport()
        }//main()

        /// <summary>The dictionary text file.</summary>
        /// <param name="directorynameSource">The directory name, source, for example, ..\\ProjectGutenberg.</param>
        /// <param name="fileSearchPattern">The file search pattern, for example. *.txt.</param>
        public static void DictionaryTextFile
        (
            string directorynameSource,
            string fileSearchPattern
        )
        {
            int indexEntryStart    = -1;
            int indexEntryEnd      = -1;
            int indexParagraphPage = -1;
            int indexPoint26       = -1;
            int indexWordEnd       = -1;

            string filenameDictionary = null;
            string dictionaryFile     = null;
            string exceptionMessage   = null;
            string indexEntry         = null;
            string indexWord          = null;

            StringBuilder sbDictionary           = null;
            StringBuilder SQLStatement           = null;
            ArrayList     arrayListDirectoryname = null;
            ArrayList     arrayListFilename      = null;

            System.Collections.IEnumerator enumeratorFilename = null;

            OleDbConnection oleDbConnection = null;

            oleDbConnection = UtilityDatabase.DatabaseConnectionInitialize
                              (
                DatabaseConnectionString,
                ref exceptionMessage
                              );

            UtilityDatabase.DatabaseNonQuery
            (
                oleDbConnection,
                ref exceptionMessage,
                SQLStatementDictionaryTruncate
            );

            UtilityDirectory.Dir
            (
                ref DirectorynameSource,
                ref fileSearchPattern,
                ref arrayListDirectoryname,
                ref arrayListFilename
            );//UtilityDirectory.Dir

            enumeratorFilename = arrayListFilename.GetEnumerator();

            while (enumeratorFilename.MoveNext())
            {
                filenameDictionary = (string)enumeratorFilename.Current;
                System.Console.WriteLine("{0}", filenameDictionary);
                sbDictionary = new StringBuilder();

                try
                {
                    // Create an instance of StreamReader to read from a file.
                    // The using statement also closes the StreamReader.
                    using (StreamReader sr = new StreamReader(filenameDictionary))
                    {
                        String line;
                        // Read and display lines from the file until the end of
                        // the file is reached.
                        while ((line = sr.ReadLine()) != null)
                        {
                            sbDictionary.Append(line);
                            //System.Console.WriteLine(line);
                        } //while ((line = sr.ReadLine()) != null)
                    }     //using (StreamReader sr = new StreamReader("TestFile.txt"))

                    dictionaryFile = sbDictionary.ToString();
                    indexPoint26   = dictionaryFile.IndexOf(ParagraphPoint26);
     #if (DEBUG)
                    System.Console.WriteLine("ParagraphPoint26: {0}", indexPoint26);
     #endif

                    indexEntryStart = dictionaryFile.IndexOf(ParagraphHW, indexPoint26);

                    while (indexEntryStart > 0)
                    {
                        indexEntryEnd = dictionaryFile.IndexOf(ParagraphHW, indexEntryStart + 1);

                        if (indexEntryEnd > 0)
                        {
                            indexEntry = dictionaryFile.Substring(indexEntryStart, indexEntryEnd - indexEntryStart);
                        }
                        else
                        {
                            indexEntry         = dictionaryFile.Substring(indexEntryStart);
                            indexParagraphPage = indexEntry.LastIndexOf(ParagraphPage);
                            if (indexParagraphPage >= 0)
                            {
                                indexEntry = indexEntry.Substring(indexEntry.Length - indexParagraphPage);
                            }
                            break;
                        }//if ( indexEntryEnd <= 0 )

                        indexWordEnd = indexEntry.IndexOf(AnchorEndHW);
                        if (indexWordEnd < 0)
                        {
                            indexEntryStart = indexEntryEnd;
                            continue;
                        }
                        indexWord = indexEntry.Substring(IndexHWWordStart, indexWordEnd - IndexHWWordStart);
                        for (int indexReplace = 0; indexReplace < DictionaryWordReplace.Length; ++indexReplace)
                        {
                            indexWord = indexWord.Replace
                                        (
                                DictionaryWordReplace[indexReplace][0],
                                DictionaryWordReplace[indexReplace][1]
                                        );
                            indexEntry = indexEntry.Replace
                                         (
                                DictionaryWordReplace[indexReplace][0],
                                DictionaryWordReplace[indexReplace][1]
                                         );
                        }

      #if (DEBUG)
                        System.Console.WriteLine
                        (
                            "Index Entry Start: {0} | End: {1} | Word: {2} | Entry: {3}",
                            indexEntryStart,
                            indexEntryEnd,
                            indexWord,
                            indexEntry
                        );
      #endif

                        SQLStatement = new StringBuilder();
                        SQLStatement.AppendFormat
                        (
                            SQLStatementDictionaryInsert,
                            indexWord,
                            indexEntry
                        );

      #if (DEBUG)
                        System.Console.WriteLine("SQL Statement: {0}", SQLStatement.ToString());
      #endif

                        UtilityDatabase.DatabaseNonQuery
                        (
                            oleDbConnection,
                            ref exceptionMessage,
                            SQLStatement.ToString()
                        );

                        indexEntryStart = indexEntryEnd;
                    } //while ( indexEntryStart > 0 )
                }     //try
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                }
            }//while ( enumeratorFilename.MoveNext() )

            UtilityDatabase.DatabaseConnectionHouseKeeping
            (
                oleDbConnection,
                ref exceptionMessage
            );
        }//DictionaryTextFile()