Here is my code...which gives a sorted (descending) list of cosine similarity values of different queries with a document.
var dd = new List<Tuple<string, double, string>>();
while ((line = file.ReadLine()) != null)
{
dd.Add(Tuple.Create(line, p.calculate_CS(line, document), document));
}
var top_value = dd.OrderByDescending(x => x.Item2).FirstOrDefault();
if (top_value != null)
{
// look up record using top_value.Item3, and then store top_value.Item1
var abstrct = top_value.Item3.ToString();
var r_field = top_value.Item1.ToString();
write_To_Database(abstrct, r_field);
}
This is the data insertion method......
static void write_To_Database(string document, string research_field)
{
try
{
SqlConnection con = new SqlConnection("Data Source=KHIZER;Initial Catalog=subset_aminer;Integrated Security=True;");
con.Open();
SqlCommand query = con.CreateCommand();
query.CommandText = "select id from sub_aminer_paper where pid between 1 and 500 and DATALENGTH(p_abstract) != 0 and p_abstract = " + document;
SqlDataReader reader = query.ExecuteReader();
reader.Read();
int id = reader.GetInt32(0);
//reader.Close();
query.Parameters.Add("@research_field", SqlDbType.Text);
query.Parameters.Add("@id", SqlDbType.Int);
query.CommandText = "insert into sub_aminer_paper (research_area) values(@research_field) where id = @id";
query.ExecuteNonQuery();
con.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
finally
{
Console.WriteLine("Executing finally block.");
}
}
I want to store the value of top (highest cosine similarity value) query in database against the string document
which is taken from the same table...
Table structure is as follows...
--------------------------------------------------------------------------------
id | pid | p_title | p_author | p_year | p_venue | p_abstract | research_area
--------------------------------------------------------------------------------
string document is p_abstract
and query is to be saved in the column research_area
Any suggestions will be highly appreciated.