Esempio n. 1
0
        public static void ExportCSV(string filenameToSave, Array column1, Array column2)
        {
            if (column1.Length != column2.Length)
            {
                return;
            }

            var arr = new object[column1.Length][];

            int count = 1;

            for (int i = 0; i < column1.Length; i++)
            {
                arr[i] = new object[3] {
                    count,
                    column1.GetValue(i),
                    column2.GetValue(i)
                };
                count++;
            }
            ;

            var csv = new CSVWriter(filenameToSave);

            csv.Write(arr);
        }
Esempio n. 2
0
        public static void ExportCSV(string filenameToSave, Array data, int length = 0)
        {
            if (length == 0 || length > data.Length)
            {
                length = data.Length;
            }

            var arr = new object[length][];

            int count = 1;

            for (int i = 0; i < length; i++)
            {
                arr[i] = new object[2] {
                    count,
                    data.GetValue(i)
                };
                count++;
            }
            ;

            var csv = new CSVWriter(filenameToSave);

            csv.Write(arr);
        }
Esempio n. 3
0
        public static void exportCSV(string filenameToSave, Array column1, Array column2, Array column3, Array column4, Array column5, Array column6)
        {
            if (column1.Length != column2.Length ||
                column1.Length != column3.Length ||
                column1.Length != column4.Length ||
                column1.Length != column5.Length ||
                column1.Length != column6.Length)
            {
                return;
            }

            object[][] arr = new object[column1.Length][];

            int count = 1;

            for (int i = 0; i < column1.Length; i++)
            {
                arr[i] = new object[7] {
                    count,
                    column1.GetValue(i),
                    column2.GetValue(i),
                    column3.GetValue(i),
                    column4.GetValue(i),
                    column5.GetValue(i),
                    column6.GetValue(i),
                };
                count++;
            }
            ;

            CSVWriter csv = new CSVWriter(filenameToSave);

            csv.Write(arr);
        }
Esempio n. 4
0
        public static void exportCSV(string filenameToSave, double[][] data)
        {
            object[][] arr = new object[data.Length][];

            for (int i = 0; i < data.Length; i++)
            {
                arr[i] = new object[data[i].Length];
                for (int j = 0; j < data[i].Length; j++)
                {
                    arr[i][j] = data[i][j];
                }
            };

            CSVWriter csv = new CSVWriter(filenameToSave);
            csv.Write(arr);
        }
Esempio n. 5
0
        public static void ExportCSV(string filenameToSave, double[][] data)
        {
            var arr = new object[data.Length][];

            for (int i = 0; i < data.Length; i++)
            {
                arr[i] = new object[data[i].Length];
                for (int j = 0; j < data[i].Length; j++)
                {
                    arr[i][j] = data[i][j];
                }
            }
            ;

            var csv = new CSVWriter(filenameToSave);

            csv.Write(arr);
        }
Esempio n. 6
0
        public static void exportCSV(string filenameToSave, Array column1, Array column2)
        {
            if (column1.Length != column2.Length) return;

            object[][] arr = new object[column1.Length][];

            int count = 1;
            for (int i = 0; i < column1.Length; i++)
            {
                arr[i] = new object[3] {
                    count,
                    column1.GetValue(i),
                    column2.GetValue(i)
                };
                count++;
            };

            CSVWriter csv = new CSVWriter(filenameToSave);
            csv.Write(arr);
        }
Esempio n. 7
0
        public static void exportCSV(string filenameToSave, Array data, int length=0)
        {
            if (length == 0) {
                length = data.Length;
            }

            object[][] arr = new object[length][];

            int count = 1;
            for (int i = 0; i < length; i++)
            {
                arr[i] = new object[2] {
                    count,
                    data.GetValue(i)
                };
                count++;
            };

            CSVWriter csv = new CSVWriter(filenameToSave);
            csv.Write(arr);
        }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            string inputCSVFile  = null;
            string outputCSVFile = null;
            bool   doTest        = false;

            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }
            else if (args.Length == 1)
            {
                if (args[0].Contains("test"))
                {
                    doTest = true;
                }
            }
            else if (args.Length == 2)
            {
                inputCSVFile  = args[0];
                outputCSVFile = args[1];
            }

            if (doTest)
            {
                TestDoubleMethaphone();
                return;
            }

            if (!File.Exists(inputCSVFile))
            {
                Console.Error.WriteLine("Could not find specified input file");
                return;
            }

            // define a list that can hold entries with identical keys
            var    nameResults      = new List <KeyValuePair <string, string> >();
            String text             = File.ReadAllText(inputCSVFile, Encoding.Default);
            var    stringSeparators = new string[] { "\r\n" };
            var    namesArray       = text.Split(stringSeparators, StringSplitOptions.None);

            // encode each name
            foreach (var name in namesArray)
            {
                EncodeAndStore(name, nameResults);
            }

            // sort names by encoded value
            var sortedList = from s in nameResults
                             orderby s.Key
                             select s;

            // build jagged array that can easily be written as csv
            var output  = new object[sortedList.Count()][];
            int counter = 0;

            foreach (var name in sortedList)
            {
                output[counter]    = new object[2];
                output[counter][0] = name.Key;
                output[counter][1] = name.Value;
                counter++;
            }

            CSVWriter csvWriter = new CommonUtils.CSVWriter(outputCSVFile, ',');

            csvWriter.Write(output);
        }
Esempio n. 9
0
        /// <summary>
        ///   Create fingerprints/min-hash signatures/LSH buckets and insert them in underlying storage
        /// </summary>
        /// <param name = "files">Files to be processed</param>
        /// <param name = "audioProxy">Audio proxy used in processing</param>
        /// <param name = "queryStride">Stride between 2 consecutive fingerprints on query</param>
        /// <param name = "creationalStride">Stride between 2 consecutive fingerprints on creation</param>
        /// <param name = "mintracklen">Minimum track length</param>
        /// <param name = "maxtracklen">Maximum track length</param>
        /// <param name = "milliSecondsToProcess">Number of milliseconds to process</param>
        /// <param name = "startMillisecond">Start processing at a specific millisecond</param>
        /// <param name = "hashTables">Number of hash-tables used in LSH decomposition</param>
        /// <param name = "hashKeys">Number of Min Hash keys per LSH table</param>
        /// <param name = "trackProcessed">Invoked once the track is processed</param>
        /// <returns>List of processed tracks</returns>
        public List<Track> ProcessTracks(List<string> files, BassProxy audioProxy, IStride queryStride, IStride creationalStride,
                                  int mintracklen, int maxtracklen,
                                  int milliSecondsToProcess, int startMillisecond, int hashTables, int hashKeys, Action<Track> trackProcessed)
        {
            List<Track> tracks = new List<Track>();
            _threadCounts++;

            foreach (string file in files) //filter files that can be processed
            {
                if (_aborted) break;

                Track track = GetTrack(mintracklen, maxtracklen, file, audioProxy);
                if (track == null)
                    continue; /*track is not eligible because of min/max parameters*/
                //create spectrogram of the file
                float[][] logSpectrum = null;
                try
                {
                    //try creating the spectrum from a file
                    logSpectrum = _manager.CreateLogSpectrogram(audioProxy, track.Path, milliSecondsToProcess, startMillisecond);
                }
                catch (Exception ex)
                {
                    if (ex is ThreadAbortException)
                        throw;
                    /*the file might be corrupted or missing*/
                    continue; /*Continue processing even if creation of the spectrogram failed*/
                }
                _storage.InsertTrack(track); /*Insert track into the storage*/
                /*Create fingerprints that will be used as initial fingerprints to be queried*/
                List<bool[]> dbFingers = _manager.CreateFingerprints(logSpectrum, creationalStride);
                /*Get fingerprint's hash signature, and associate it to a specific track*/
                List<HashSignature> creationalsignatures = GetSignatures(dbFingers, track, hashTables, hashKeys);
                foreach (HashSignature hash in creationalsignatures)
                {
                    _storage.InsertHash(hash, HashType.Creational);
                    /*Set this hashes as also the query hashes*/
                    _storage.InsertHash(hash, HashType.Query);
                }
                /*Create fingerprints for query*/
                List<bool[]> queryFingers = _manager.CreateFingerprints(logSpectrum, queryStride); /*Create fingerprints*/
                List<HashSignature> querysignatures = GetSignatures(queryFingers, track, hashTables, hashKeys);

                // ***** PIN TODO: CHANGE THIS
                object[][] arr = new object[querysignatures.Count][];
                int count = 0;
                foreach (HashSignature hash in querysignatures) {
                    _storage.InsertHash(hash, HashType.Query); /*Insert hash-buckets into hash-tables*/

                    String signatureText = "{";
                    for (int s = 0; s < hash.Signature.Length; s++) {
                        signatureText += hash.Signature[s];
                        signatureText += " ";
                    }
                    signatureText += "}";

                    arr[count++] = new object[5] {
                        hash.Id,
                        hash.Track.Title,
                        hash.Track.Artist,
                        hash.Track.TrackLength,
                        signatureText
                    };
                }
                String filenameToSave = String.Format("C:\\{0}-hash-buckets.txt", System.IO.Path.GetFileNameWithoutExtension(file));
                CSVWriter csv = new CSVWriter(filenameToSave);
                csv.Write(arr);
                // ***** end PIN

                if (trackProcessed != null)
                    trackProcessed.Invoke(track);
                tracks.Add(track);
            }
            _threadCounts--;
            return tracks;
        }
Esempio n. 10
0
        public static void Main(string[] args)
        {
            string inputCSVFile = null;
            string outputCSVFile = null;
            bool doTest = false;

            if (args.Length == 0) {
                PrintUsage();
                return;
            } else if (args.Length == 1) {
                if (args[0].Contains("test")) {
                    doTest = true;
                }
            } else if (args.Length == 2) {
                inputCSVFile = args[0];
                outputCSVFile = args[1];
            }

            if (doTest) {
                TestDoubleMethaphone();
                return;
            }

            if (!File.Exists(inputCSVFile)) {
                Console.Error.WriteLine("Could not find specified input file");
                return;
            }

            // define a list that can hold entries with identical keys
            var nameResults = new List<KeyValuePair<string, string>>();
            String text = File.ReadAllText(inputCSVFile, Encoding.Default);
            var stringSeparators = new string[] { "\r\n" };
            var namesArray = text.Split(stringSeparators, StringSplitOptions.None);

            // encode each name
            foreach (var name in namesArray) {
                EncodeAndStore(name, nameResults);
            }

            // sort names by encoded value
            var sortedList = from s in nameResults
                orderby s.Key
                select s;

            // build jagged array that can easily be written as csv
            var output = new object[sortedList.Count()][];
            int counter = 0;
            foreach (var name in sortedList) {
                output[counter] = new object[2];
                output[counter][0] = name.Key;
                output[counter][1] = name.Value;
                counter++;
            }

            CSVWriter csvWriter = new CommonUtils.CSVWriter(outputCSVFile, ',');
            csvWriter.Write(output);
        }