示例#1
0
        public static Double ECosineSimilarity(string query, EQUESTION Question)
        {
            var QueryTerms = query.EnglishTokenize();

            List <String> superset = new List <string>();

            foreach (var term in QueryTerms)
            {
                superset.Add(term.Key);
            }

            foreach (EQUESTIONTERM QT in Question.EQUESTIONTERMs)
            {
                string temp = QT.ETERM.VALUE;

                if (!superset.Contains(temp))
                {
                    superset.Add(temp);
                }
            }

            // normalize documents into term vectors for comparison
            var vectorOne = CreateQueryFrequencyVector(superset, QueryTerms);
            var vectorTwo = CreateEQuestionFrequencyVector(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)
        {
            EQUESTION eQUESTION = db.EQUESTIONs.Find(id);

            db.EQUESTIONs.Remove(eQUESTION);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ID,VALUE,ANSWER,Indexed")] EQUESTION eQUESTION)
 {
     if (ModelState.IsValid)
     {
         eQUESTION.Indexed         = 0;
         db.Entry(eQUESTION).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(eQUESTION));
 }
        public ActionResult Create([Bind(Include = "ID,VALUE,ANSWER,Indexed")] EQUESTION eQUESTION)
        {
            if (ModelState.IsValid)
            {
                eQUESTION.ID      = Guid.NewGuid();
                eQUESTION.Indexed = 0;
                db.EQUESTIONs.Add(eQUESTION);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(eQUESTION));
        }
        // GET: EQUESTIONs/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EQUESTION eQUESTION = db.EQUESTIONs.Find(id);

            if (eQUESTION == null)
            {
                return(HttpNotFound());
            }
            return(View(eQUESTION));
        }
示例#6
0
        public static Double[] CreateEQuestionFrequencyVector(List <string> superset, EQUESTION Question)
        {
            Dictionary <string, Double> keyset = new Dictionary <string, Double>();

            foreach (var key in superset)
            {
                keyset.Add(key, 0);
            }

            foreach (EQUESTIONTERM QT in Question.EQUESTIONTERMs)
            {
                keyset[QT.ETERM.VALUE] = Convert.ToDouble(QT.WEIGHT);
            }

            return(keyset.Values.ToArray());
        }