Ejemplo n.º 1
0
 public static void RunSentimentAnalysis(int RequestLimit)
 {
     using (var conn = new SqlCeConnection(_sqlConnection))
     {
         var sql = "SELECT * FROM Tweets WHERE Language = 'English' AND Positive IS NULL";
         conn.Open();
         using (var reader = new SqlCeCommand(sql, conn).ExecuteReader())
         {
             var text         = new List <Tuple <long, string> >();
             var batchCount   = 0;
             var requestCount = 0;
             while (reader.Read())
             {
                 text.Add(new Tuple <long, string>(long.Parse(reader["TweetId"].ToString()), reader["Text"].ToString()));
                 batchCount++;
                 if (batchCount == _limit)
                 {
                     SentimentAnalysisBatch(text, conn);
                     batchCount = 0;
                     text.Clear();
                     requestCount++;
                     if (requestCount == RequestLimit)
                     {
                         break;
                     }
                 }
             }
             if (text.Count() > 0)
             {
                 SentimentAnalysisBatch(text, conn);
             }
         }
     }
 }
Ejemplo n.º 2
0
 private static void Main(string[] args)
 {
     string fileName;
     if (args.Length > 0) fileName = args[0];
     else
     {
         Console.WriteLine("You need to specify the path to the sdf file as a command-line argument!!");
         return;
     }
     using (var connection = new SqlCeConnection(string.Format("Data Source={0}", fileName)))
     {
         connection.Open();
         while (true)
         {
             Console.WriteLine("What?");
             string commandText = Console.ReadLine().Trim();
             if (commandText.Equals("exit") || commandText.Equals("quit")) return;
             try
             {
                 if (!commandText.ToLower().StartsWith("select"))
                 {
                     int count = new SqlCeCommand(commandText, connection).ExecuteNonQuery();
                     Console.WriteLine("Number of rows affected:\t{0}", count);
                     continue;
                 }
                 SqlCeDataReader reader = new SqlCeCommand(commandText, connection).ExecuteReader();
                 int columnCount;
                 for (int i = 0;; i++)
                 {
                     try
                     {
                         Console.Write("{0}\t", reader.GetName(i));
                     }
                     catch
                     {
                         columnCount = i;
                         break;
                     }
                 }
                 Console.WriteLine();
                 while (reader.Read())
                 {
                     for (int i = 0; i < columnCount; i++)
                     {
                         Console.Write("{0}\t", reader.GetValue(i));
                     }
                     Console.WriteLine();
                 }
             }
             catch (Exception e)
             {
                 Console.WriteLine("There was an error!!! What did you do?");
                 Console.WriteLine("The error details are:");
                 Console.WriteLine(e);
                 Console.WriteLine("Let's try to not repeat it shall we!!");
             }
         }
     }
 }
Ejemplo n.º 3
0
        private void lbResults_DoubleClick(object sender, EventArgs e)
        {
            // Show the bible verse
            if (lbResults.SelectedIndex >= 0)
            {
                string value    = lbResults.SelectedItem.ToString();
                int    keyIndex = value.IndexOf("Key: ") + 4;
                string key      = value.Substring(keyIndex, value.IndexOf('\t', keyIndex) - keyIndex).Trim(';').Trim();
                int    verseId  = int.Parse(key);

                // Get the verse
                string sql   = "SELECT v.*, b.* FROM Verse v INNER JOIN Book b ON v.BookID = b.BookID WHERE VerseID = " + verseId;
                string verse = string.Empty;
                using (SqlCeConnection conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {
                    conn.Open();
                    SqlCeDataReader rdr = new SqlCeCommand(sql, conn).ExecuteReader();
                    rdr.Read();
                    verse = string.Format("{0} {1}:{2} - {3}", rdr["BookName"], rdr["BookNum"], rdr["VerseNum"], rdr["VerseText"]);
                    rdr.Close();
                }
                MessageBox.Show(verse);
            }
        }
Ejemplo n.º 4
0
        private void lbResults_DoubleClick(object sender, EventArgs e)
        {
            // Show the bible verse
            if (lbResults.SelectedIndex >= 0)
            {
                string value = lbResults.SelectedItem.ToString();
                int keyIndex = value.IndexOf("Key: ") + 4;
                string key = value.Substring(keyIndex, value.IndexOf('\t', keyIndex) - keyIndex).Trim(';').Trim();
                int verseId = int.Parse(key);

                // Get the verse
                string sql = "SELECT v.*, b.* FROM Verse v INNER JOIN Book b ON v.BookID = b.BookID WHERE VerseID = " + verseId;
                string verse = string.Empty;
                using (SqlCeConnection conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {
                    conn.Open();
                    SqlCeDataReader rdr = new SqlCeCommand(sql, conn).ExecuteReader();
                    rdr.Read();
                    verse = string.Format("{0} {1}:{2} - {3}", rdr["BookName"], rdr["BookNum"], rdr["VerseNum"], rdr["VerseText"]);
                    rdr.Close();
                }
                MessageBox.Show(verse);
            }
        }