public static BuildChecker ( string filepath ) : string>.Dictionary |
||
filepath | string | |
리턴 | string>.Dictionary |
public void NaiveKruskalArtificial() { Shred.BUFFER = 0; Shred.SAMPLE_SIZE = 4; var path = Path.Combine(Drive.GetDriveRoot(), Dir.ArtificialTestDirectory, Dir.NaiveKruskalHttpDocument); var shreds = Shred.Factory("image", path, false); var results = Reconstructor.NaiveKruskalAlgorithm(shreds); var checker = Helpers.BuildChecker(Path.Combine(path, Helpers.CheckFile)); shreds.ForEach(shred => Console.Write(" " + shred.Id + ", ")); Console.WriteLine(); results.ForEach(shred => Console.Write(" " + shred.Id + ", ")); Console.WriteLine(); var indicies = results.Select((t, pos) => new Tuple <int, Shred>(pos, t)).ToList(); var result = indicies.Select(pair => { var filename = Path.GetFileName(pair.Item2.Filepath); Assert.IsNotNull(filename); Assert.IsNotNull(checker[filename]); var expected = checker[filename]; var actual = pair.Item1; Console.WriteLine("Actual " + actual + " vs. " + expected + " | File: " + filename); return(actual.ToString(CultureInfo.InvariantCulture) == expected); }).ToList(); // var diff = Differ.DiffShredByOrder(results.Select(shred => shred.Id).ToList(), //Enumerable.Range(0, results.Count).Select(ii => (long)ii).ToList()); // Console.WriteLine("Difference : " + diff); ExportResult((Cluster)shreds.First().Root(), "../../visualizer/NaiveKruskalArtifical.png"); }
public void OcrSimpleOcrTest() { // Init Drive and a Checker (Hashmap) var relpath = Path.Combine(Dir.OcrDirectory, Dir.OcrSimple); var fullpath = Path.Combine(Drive.GetDriveRoot(), relpath); var checker = Helpers.BuildChecker(Path.Combine(fullpath, Helpers.CheckFile)); var drive = new Drive(relpath, Drive.Reason.Read); // Init Correct List var correct = new List <bool>(drive.FileCount("snip")); // Scan each snippet, check if they are substrings, save result in correct foreach (var file in drive.Files("snip")) { var img = new Bitmap(file); var filename = Path.GetFileName(file); var ocrdata = OCR.Recognize(img); Assert.IsTrue(filename != null); Assert.IsTrue(checker[filename] != null); var isCorrect = ocrdata.Text.ToLower().Contains(checker[filename].ToLower()); correct.Add(isCorrect); Console.WriteLine("-------------------------------------------"); Console.WriteLine("CORRECT: " + isCorrect); Console.WriteLine("OCR: " + OCR.StripNewLine(ocrdata.Text)); Console.WriteLine("REAL: " + checker[filename].ToLower()); Console.WriteLine("COST: " + ocrdata.Cost); Console.WriteLine(); } // Ensure that all the OCR scans were correct Assert.IsTrue(correct.All(x => x)); }
public void FilterEmptyDetectionTest() { //Load Shreds var path = Path.Combine(Dir.OcrDirectory, Dir.OcrEmptyTestDirectory); var shreds = (new Drive(path, Drive.Reason.Read)).Files("image"); var checker = Helpers.BuildChecker(Path.Combine(Drive.GetDriveRoot(), path, Helpers.CheckFile)); var results = shreds.Select(shred => { var filename = Path.GetFileName(shred); bool?empty; using (Bitmap bmp = new Bitmap(shred)) { Assert.IsTrue(filename != null); empty = Filter.IsEmpty(bmp); Console.WriteLine("--------------------------------------"); Console.WriteLine("Shred Name" + Path.GetFileNameWithoutExtension(shred)); Console.WriteLine("IsEmpty? = " + empty); Console.WriteLine("Is Really Empty? = " + checker[filename]); Console.WriteLine("Correct: " + (checker[filename] == ((bool)empty ? "y" : "n"))); Console.WriteLine(); } return(checker[filename] == ((bool)empty ? "y" : "n")); }); results.ToList().ForEach(Assert.IsTrue); }
public void OcrEmptyDetectionTest() { //Load Shreds var abspath = Path.Combine(Drive.GetDriveRoot(), Dir.OcrDirectory, Dir.OcrEmptyTestDirectory); var shreds = Shred.Factory("empty", abspath, true); var checker = Helpers.BuildChecker(Path.Combine(abspath, Helpers.CheckFile)); var results = shreds.Select(shred => { var filename = Path.GetFileName(shred.Filepath); Assert.IsTrue(filename != null); Console.WriteLine("--------------------------------------"); Console.WriteLine("Shred Name" + Path.GetFileNameWithoutExtension(shred.Filepath)); Console.WriteLine("IsEmpty? = " + shred.IsEmpty); Console.WriteLine("Is Really Empty? = " + checker[filename]); Console.WriteLine("Correct: " + (checker[filename] == (shred.IsEmpty ? "y" : "n"))); Console.WriteLine(); return(checker[filename] == (shred.IsEmpty ? "y" : "n")); }); results.ToList().ForEach(Assert.IsTrue); }
public void NaiveKruskalPrimitive() { Shred.BUFFER = 0; Shred.SAMPLE_SIZE = 1; var folder = Path.Combine(Drive.GetDriveRoot(), Dir.NaiveKruskalTestDirectory); var paths = new List <string>(); paths.Add(Path.Combine(folder, NaiveThree)); paths.Add(Path.Combine(folder, NaiveSix)); paths.Add(Path.Combine(folder, NaiveTen)); foreach (var path in paths) { var shreds = Shred.Factory("Shred", path, false); var checker = Helpers.BuildChecker(Path.Combine(path, Helpers.CheckFile)); var results = Reconstructor.NaiveKruskalAlgorithm(shreds); var indicies = results.Select((t, pos) => new Tuple <int, Shred>(pos, t)).ToList(); Console.WriteLine(" ---- " + path + "----"); var result = indicies.Select(pair => { var filename = Path.GetFileName(pair.Item2.Filepath); Assert.IsNotNull(filename); Assert.IsNotNull(checker[filename]); var expected = checker[filename]; var actual = pair.Item1; Console.WriteLine("Actual " + actual + " vs. " + expected + " | File: " + filename); return(actual.ToString(CultureInfo.InvariantCulture) == expected); }).ToList(); Exporter.ExportJson(results.First().Root()); Console.WriteLine(); result.ForEach(Assert.IsTrue); } }