public static Double ACosineSimilarity(string query, AQUESTION Question) { var QueryTerms = query.ArabicTokenize(); List <String> superset = new List <string>(); foreach (var term in QueryTerms) { superset.Add(term.Key); } foreach (AQUESTIONTERM QT in Question.AQUESTIONTERMs) { string temp = QT.ATERM.VALUE; if (!superset.Contains(temp)) { superset.Add(temp); } } // normalize documents into term vectors for comparison var vectorOne = CreateQueryFrequencyVector(superset, QueryTerms); var vectorTwo = CreateAQuestionFrequencyVector(superset, Question); // calculate the dot product of the two vectors ((V1[0] * V2[0]) + (V1[1] * V2[1]) ... + (V1[n] * V2[n])) var dotProduct = DotProduct(vectorOne, vectorTwo); // calculate the product of the vector magnatudes (Sqrt(Sum(V1) * Sum(V2))) var productOfMagnitudes = ProductOfMagnitudes(vectorOne, vectorTwo); // return dot product normalized by the product of magnatudes return(dotProduct / productOfMagnitudes); }
public ActionResult DeleteConfirmed(Guid id) { AQUESTION aQUESTION = db.AQUESTIONs.Find(id); db.AQUESTIONs.Remove(aQUESTION); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,VALUE,ANSWER,Indexed")] AQUESTION aQUESTION) { if (ModelState.IsValid) { aQUESTION.Indexed = 0; db.Entry(aQUESTION).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aQUESTION)); }
public ActionResult Create([Bind(Include = "ID,VALUE,ANSWER,Indexed")] AQUESTION aQUESTION) { if (ModelState.IsValid) { aQUESTION.ID = Guid.NewGuid(); aQUESTION.Indexed = 0; db.AQUESTIONs.Add(aQUESTION); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aQUESTION)); }
// GET: AQUESTIONs/Delete/5 public ActionResult Delete(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AQUESTION aQUESTION = db.AQUESTIONs.Find(id); if (aQUESTION == null) { return(HttpNotFound()); } return(View(aQUESTION)); }
public static Double[] CreateAQuestionFrequencyVector(List <string> superset, AQUESTION Question) { Dictionary <string, Double> keyset = new Dictionary <string, Double>(); foreach (var key in superset) { keyset.Add(key, 0); } foreach (AQUESTIONTERM QT in Question.AQUESTIONTERMs) { keyset[QT.ATERM.VALUE] = Convert.ToDouble(QT.WEIGHT); } return(keyset.Values.ToArray()); }