Пример #1
0
        //Just a function used to test the classifier
        private void Test()
        {
            TextAnalyzer analyzer = TextAnalyzer.GetInstance();
            float        result   = analyzer.Analyze("");

            Debug.WriteLine(result);
        }
Пример #2
0
        public void PrivateKey()
        {
            TextFile textFile = GetTextFile("id");

            _analyzer.Analyze(textFile);

            Assert.AreEqual(1, _vulnerabilities.Count);
            Vulnerability vulnerability = _vulnerabilities[0];

            Assert.AreEqual("PrivateKey", vulnerability.Code);
            Assert.AreEqual("App contains a private key", vulnerability.Title);
            Assert.AreEqual("Private keys should never be embedded in your app.", vulnerability.Description);
            string expectedPath = Path.Combine("TestFiles", "PrivateKey", "id");

            Assert.AreEqual(expectedPath, vulnerability.FilePath);
            Assert.AreEqual("id", vulnerability.FullyQualifiedName);
            Assert.AreEqual(0, vulnerability.LineNumber);
        }
Пример #3
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"));
        }
 /// <summary>
 /// Analyzes the last 100 comments made by the given user and returns their estimated political leaning
 /// </summary>
 /// <param name="comments"></param>
 /// <returns>A float representing estimated political leaning, with 0 being liberal, 1 being conservative, and 0.5 being moderate</returns>
 public static float CommentAnalyzer(RedditComment[] comments)
 {
     if (comments.Length == 0)
     {
         return(DEFAULT_RANK);
     }
     //Convert the array of Reddit comments to strings
     string[] strings = new string[comments.Length];
     for (int i = 0; i < comments.Length; i++)
     {
         strings[i] = comments[i].Body;
     }
     return(textAnalyzer.Analyze(strings));
 }
Пример #5
0
        public void Setup()
        {
            var input        = @"
                <w:body>
                    <w:p>
                        <w:r>                            
                            <w:t> ok jim, ok</w:t>
                        </w:r>
                    </w:p>
                </w:body>
            ";
            var textAnalyzer = new TextAnalyzer();

            var node = TestHelper.ParseString(input, true);

            result = textAnalyzer.Analyze(node);
        }