Exemplo n.º 1
0
        static void Main()
        {
            // A collection of Documents
            Document[] docArray = new Document[2];

            // First entry is a Document
            docArray[0] = new Document("Test Document");

            // Second entry is a CompressibleDocument (ok because
            // CompressibleDocument is a Document)
            docArray[1] = new CompressibleDocument("Test compressibleDocument");


            // don't know what we'll pull out of this hat
            foreach (Document doc in docArray)
            {
                // report your name
                Console.WriteLine("Got: {0}", doc);

                // Both pass this test
                IStorable isDoc = doc as IStorable;
                if (isDoc != null)
                {
                    isDoc.Read();
                }

                // fails for Document
                // passes for CompressibleDocument
                ICompressible icDoc = doc as ICompressible;
                if (icDoc != null)
                {
                    icDoc.Compress();
                }
            }
        }
Exemplo n.º 2
0
        // Given a test ticket and a set of tickets, return a sorted list of all tickets within the
        // set similar to the test ticket
        public ICompressible[] FindSimilarEntities(ICompressible entity, ICompressible[] dataSet)
        {
            // List to hold all of the similar tickets
            List<Tuple<double, ICompressible>> similarEntities = new List<Tuple<double, ICompressible>>();

            // Similary value between the two tickets
            double similarityVal;

            // Cutoff value for adding similar tickets to the similarEntities List
            double similarityThreshold = 0.44;

            // Iterate through the set of tickets and add similar tickets to the similarEntites List
            foreach (ICompressible entity2 in dataSet)
            {
                similarityVal = GetSimilarity(entity, entity2);
                if (similarityVal < similarityThreshold)
                {
                    similarEntities.Add(new Tuple<double, ICompressible>(similarityVal,entity2));
                }
            }

            // Sort the similarEntities List by NCD value
            similarEntities.Sort((a, b) => a.Item1.CompareTo(b.Item1));

            return similarEntities.Select(t => t.Item2).ToArray();
        }
Exemplo n.º 3
0
 public ProcessManager(string inputFile, string outputFile, ProcessMode mode)
 {
     m_inputFile   = inputFile;
     m_outputFile  = outputFile;
     m_processMode = mode;
     m_compressor  = new Compressors.GZipCompressor();
     InitializePlan();
 }
Exemplo n.º 4
0
 public static bool Initialize(IImageHolder imageHolder, IEncryptable encryptable, ICompressible compressible)
 {
     try
     {
         _imageHolder     = imageHolder;
         _imageEncryptor  = encryptable;
         _imageComprosser = compressible;
         return(true);
     }
     catch (Exception e)
     {
         throw new ArgumentException("Arguments can't match the correct types!");
     }
 }
Exemplo n.º 5
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;
            }
        }
Exemplo n.º 6
0
        static void Main()
        {
            //kolekcija Docmunets
            Document[] docArray = new Document[2];

            //prvi unos je Document
            docArray[0] = new Document("Test document");

            //drugi unos je CompressibleDocument
            //uredu je jer je CompressibleDocument Document
            docArray[1] = new CompressibleDocument("Test compressible document");

            //ne znamo sta cemo izvuci iz sesira
            foreach (Document doc in docArray)
            {
                //ispisuje ime
                Console.WriteLine("Got: {0}", doc);

                //obje prolaze test
                //sa operatorom is
                if (doc is IStorable)
                {
                    IStorable isDoc = (IStorable)doc;
                    isDoc.Read();
                }

                //sa operatorom as
                IStorable isDoc2 = doc as IStorable;
                if (isDoc2 != null)
                {
                    isDoc2.Read();
                }

                //ne uspjeva za Documnet
                //prolazi za CompressibleDocument
                if (doc is ICompressible)
                {
                    ICompressible icDoc = (ICompressible)doc;
                    icDoc.Compress();
                }
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Document doc = new Document("Hello! This is Document");

            IStorable isDoc = doc as IStorable;

            if (isDoc != null)
            {
                isDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorable not support");
            }

            ICompressible icDoc = doc as ICompressible;

            if (icDoc != null)
            {
                icDoc.Compress();
            }
            else
            {
                Console.WriteLine("ICompressible not support");
            }

            ILoggedCompressible ilcDoc = doc as ILoggedCompressible;

            if (ilcDoc != null)
            {
                ilcDoc.LogSavedByte();
                ilcDoc.Compress();
            }
            else
            {
                Console.WriteLine("ILoggedCompressible not support");
            }
            IStorableCompressible iscDoc = doc as IStorableCompressible;

            if (iscDoc != null)
            {
                iscDoc.LogSavedByte();
                iscDoc.LogOriginalSize();
                iscDoc.Compress();
                iscDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorableCompressible not support");
            }

            IEncryptable ieDoc = doc as IEncryptable;

            if (ieDoc != null)
            {
                ieDoc.Encrypt();
            }
            else
            {
                Console.WriteLine("Encrypt not support");
            }
            Console.ReadLine();
        }
Exemplo n.º 8
0
        private const int c_blockSize = 2 << 10; // 1mb

        public ProcessPlanMultithread(string inputFilePath, string outputFilePath, ICompressible compressor)
        {
            m_inputFile  = inputFilePath;
            m_outputFile = outputFilePath;
            m_compressor = compressor;
        }
        static void Main()
        {
            // create a document object
            Document doc = new Document("Test Document");

            // cast the document to the various interfaces
            IStorable isDoc = doc as IStorable;

            if (isDoc != null)
            {
                isDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorable not supported");
            }

            ICompressible icDoc = doc as ICompressible;

            if (icDoc != null)
            {
                icDoc.Compress();
            }
            else
            {
                Console.WriteLine("Compressible not supported");
            }

            ILoggedCompressible ilcDoc = doc as ILoggedCompressible;

            if (ilcDoc != null)
            {
                ilcDoc.LogSavedBytes();
                ilcDoc.Compress();
                // ilcDoc.Read();
            }
            else
            {
                Console.WriteLine("LoggedCompressible not supported");
            }

            IStorableCompressible isc = doc as IStorableCompressible;

            if (isc != null)
            {
                isc.LogOriginalSize(); // IStorableCompressible
                isc.LogSavedBytes();   // ILoggedCompressible
                isc.Compress();        // ICompressible
                isc.Read();            // IStorable
            }
            else
            {
                Console.WriteLine("StorableCompressible not supported");
            }

            IEncryptable ie = doc as IEncryptable;

            if (ie != null)
            {
                ie.Encrypt();
            }
            else
            {
                Console.WriteLine("Encryptable not supported");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Method to determine the NCD value between two tickets (ICompressible objects)
        /// NCD(x,y) = {Z(xy) - min[Z(x), Z(y)]} / max[Z(x), Z(y)]
        /// </summary>
        /// <param name="entity1">ICompressible ticket to operate NCD on</param>
        /// <param name="entity2">ICompressible ticket to operate NCD on</param>
        /// <returns>Double value representing the NCD value between the two tickets</returns>
        private double getNCD(ICompressible entity1, ICompressible entity2)
        {
            // Compress the tickets
            int compressedEntity1 = GetComplexity(entity1);
            int compressedEntity2 = GetComplexity(entity2);

            // Concatenate the tickets
            byte[] combinedArray = entity1.ToByteArray().Concat(entity2.ToByteArray()).ToArray();

            // NCD_A = compressed size of the two tickets concatenated
            double NCD_A = (double) compressionSize(combinedArray);

            // NCD_B = min(compressed size of ticket 1, compressed size of ticket 2)
            // NCD_C = max(compressed size of ticket 1, compressed size of ticket 2)
            double NCD_B, NCD_C;

            // Determine the values of NCD_B and NCD_C
            if (compressedEntity1 >= compressedEntity2)
            {
                NCD_B = (double) compressedEntity2;
                NCD_C = (double) compressedEntity1;
            }
            else
            {
                NCD_B = (double) compressedEntity1;
                NCD_C = (double) compressedEntity2;
            }

            // Compute and return the NCD value
            double NCD_result = (NCD_A - NCD_B) / NCD_C;
            return NCD_result;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Method to determine the MCD value between two tickets
        /// MCD(A,B) = max(|c(AB)-c(AA)|, |c(AB)-c(BB)|)/max(c(AA),c(BB))
        /// </summary>
        /// <param name="entity1">ICompressible ticket to operate MCD on</param>
        /// <param name="entity2">ICompressible ticket to operate MCD on</param>
        /// <returns>Double value representing the MCD value between the two tickets</returns>
        private double getMCD(ICompressible entity1, ICompressible entity2)
        {
            double MCD_numerator;
            double MCD_result;

            // Create two StringCompressible objects of the entities concatenated to themselves
            ICompressible AA = new StringCompressible (Encoding.ASCII.GetString(entity1.ToByteArray().Concat(entity1.ToByteArray()).ToArray()));
            ICompressible BB = new StringCompressible (Encoding.ASCII.GetString(entity2.ToByteArray().Concat(entity2.ToByteArray()).ToArray()));

            // Find c(AA) and c(BB)
            double MCD_AA = (double) GetComplexity(AA);
            double MCD_BB = (double) GetComplexity(BB);

            // Find c(AB)
            byte[] combinedArray = entity1.ToByteArray().Concat(entity2.ToByteArray()).ToArray();
            double MCD_AB = (double)compressionSize(combinedArray);

            // Find max( |c(AB)-c(AA)|, |c(AB)-c(BB)|)
            if (Math.Abs(MCD_AB - MCD_AA) >= Math.Abs(MCD_AB - MCD_BB))
            {
                MCD_numerator = Math.Abs(MCD_AB - MCD_AA);
            }
            else
            {
                MCD_numerator = Math.Abs(MCD_AB - MCD_BB);
            }

            // Find MCD(A,B)
            if (MCD_AA >= MCD_BB)
            {
                MCD_result = (MCD_numerator / MCD_AA);
            }
            else
            {
                MCD_result = (MCD_numerator / MCD_BB);
            }

            return MCD_result;
        }
Exemplo n.º 12
0
 // Determines if two given tickets are similar or not
 public bool IsSimilar(ICompressible entity1, ICompressible entity2)
 {
     if (GetSimilarity(entity1, entity2) <= threshold)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 13
0
 // Return the NCD value between two tickets
 public double GetSimilarity(ICompressible entity1, ICompressible entity2)
 {
     return getMCD(entity1, entity2);
 }
Exemplo n.º 14
0
        // Returns the size of the compressed ticket
        public int GetComplexity(ICompressible entity)
        {
            // Return the complexity of the ticket if its been set (i.e. not zero)
            if (entity.Complexity != 0)
            {
                return entity.Complexity;
            }

            // Set the complexity of the ticket for later use
            entity.Complexity = compressionSize(entity.ToByteArray());

            return entity.Complexity;
        }
Exemplo n.º 15
0
        public void Run()
        {
            string testString = "String ";

            Note[] myNoteArray = new Note[3];

            for (int i = 0; i < 3; i++)
            {
                string docText = testString + i.ToString();
                if (i % 2 == 0)
                {
                    Document myDocument = new Document(docText, (i + 5) * 10);
                    myNoteArray[i] = myDocument;
                }
                else
                {
                    Note myNote = new Note(docText);
                    myNoteArray[i] = myNote;
                }
            }

            foreach (Note theNote in myNoteArray)
            {
                Console.WriteLine("\nTesting {0} with IS", theNote);

                theNote.Read();     // all notes can do this
                if (theNote is ICompressible)
                {
                    ICompressible myCompressible = theNote as ICompressible;
                    myCompressible.Compress();
                }
                else
                {
                    Console.WriteLine("This storable object is not compressible.");
                }

                if (theNote is Document)
                {
                    Document myDoc = theNote as Document;

                    // clean cast
                    myDoc = theNote as Document;
                    Console.WriteLine("my documentID is {0}", myDoc.ID);
                }
            }

            foreach (Note theNote in myNoteArray)
            {
                Console.WriteLine("\nTesting {0} with AS", theNote);
                ICompressible myCompressible = theNote as ICompressible;
                if (myCompressible != null)
                {
                    myCompressible.Compress();
                }
                else
                {
                    Console.WriteLine("This storable object is not compressible.");
                }    // end else

                Document theDoc = theNote as Document;
                if (theDoc != null)
                {
                    Console.WriteLine("My documentID is {0}", ((Document)theNote).ID);
                }
                else
                {
                    Console.WriteLine("Not a document.");
                }
            }
        }
Exemplo n.º 16
0
        public static void Main(string[] args)
        {
            // create a document object
            Document doc = new Document("Test Document");

            // cast the document to the various interfaces
            IStorable isDoc = doc as IStorable;

            if (isDoc != null)
            {
                isDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorable not supported");
            }

            ICompressible icDoc = doc as ICompressible;

            if (icDoc != null)
            {
                icDoc.Compress();
            }
            else
            {
                Console.WriteLine("Compressible not supported");
            }

            ILoggedCompressible ilcDoc = doc as ILoggedCompressible;

            if (ilcDoc != null)
            {
                ilcDoc.LogSavedBytes();
                ilcDoc.Compress();
                // ilcDoc.Read();
            }
            else
            {
                Console.WriteLine("LoggedCompressible not supported");
            }

            IStorableCompressible isc = doc as IStorableCompressible;

            if (isc != null)
            {
                isc.LogOriginalSize();  // IStorableCompressible
                isc.LogSavedBytes();    // ILoggedCompressible
                isc.Compress();         // ICompressible
                isc.Read();             // IStorable
            }
            else
            {
                Console.WriteLine("StorableCompressible not supported");
            }

            IEncryptable ie = doc as IEncryptable;

            if (ie != null)
            {
                ie.Encrypt();
            }
            else
            {
                Console.WriteLine("Encryptable not supported");
            }

            IStorable isDocument = (IStorable)doc;

            isDocument.Status = 0;
            isDocument.Read();

            // error!
//            IStorable doc1 = new IStorable ();

            // OK!
            IStorable doc2 = new Document("Test2 document");

            if (doc2)
            {
                doc2.Read();
            }
        }
Exemplo n.º 17
0
        static void Main()
        {
            //pravi objekat dokumenta
            Document doc = new Document("Test document");

            //pretvara dokument za razlicita sucelja
            IStorable isDoc = doc as IStorable;

            if (isDoc != null)
            {
                isDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorable not supported");
            }

            ICompressible icDoc = doc as ICompressible;

            if (icDoc != null)
            {
                icDoc.Compress();
            }
            else
            {
                Console.WriteLine("Compressible not supported");
            }

            ILoggedCompressible ilcDoc = doc as ILoggedCompressible;

            if (ilcDoc != null)
            {
                ilcDoc.LogSavedBytes();
                ilcDoc.Compress();
                //ilcDoc.Read(); //ne moze pozvati metodu read
            }
            else
            {
                Console.WriteLine("LoggedCompressible not supported");
            }

            IStorableCompressible isc = doc as IStorableCompressible;

            if (isc != null)
            {
                isc.LogOriginalSize();  //IStorableCompressible
                isc.LogSavedBytes();    //ILoggedCompressible
                isc.Compress();         //ICompressible
                isc.Read();             //IStorable
            }
            else
            {
                Console.WriteLine("StorableCompressible not supported");
            }

            IEncryptable ie = doc as IEncryptable;

            if (ie != null)
            {
                ie.Encrypt();
            }
            else
            {
                Console.WriteLine("Encrytable not supported");
            }
        }
Exemplo n.º 18
0
 // Set the complexity of a ticket
 public int SetComplexity(ICompressible entity)
 {
     int complexity = GetComplexity(entity);
     entity.Complexity = complexity;
     return complexity;
 }