Ejemplo n.º 1
0
        // This method tests if an expected match is found for a given ticket and data set
        public bool ContainsMatch(ICompressible testTicket, ICompressible expectedMatch, ICompressible[] dataSet)
        {
            // Similarity object to use for FindSimilarEntities
            Similarity simTest = new Similarity();

            // Get the ordered results and return if the match is present
            ICompressible[] results = simTest.FindSimilarEntities(testTicket, dataSet);

            if(results.Contains(expectedMatch))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 2
0
        public void TestDetection()
        {
            //Create the data set as a list of StringCompressible objects
            List<StringCompressible> DataSet = new List<StringCompressible>();

            //Open the CSV to read in the data set
            string currentDirectory = Directory.GetCurrentDirectory();
            var CSVReader = new StreamReader(File.OpenRead(Path.Combine(currentDirectory, "IncidentRequest_Gold.csv")));

            //Read in the "golden set" and add the entities to DataSet
            while (!CSVReader.EndOfStream)
            {
                var row = CSVReader.ReadLine();
                var data = row.Split(',');
                DataSet.Add(new StringCompressible(data[0], data[1]));
            }

            //Open log file for writing
            var logFile = new StreamWriter(Path.Combine(currentDirectory, "TestDetection_Log.txt"));

            //Create the expected outcome 2D list
            List<List<string>> expectedLists = new List<List<string>>();

            //Read the expected outcomes json file into a string
            StreamReader fileReader = new StreamReader(File.OpenRead(Path.Combine(currentDirectory, "expectedOutcomes.json")));
            string jsonText = fileReader.ReadToEnd();
            JsonTextReader JReader = new JsonTextReader(new StringReader(jsonText));

            //Populate the expectedLists 2D list with the expected outcomes
            while (JReader.Read())
            {
                List<string> expectedMatches = new List<string>();
                if (JReader.TokenType.ToString() == "PropertyName" && JReader.Value.ToString() != "expectedOutcomes")
                {
                    expectedMatches.Add(JReader.Value.ToString());
                    JReader.Read();
                    JReader.Read();
                    while (JReader.TokenType.ToString() != "EndArray")
                    {
                        expectedMatches.Add(JReader.Value.ToString());
                        JReader.Read();
                    }
                    expectedLists.Add(expectedMatches);
                }
            }

            //Similarity object to use for FindSimilarEntities
            Similarity simTest = new Similarity();

            int currentList = 0;

            //Get the ordered results and return if the match is present
            foreach(StringCompressible ticket in DataSet)
            {
               ICompressible[] results = simTest.FindSimilarEntities(ticket, DataSet.ToArray());
               logFile.Write("{0} Matches: ", expectedLists[currentList][0]);
               foreach (StringCompressible expectedMatch in results)
               {
                   logFile.Write("{0} ", expectedMatch.ItemID);
                   logFile.Write("({0}), ", expectedLists[currentList].Contains(expectedMatch.ItemID));
               }
               currentList++;
               logFile.WriteLine();
            }
            logFile.Close();

            //Read the log file and assert that there are no false positives
            var logReader = new StreamReader(File.OpenRead(Path.Combine(currentDirectory, "TestDetection_Log.txt")));
            string log = logReader.ReadToEnd();
            logReader.Close();
            Assert.IsFalse(log.Contains("False"));
        }