Esempio n. 1
0
    protected void btnProcess_Click(object sender, EventArgs e)
    {
        assignmentReturn ar = new assignmentReturn();
        LinkedList<Paper> pa = new LinkedList<Paper>();
        pa = ar.getAssignmentList();

        int x = test.run();
        LinkedList<Report> rep = test.Reports;

        LinkedListNode<Report> rp = rep.First;
        txtOut.Text = "";
        while (rp != null)
        {
            String o = rp.Value.ToString();
            String[] f = o.Split('|');
            TableRow r = new TableRow();

            foreach (String n in f)
            {

                TableCell c = new TableCell();
                c.Controls.Add(new LiteralControl(n));
                r.Cells.Add(c);

            }
            tblOut.Rows.Add(r);

            rp = rp.Next;
        }
    }
Esempio n. 2
0
        public int run()
        {
            //int changed = 0;
            //inRestults= getdata(aID);
            // Create a temp linked list
            type = 1;
            //string c;
            //LinkedList<string> input = new LinkedList<string>();
            //c = "this is a test";
            //input.AddFirst(c);
            //c = "this is a test";
            //input.AddFirst(c);
            //c = "this is a test";
            //input.AddFirst(c);
            //Paper x = new Paper();
            //x.Data = input;
            //x.AID = "2";
            //x.Link = "this is a test link";
            //x.UserID = "TestUser";
            //LinkedList<Paper> retrived = new LinkedList<Paper>();
            //retrived.AddLast(x);
            assignmentReturn ar = new assignmentReturn();
            LinkedList<Paper> retrived = ar.getAssignmentList();
            LinkedList<Report> output = new LinkedList<Report>();

            //LinkedList<Report> oResults=new LinkedList<Report>();

            switch (type)
            {
                case 1://wc
                    // for each item inRestults
                    LinkedListNode<Paper> currentPaper = retrived.First;

                    while (currentPaper != null)
                    {
                        this.tested++;
                        Report currentReport = new Report(currentPaper.Value);
                        currentReport.TypeID = 1;
                        currentReport.TestID = wc.count(currentPaper.Value.Data);
                        reports.AddLast(currentReport);
                        currentPaper = currentPaper.Next;
                    }

                    break;
                case 2://keywc
                    // for each item inRestults
                    //String data = kwc.count(item.LL_String);
                    //data.split(:);
                    //report=new report (item.assignid,item.userid,type,data.uuid,item.link
                    //sqlinsert(keywctable(data))
                    //OResults.add(report);

                    break;
                case 3://n-word
                    break;
                case 4://phrased n-word
                    break;
                default:
                    return -1;
            }
            // put results into results tables
            // changed = sqlinsert(oresults); // number of rows added to the tables

            return this.tested;
        }
Esempio n. 3
0
        public int run(string aGUID)
        {
            assignmentReturn ar = new assignmentReturn();
            LinkedList<Paper> retrived;
            if (aGUID != null)
            {
                retrived = ar.getAssignmentList(aGUID);
            }
            else
            {
                retrived = ar.getAssignmentList();
            }
            LinkedList<Report> output = new LinkedList<Report>();

            LinkedListNode<Paper> currentPaper = retrived.First;
            switch (type)
            {
                case 1://wc
                    // for each item inRestults

                    Parallel.ForEach(retrived, current =>
                    {
                        this.tested++;
                        Report currentReport = new Report(current);
                        currentReport.TypeID = 1;
                        currentReport.TestID = wc.count(currentPaper.Value.Data);
                        reports.AddLast(currentReport);
                        currentPaper = currentPaper.Next;
                    });

                    break;
                case 2:
                    Paper found=null;
                    foreach (Paper current in retrived)
                    {
                        if (current.FileName == "Dictonary.txt")
                        {
                            found = current;

                        }
                    }

                    LinkedList<string> words;
                    if (found != null)
                    {
                        words = found.Data;
                        retrived.Remove(found);

                        //replace word list
                    }
                    else
                    {
                        words = getWordlist();
                    }
                    foreach(Paper current in retrived)
                        {
                            this.tested++;
                            Report report = new Report(current);
                            report.TypeID = 2;
                            report.KeyData=keywc.count(current.Data,words);
                            reports.AddLast(report);

                            //currentPaper = currentPaper.Next;
                        }
                    Parallel.ForEach(reports, current =>//spawn threads for every report
                    {

                        LinkedListNode<Report> testing = reports.First;// grab first not to compare to all documents
                        while (testing != null)
                        {
                            Compare store = new Compare();
                            int total = 0;
                            foreach (KeyValuePair<string, int> word in current.KeyData)
                            {
                                //setup keys we are dealing with
                                string key = word.Key;

                                //get values
                                int value1 = word.Value;
                                int value2;
                                while (!(testing.Value.KeyData.TryGetValue(key, out value2))) ;
                                //Calculate
                                int result = Math.Abs(value1 - value2);
                                total += result;
                                //save data
                                while (!(store.Data.TryAdd(key, result))) ;

                            }
                            int wc = 0;
                            while (!(store.Data.TryGetValue("WC",out wc)));
                            total -= wc;
                            while (!(store.Data.TryAdd("Total", total))) ;//add total to the dictionary before we continue
                            store.Key = current.UserID +"*"+ testing.Value.UserID;//format is GUID*GUID
                            current.Compared.AddLast(store);
                            testing = testing.Next;// go to next report
                        }

                    });

                    break;
                case 3://n-word
                    break;
                case 4://phrased n-word
                    break;
                default:
                    return -1;
            }

            return this.tested;
        }
Esempio n. 4
0
        public int run(string aGUID)
        {
            assignmentReturn ar = new assignmentReturn();
            LinkedList<Paper> retrived;
            if (aGUID != null)
            {
                retrived = ar.getAssignmentList(aGUID);
            }
            else
            {
                retrived = ar.getAssignmentList();
            }
            LinkedList<Report> output = new LinkedList<Report>();

            ConcurrentDictionary<String, int> wordList=new ConcurrentDictionary<string,int>();
            Paper found = null;
            LinkedList<string> words;
            LinkedListNode<Paper> currentPaper = retrived.First;
            switch (type)
            {
                case 1://wc
                    // for each item inRestults

                    Parallel.ForEach(retrived, current =>
                    {
                        this.tested++;
                        Report currentReport = new Report(current);
                        currentReport.TypeID = 1;
                        currentReport.TestID = wc.count(currentPaper.Value.Data);
                        reports.AddLast(currentReport);
                        currentPaper = currentPaper.Next;
                    });

                    break;
                case 2:
                    found=null;
                    foreach (Paper current in retrived)
                    {
                        if (current.FileName == "Dictonary.txt")
                        {
                            found = current;

                        }
                    }

                    if (found != null)
                    {
                        words = found.Data;
                        retrived.Remove(found);

                        //replace word list
                    }
                    else
                    {
                        words = getWordlist();
                    }
                    foreach(Paper current in retrived)
                        {
                            this.tested++;
                            Report report = new Report(current);
                            report.TypeID = 2;
                            report.KeyData=keywc.count(current.Data,words);
                            reports.AddLast(report);

                            //currentPaper = currentPaper.Next;
                        }
                    Parallel.ForEach(reports, current =>//spawn threads for every report
                    {

                        LinkedListNode<Report> testing = reports.First;// grab first not to compare to all documents
                        while (testing != null)
                        {
                            Compare store = new Compare();
                            int total = 0;
                            foreach (KeyValuePair<string, int> word in current.KeyData)
                            {
                                //setup keys we are dealing with
                                string key = word.Key;

                                //get values
                                int value1 = word.Value;
                                int value2;
                                while (!(testing.Value.KeyData.TryGetValue(key, out value2))) ;
                                //Calculate
                                int result = Math.Abs(value1 - value2);
                                total += result;
                                //save data
                                while (!(store.Data.TryAdd(key, result))) ;

                            }
                            int wc = 0;
                            while (!(store.Data.TryGetValue("WC",out wc)));
                            total -= wc;
                            while (!(store.Data.TryAdd("Total", total))) ;//add total to the dictionary before we continue
                            store.Key = current.UserID +"*"+ testing.Value.UserID;//format is GUID*GUID
                            current.Compared.AddLast(store);
                            testing = testing.Next;// go to next report
                        }

                    });

                    break;
                case 3:
                    //look for dictionary.txt
                    foreach (Paper current in retrived)
                    {
                        if (current.FileName == "Dictonary.txt")
                        {
                            found = current;

                        }
                    }

                    //use it for wordlist
                    if (found != null)
                    {
                        words = found.Data;
                        retrived.Remove(found);

                        //replace word list
                    }
                    else //use wordlist from database
                    {
                        words = getWordlist();
                    }

                    int z = 0;
                    foreach (string w in words)
                    {
                        while (!(wordList.TryAdd(w, z)))
                        {
                            int y;
                            wordList.TryRemove(w,out y);
                        }

                        z++;
                    }
                    //for each file create a report and fill in the fields includes calculations
                    Parallel.ForEach(retrived, current =>
                    {
                        this.tested++;
                        Report currentReport = new Report(current);
                        currentReport.TypeID = 3;
                        currentReport.Order = KeyOrder.count(current.Data, wordList);
                        currentReport.Dic = wordList;
                        reports.AddLast(currentReport);
                        currentPaper = currentPaper.Next;
                    });
                    Dictionary<int, LinkedList<Report>> collisions = new Dictionary<int, LinkedList<Report>>();
                    int num=5; //look at the 5 keyword
                    foreach (Report r in reports)
                    {

                        LinkedList<int> test = new LinkedList<int>();
                        foreach (int i in r.Order)
                        {
                            if (test.Count > num) test.RemoveFirst();
                            test.AddLast(i);
                            string y = "";
                            foreach (int x in test)
                            {
                                y += x;
                            }
                            if (test.Count > num)
                            {
                                LinkedList<Report> list;
                                int hash = y.GetHashCode();
                                if (collisions.TryGetValue(hash, out list)) // if hash is in table add to list
                                {
                                    if (!list.Contains(r)) // don't colide with self
                                    {
                                        list.AddLast(r);
                                    }

                                }
                                else //or make a new list of and add
                                {
                                    list = new LinkedList<Report>();
                                    list.AddLast(r);
                                    collisions.Add(hash, list);
                                }
                            }

                        }
                    }

                    int n=0;
                    //count the number of collisions for each word that has more then one report in the list
                    foreach (KeyValuePair<int, LinkedList<Report>> c in collisions)
                    {
                        if (c.Value.Count > 1)
                        {
                            string id = "";
                            foreach (Report r in c.Value)
                            {
                                id +="*"+r.UserID;
                            }
                            if (hits.TryRemove(id, out n))
                            {
                                n++;

                                hits.TryAdd(id, n);
                            }
                            else
                            {
                                hits.TryAdd(id, 1);
                            }
                        }
                    }

                    break;
                case 4://phrased n-word
                    break;
                default:
                    return -1;
            }

            return this.tested;
        }
Esempio n. 5
0
        public int run(string aGUID)
        {
            //int changed = 0;
            //inRestults= getdata(aID);
            // Create a temp linked list
            //type = 1;
            //string c;
            //LinkedList<string> input = new LinkedList<string>();
            //c = "this is a test";
            //input.AddFirst(c);
            //c = "this is a test";
            //input.AddFirst(c);
            //c = "this is a test";
            //input.AddFirst(c);
            //Paper x = new Paper();
            //x.Data = input;
            //x.AID = "2";
            //x.Link = "this is a test link";
            //x.UserID = "TestUser";
            //LinkedList<Paper> retrived = new LinkedList<Paper>();
            //retrived.AddLast(x);
            assignmentReturn ar = new assignmentReturn();
            LinkedList<Paper> retrived;
            if (aGUID != null)
            {
                retrived = ar.getAssignmentList(aGUID);
            }
            else
            {
                retrived = ar.getAssignmentList();
            }
            LinkedList<Report> output = new LinkedList<Report>();

            //LinkedList<Report> oResults=new LinkedList<Report>();
            LinkedListNode<Paper> currentPaper = retrived.First;
            switch (type)
            {
                case 1://wc
                    // for each item inRestults

                    Parallel.ForEach(retrived, current =>
                    {
                        this.tested++;
                        Report currentReport = new Report(current);
                        currentReport.TypeID = 1;
                        currentReport.TestID = wc.count(currentPaper.Value.Data);
                        reports.AddLast(currentReport);
                        currentPaper = currentPaper.Next;
                    });

                    break;
                case 2:

                    Parallel.ForEach(retrived, current =>
                        {
                            this.tested++;
                            Report report = new Report(current);
                            report.TypeID = 2;
                            report.KeyData=keywc.count(current.Data);
                            reports.AddLast(report);
                            //currentPaper = currentPaper.Next;
                        });
                    //while (currentPaper != null)
                    //{
                    //    this.tested++;
                    //    Report currentReport = new Report(currentPaper.Value);
                    //    currentReport.TypeID = 2;
                    //    Thread t = new Thread();     //(keywc.count(currentPaper.Value.Data,currentReport));
                    //    reports.AddLast(currentReport);
                    //    currentPaper = currentPaper.Next;
                    //}

                    break;
                case 3://n-word
                    break;
                case 4://phrased n-word
                    break;
                default:
                    return -1;
            }
            // put results into results tables
            // changed = sqlinsert(oresults); // number of rows added to the tables

            return this.tested;
        }