Ejemplo n.º 1
0
        public static List <Tuple <Shred, int> > LoadShredsRandomized(List <string> filenames, bool runOcr = true)
        {
            var randomizedFilenames = Shuffle(filenames);
            var shreds = Shred.Factory(randomizedFilenames.Select(pair => pair.Item1).ToList(), runOcr);

            return(randomizedFilenames.Zip(shreds, (pair, shred) => Tuple.Create(shred, pair.Item2)).ToList());
        }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 3
0
        public void StitcherArtificialTest()
        {
            var shreds = Shred.Factory("image", Path.Combine(Drive.GetDriveRoot(), Dir.ArtificialTestDirectory, Dir.ArtificialHttpDocument), false);
            var bitmap = Stitcher.Merge(shreds);

            bitmap.Save("StitcherArtificialTest.png", ImageFormat.Png);
        }
Ejemplo n.º 4
0
        public void StitcherPrimitiveTest()
        {
            var shreds = Shred.Factory("Shred", Path.Combine(Drive.GetDriveRoot(), Dir.StitcherTestDirectory, "PrimitiveTest"), false);
            var bitmap = Stitcher.Merge(shreds);

            bitmap.Save("StitcherPrimitiveTest.png", ImageFormat.Png);
        }
Ejemplo n.º 5
0
        public static List <Shred> InitializeShreds(bool runOcr = false)
        {
            Console.WriteLine("Building Shreds");
            var path   = Path.Combine(Drive.GetDriveRoot(), Dir.CarusoTestDirectory, Dir.FewTestMaterials);
            var shreds = Shred.Factory("image", path, runOcr);

            return(shreds);
        }
Ejemplo n.º 6
0
        public static List <Shred> BootstrapPrimitiveThree()
        {
            Console.WriteLine("Building Shreds");
            var path   = Path.Combine(Drive.GetDriveRoot(), Dir.PrimitiveTestDirectory, Dir.PrimitiveTestThreeNormal);
            var shreds = Shred.Factory("Shred", path, false);

            return(shreds);
        }
Ejemplo n.º 7
0
        public static void Reconstruct(string prefix, string dir, bool display)
        {
            Console.WriteLine("Loading Shreds");
            var shreds = Shred.Factory(prefix, dir, false);

            Console.WriteLine("Comparing And Clusering");
            var results = Reconstructor.NaiveKruskalAlgorithm(shreds);

            Console.WriteLine("Exporting Results");
            NaiveKruskalTests.ExportResult((Cluster)results.First().Root(), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "output.png"),
                                           Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "json.js"));
        }
Ejemplo n.º 8
0
        public void OcrFullOrientationTest()
        {
            const string docRev   = @"Documents\EnergyInfrastructure\Full2";
            const string docReg   = @"Documents\IncomeTax_Ingalls\Full1";
            var          driveRev = new Drive(docRev, Drive.Reason.Read);
            var          driveReg = new Drive(docReg, Drive.Reason.Read);

            var revs = Shred.Factory(driveRev.Files("image").ToList(), true);
            var regs = Shred.Factory(driveReg.Files("image").ToList(), true);

            var resV = revs.Select(shred =>
            {
                Console.Write(" | Expected:" + Orientation.Reversed);
                Console.Write(" | Actual: " + (shred.TrueOrienation.ToString()));
                Console.Write(" | Orientation Confidence: " + shred.OrientationConfidence);
                if (shred.TrueOrienation == null)
                {
                    Console.WriteLine(" | Empty? =" + shred.IsEmpty);
                    Console.WriteLine("Correct? Indeterminable");
                    return(true);
                }

                var passed = (Orientation.Reversed == shred.TrueOrienation || shred.IsEmpty);
                Console.WriteLine(" | Empty? =" + shred.IsEmpty);
                Console.WriteLine("Correct? = " + passed);
                return(passed);
            }).ToList();
            var resG = regs.Select(shred =>
            {
                Console.Write(" | Expected:" + Orientation.Regular);
                Console.Write(" | Actual: " + (shred.TrueOrienation.ToString()));
                Console.Write(" | Orientation Confidence: " + shred.OrientationConfidence);
                if (shred.TrueOrienation == null)
                {
                    Console.WriteLine(" | Empty? =" + shred.IsEmpty);
                    Console.WriteLine("Correct? Indeterminable");
                    return(true);
                }

                var passed = Orientation.Regular == shred.TrueOrienation || shred.IsEmpty;
                Console.WriteLine(" | Empty? =" + shred.IsEmpty);
                Console.WriteLine("Correct? = " + passed);
                return(passed);
            }).ToList();

            Assert.IsTrue(resV.All(item => item));
            Assert.IsTrue(resG.All(item => item));
        }
Ejemplo n.º 9
0
        public void NaiveKruskalAuthentic()
        {
            var path = Path.Combine(Drive.GetDriveRoot(), Dir.PdfRequiremnetTestDirectory,
                                    Dir.PdfRequiremnetTestFullOne);
            var shreds  = Shred.Factory("image", path, false);
            var results = Reconstructor.NaiveKruskalAlgorithm(shreds);

            shreds.ForEach(shred => Console.Write(" " + shred.Id + ", "));
            Console.WriteLine();
            results.ForEach(shred => Console.Write(" " + shred.Id + ", "));
            Console.WriteLine();
            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)results.First().Root(), "../../visualizer/NaiveKruskalAuthentic.png");
        }
Ejemplo n.º 10
0
        public void TestQueue()
        {
            var max  = 1.00;
            var path = Path.Combine(Drive.GetDriveRoot(), Dir.PdfRequiremnetTestDirectory,
                                    Dir.PdfRequiremnetTestFullOne);
            var shreds = Shred.Factory("image", path, false);
            var queue  = Reconstructor.BuildQueue(shreds);

            while (queue.Count > 0)
            {
                var next = queue.Dequeue().ChamferSimilarity;
                Assert.IsTrue(next <= max);
                Console.WriteLine(next);
                max = next;
            }
        }
Ejemplo n.º 11
0
        public void ShredFactoryTest()
        {
            Console.WriteLine("Loading File from TestDrive And From Factory Independently");
            var relativeDirectory = Path.Combine(CarusoTestDirectory, CarusoTestMaterialsFolder);
            var fullDirectory     = Path.Combine(Drive.GetDriveRoot(), relativeDirectory);
            var mydrive           = new Drive(relativeDirectory, Drive.Reason.Read);
            var shreds            = Shred.Factory("image", fullDirectory);

            Assert.IsTrue(shreds.Count == mydrive.FileCount("image"));

            foreach (Shred shred in shreds)
            {
                Assert.IsTrue(File.Exists(shred.Filepath));
            }

            Console.WriteLine("Factory Test Successful");
        }
Ejemplo n.º 12
0
        public string Reconstruct(string prefix, string dir, bool display)
        {
            StringBuilder sb = new StringBuilder();

            WriteToLog("Loading Shreds");
            var shreds = Shred.Factory(prefix, dir, false);

            WriteToLog("Comparing And Clusering");
            var results = Reconstructor.NaiveKruskalAlgorithm(shreds);

            WriteToLog("Exporting Results");
            string currentDir = Directory.GetCurrentDirectory();

            NaiveKruskalTests.ExportResult((Cluster)results.First().Root(), Path.Combine(currentDir, "output.png"),
                                           Path.Combine(currentDir, "json.js"));
            WriteToLog("Export Complete");
            return(sb.ToString());
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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);
            }
        }