public void HashedFingerprintTest()
 {
     const int Id = 0;
     const long HashBin = 20;
     const int HashTable = 30;
     const int TrackId = 0;
     const int HashedFingerprint = 0;
     HashBinMinHash target = new HashBinMinHash(Id, HashBin, HashTable, TrackId, HashedFingerprint);
     const int Expected = 0;
     target.HashedFingerprint = Expected;
     int actual = target.HashedFingerprint;
     Assert.AreEqual(Expected, actual);
 }
        public void HashBinMinHashConstructorTest()
        {
            string name = MethodBase.GetCurrentMethod().Name;

            const int Id = -1;
            const long HashBin = 10;
            const int HashTable = 120;
            const int TrackId = -1;
            const int HashedFingerprint = -1;
            HashBinMinHash target = new HashBinMinHash(Id, HashBin, HashTable, TrackId, HashedFingerprint);
            Assert.AreEqual(Id, target.Id);
            Assert.AreEqual(HashBin, target.Hashbin);
            Assert.AreEqual(HashTable, target.HashTable);
            Assert.AreEqual(TrackId, target.TrackId);
            Assert.AreEqual(HashedFingerprint, target.HashedFingerprint);
        }
        /// <summary>
        ///   Get a command to insert a HashBin created by Min-Hash + LSH schema into the database
        /// </summary>
        /// <param name = "hashBinMinHash">Hash to be inserted</param>
        /// <param name = "connection">Connection used to insert the hash</param>
        /// <returns>Command to be executed</returns>
        public DbCommand GetInsertHashBinMinHashCommand(HashBinMinHash hashBinMinHash, DbConnection connection)
        {
            DbCommand command = GetStoredProcedureCommand(SP_INSERT_MINHASH_HASHBIN, connection);
            DbParameter param = command.CreateParameter();
            param.ParameterName = PARAM_HASHBIN_MINHASH_HASHBIN;
            param.DbType = DbType.Int64;
            param.Value = hashBinMinHash.Hashbin;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = PARAM_HASHBIN_MINHASH_HASHTABLE;
            param.DbType = DbType.Int32;
            param.Value = hashBinMinHash.HashTable;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = PARAM_HASHBIN_MINHASH_TRACK_ID;
            param.DbType = DbType.Int32;
            param.Value = hashBinMinHash.TrackId;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = PARAM_HASHBIN_MINHASH_FINGERPRINT;
            param.DbType = DbType.Int32;
            param.Value = hashBinMinHash.HashedFingerprint;
            command.Parameters.Add(param);

            return command;
        }
Пример #4
0
        /// <summary>
        ///   Compute Hash Bins using Min Hash algorithm
        /// </summary>
        private void ComputeHashBinsUsingMinHash()
        {
            List<Track> tracks = _dalManager.ReadTracks(); /*Read all tracks from the database*/
            _pbMinHash.Invoke(new Action(() => /*Progress bar Settings*/
                                         {
                                             _pbMinHash.Minimum = 1;
                                             _pbMinHash.Maximum = tracks.Count;
                                             _pbMinHash.Value = 1;
                                             _pbMinHash.Step = 1;
                                         }));

            MinHash minHash = new MinHash(_permutations);
            for (int index = 0; index < tracks.Count; index++)
            {
                Track track = tracks[index];
                List<Fingerprint> fingerprints;
                try
                {
                    fingerprints = _dalManager.ReadFingerprintsByTrackId(track.Id, 0); /*Read corresponding fingerprints of a specific track*/
                    if (fingerprints == null)
                        continue;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                List<HashBinMinHash> listToInsert = new List<HashBinMinHash>(); /*Generate Min Hash signatures*/
                foreach (Fingerprint fingerprint in fingerprints)
                {
                    int[] hashBins = minHash.ComputeMinHashSignature(fingerprint.Signature); /*For each of the fingerprints*/
                    Dictionary<int, long> hashTable = minHash.GroupMinHashToLSHBuckets(hashBins, _numberofgroupsminhash, _numberofhashesperkeyminhash);
                    foreach (KeyValuePair<int, long> item in hashTable)
                    {
                        HashBinMinHash hash = new HashBinMinHash(-1, item.Value, item.Key, track.Id, fingerprint.Id);
                        listToInsert.Add(hash);
                    }
                }
                _dalManager.InsertHashBin(listToInsert); /*Actual insert*/
                _pbMinHash.Invoke(new Action(() => _pbMinHash.PerformStep()));
            }
        }
        public void GetInsertHashBinMinHashCommandTest()
        {
            string name = MethodBase.GetCurrentMethod().Name;

            DaoStoredProcedureBuilder target = new DaoStoredProcedureBuilder();
            HashBinMinHash hashBinMinHash = new HashBinMinHash(0, 125, 10, 0, 0);

            DbConnection connection = Dbf.CreateConnection();
            IDbCommand actual = target.GetInsertHashBinMinHashCommand(hashBinMinHash, connection);

            Assert.AreEqual(SP_INSERT_MINHASH_HASHBIN, actual.CommandText);
            Assert.AreEqual(CommandType.StoredProcedure, actual.CommandType);
            Assert.IsNotNull(actual.Connection);
            Assert.AreEqual(ConnectionState.Closed, actual.Connection.State);
            Assert.AreEqual(4, actual.Parameters.Count);
        }
Пример #6
0
 /// <summary>
 ///   Hash Fingerprints using Min-Hash algorithm
 /// </summary>
 /// <param name = "listOfFingerprintsToHash">List of fingerprints already inserted in the database</param>
 /// <param name = "track">Track of the corresponding fingerprints</param>
 /// <param name = "hashTables">Number of hash tables</param>
 /// <param name = "hashKeys">Number of hash keys</param>
 private void HashFingerprintsUsingMinHash(IEnumerable<Fingerprint> listOfFingerprintsToHash, Track track, int hashTables, int hashKeys)
 {
     List<HashBinMinHash> listToInsert = new List<HashBinMinHash>();
     MinHash minHash = new MinHash(_permStorage);
     foreach (Fingerprint fingerprint in listOfFingerprintsToHash)
     {
         int[] hashBins = minHash.ComputeMinHashSignature(fingerprint.Signature); //Compute Min Hashes
         Dictionary<int, long> hashTable = minHash.GroupMinHashToLSHBuckets(hashBins, hashTables, hashKeys);
         foreach (KeyValuePair<int, long> item in hashTable)
         {
             HashBinMinHash hash = new HashBinMinHash(-1, item.Value, item.Key, track.Id, fingerprint.Id);
             listToInsert.Add(hash);
         }
     }
     _dalManager.InsertHashBin(listToInsert); //Insert 
 }
 public void InsertReadHashBinMinHashTest()
 {
     string name = MethodBase.GetCurrentMethod().Name;
     Album album = dalManager.ReadUnknownAlbum();
     Track track = new Track(0, name, name, album.Id);
     dalManager.InsertTrack(track);
     Fingerprint finger = new Fingerprint(0, GenericFingerprint, track.Id, 0);
     dalManager.InsertFingerprint(finger);
     const long Hashbin = 100000;
     const int Hashtable = 20;
     HashBinMinHash hashbinminhash = new HashBinMinHash(0, Hashbin, Hashtable, track.Id, finger.Id);
     dalManager.InsertHashBin(hashbinminhash);
     Dictionary<int, List<HashBinMinHash>> result =
         dalManager.ReadFingerprintsByHashBucketAndHashTableLSH(new[] { Hashbin }, new[] { Hashtable });
     Assert.IsNotNull(result);
     Assert.AreEqual(1, result.Count);
     Assert.AreEqual(true, result.ContainsKey(finger.Id));
     Assert.AreEqual(1, result[finger.Id].Count);
     Assert.AreEqual(hashbinminhash.Id, result[finger.Id][0].Id);
     dalManager.DeleteTrack(track.Id);
 }