public static void BlockSentimentToDb(SqlConnection connection, long docId, short blockNum, int positives, int negatives, int noTokens) { using (SqlCommand cmd = new SqlCommand(null, connection)) { cmd.CommandTimeout = 300; cmd.CommandText = ClBlockSentiment; double polarity = 1.0 * (positives - negatives) / (positives + negatives); // Console.WriteLine("\n -------------------"+entityUri); cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@document_id", docId); cmd.Parameters.AddWithValue("@block_id", blockNum); cmd.Parameters.AddWithValue("@positives", positives); cmd.Parameters.AddWithValue("@negatives", negatives); cmd.Parameters.AddWithValue("@polarity", polarity); cmd.Parameters.AddWithValue("@tokens", noTokens); try { cmd.ExecuteNonQueryRetryOnDeadlock(); //Execute the command } catch (Exception ex) { string errorMessage = String.Format("\nError inserting block sentiment: \n\t\t DocumentId:{0} \n\t\t BlockNum{1}", docId, blockNum); throw new Exception(ex + errorMessage); } } }
/// <summary> /// Inserts the data about the actual term (string) from teh document /// </summary> public static void TermToDb(SqlConnection connection, long occurrenceId, string term) { using (SqlCommand cmd = new SqlCommand(null, connection)) { cmd.CommandTimeout = 300; cmd.CommandText = ClTerm; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@occurrence_id", occurrenceId); cmd.Parameters.AddWithValue("@term", Shorten(term, 400)); try { cmd.ExecuteNonQueryRetryOnDeadlock(); //Execute the command } catch (Exception) { Console.WriteLine("\nTerm insert exception : occurrence_id \t" + occurrenceId + " \t" + term); } } }
public static void SentenceSentimentToDb(SqlConnection connection, long docId, short blockNum, short sentenceNum, int positives, int negatives, int noTokens) { using (SqlCommand cmd = new SqlCommand(null, connection)) { cmd.CommandTimeout = 300; cmd.CommandText = ClSentenceSentiment; double polarity = 1.0 * (positives - negatives) / (positives + negatives); // Console.WriteLine("\n -------------------"+entityUri); cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@document_id", docId); cmd.Parameters.AddWithValue("@block_id", blockNum); cmd.Parameters.AddWithValue("@sentence_id", sentenceNum); cmd.Parameters.AddWithValue("@positives", positives); cmd.Parameters.AddWithValue("@negatives", negatives); cmd.Parameters.AddWithValue("@polarity", polarity); cmd.Parameters.AddWithValue("@tokens", noTokens); cmd.ExecuteNonQueryRetryOnDeadlock(); //Execute the command } }