コード例 #1
0
        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);
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            AQUESTION aQUESTION = db.AQUESTIONs.Find(id);

            db.AQUESTIONs.Remove(aQUESTION);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
 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));
 }
コード例 #4
0
        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));
        }
コード例 #5
0
        // 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));
        }
コード例 #6
0
        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());
        }