Beispiel #1
0
        public async Task <ActionResult> Main(HttpPostedFileBase file)
        {
            if (file?.ContentLength > 0 && (Path.GetFileName(file.FileName).Split('.')[1] == "doc" || Path.GetFileName(file.FileName).Split('.')[1] == "docx"))
            {
                var types    = file.ContentType;
                var fileName = Path.GetFileName(file.FileName);
                var path     = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                file.SaveAs(path);

                var initialText = TextDocumentManager.TextFromFile(path);
                TextManager.PrepareText(initialText, out string[] initialWords, out Dictionary <int, string> initialDocIndexToSimplifiedWord, out int[] initialDocIndexes, out string[] simplifiedWords, out int wordCount);

                var plagiarismInWebSearch     = PlagiarismInWebFinder.FindAsync(initialWords, initialDocIndexToSimplifiedWord, initialDocIndexes, simplifiedWords, Server.MapPath("~/App_Data/uploads"));
                var plagiarismInLocalDBSearch = PlagiarismInLocalDBFinder.FindAsync(initialWords, initialDocIndexToSimplifiedWord, initialDocIndexes, simplifiedWords);

                await Task.WhenAll(plagiarismInWebSearch, plagiarismInLocalDBSearch);

                var plagiarismInWeb     = plagiarismInWebSearch.Result;
                var plagiarismInLocalDB = plagiarismInLocalDBSearch.Result;

                var DBPlagiarizedIndexes = plagiarismInLocalDB.InitialWordIndexToSourceIds.Keys.ToList();
                DBPlagiarizedIndexes.AddRange(plagiarismInWeb.InitialWordIndexToSourceIds.Keys.ToList());
                var allPlagiarismHtmlText = TextManager.ComposeHtmlText(initialWords, DBPlagiarizedIndexes);

                var(vodnost, toshnotnost) = TextAnalyzer.Analyze(simplifiedWords);
                PlagiarismResult plagiarism = new PlagiarismResult
                {
                    InitialWords          = initialWords,
                    SimplifiedWords       = simplifiedWords,
                    WordCount             = wordCount,
                    Vodnost               = vodnost,
                    Toshnotnost           = toshnotnost,
                    PlagiarismWeb         = plagiarismInWeb,
                    PlagiarismDB          = plagiarismInLocalDB,
                    AllPlagiarismHtmlText = allPlagiarismHtmlText,
                    DebugLogs             = plagiarismInWeb.DebugLogs + plagiarismInLocalDB.DebugLogs
                };
                ViewBag.DebugLogs = plagiarism.DebugLogs;
                foreach (KeyValuePair <int, HashSet <int> > lists in plagiarismInLocalDB.SourceIdToSourceWordsIndexes)
                {
                    Session["Doc" + lists.Key] = lists.Value;
                }
                foreach (KeyValuePair <string, HashSet <int> > lists in plagiarismInWeb.SourceIdToSourceWordsIndexes)
                {
                    Session[lists.Key] = lists.Value;
                }

                return(View("Main", plagiarism));
            }

            return(RedirectToAction("Main"));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //string nameFile = "Пар 3-01 Інтеграл Ньютона-Лейбніца";
            //string test = TextDocumentManager.TextFromFile(@"C:\Users\alex1\Desktop\" + nameFile + ".doc");
            //AddDocument(nameFile, test);
            //test = TextManager.SimplifyText(test).Replace("\r\n", " ");
            //AddWords(Logic.IndexingForDB(TextManager.WordsFromText(test).ToArray()), nameFile);

            string[] files = new string[5];
            files[0] = "Пар 3-01 Інтеграл Ньютона-Лейбніца.doc";
            files[1] = "LOL.docx";
            files[2] = "GPK.docx";
            files[3] = "Середа оцінювання адаптивних інтерфейсів користувачів.docx";
            files[4] = "Документ для теста.docx";
            // string fileName = "Пар 3-01 Інтеграл Ньютона-Лейбніца";
            for (int i = 0; i < 5; i++)
            {
                string initialText = TextDocumentManager.TextFromFile(@"C:\Users\alex1\Desktop\" + files[i]);
                AddDocument(files[i], initialText);
                TextManager.PrepareText(initialText, out string[] initialWords, out Dictionary <int, string> initialDocIndexToSimplifiedWord, out int[] initialDocIndexes, out string[] simplifiedWords, out int wordCount);
                AddWords(Logic.IndexingForDB(initialDocIndexes, simplifiedWords), files[i]);
            }



            //string str = "";
            //List<String> example = new List<string> { "index", "data", "are", "the", "of" };
            //foreach (KeyValuePair<int, List<List<int>>> pair in GetDocuments(example))
            //{

            //    Console.WriteLine("Документ - " + pair.Key);
            //    foreach (List<int> positions in pair.Value)
            //    {
            //        foreach (int pos in positions)
            //        {
            //            str += Convert.ToString(pos) + " ";
            //        }
            //        Console.WriteLine("  Позицiї - " + str);
            //        str = "";
            //    }
            //}
            Console.WriteLine("Ready");
            Console.ReadKey();
        }