示例#1
0
        public void Normalize()
        {
            var i   = 0;
            var per = 0;

            while (i < Digits.Count)
            {
                Digits[i] += per;
                per        = Digits[i] / Base;
                if (per > 0)
                {
                    Digits[i] = Digits[i] % Base;
                }
                i++;
            }
            while (per > 0)
            {
                var temp = per / Base;
                if (temp > 0)
                {
                    Digits.Add(per % Base);
                    per = temp;
                }
                else
                {
                    Digits.Add(per);
                }
            }
        }
        public void Find6and0()
        {
            var hs1  = new HashSet <char>(Digits[1].ToCharArray());
            var coll = UniqueValues.Where(uv => uv.Key.Length == 6).ToList();

            foreach (var uv in coll)
            {
                var hs = new HashSet <char>(Digits[8].ToCharArray());
                hs.ExceptWith(uv.Key.ToCharArray());
                char ch = hs.Single();
                if (hs1.Contains(ch))
                {
                    Digits.Add(6, uv.Key);
                    C = ch;
                }
                else if (Digits[9] == uv.Key)
                {
                    // 9 already found
                    ;
                }
                else
                {
                    // D
                    D = ch;
                    Digits.Add(0, uv.Key);
                }
            }
        }
示例#3
0
        void ReadFromFile()
        {
            Console.WriteLine("Pass the full path of a file with data");
            string input;

            do
            {
                input = Console.ReadLine();
                if (!File.Exists(input))
                {
                    Console.WriteLine("The passed file doesn't exist");
                }
            } while (!File.Exists(input));

            TextReader textReader   = new StreamReader(input);
            string     dataFromFile = textReader.ReadToEnd().ToString();

            foreach (char character in dataFromFile)
            {
                if (char.IsDigit(character))
                {
                    Digits.Add(Double.Parse(character.ToString()));
                }
            }
        }
示例#4
0
 public NumberGenerator()
 {
     for (var i = 0; i < 10; i++)
     {
         Digits.Add(i);
     }
     for (var i = 0; i < Constants.MatrixNumberOfColumns * Constants.MatrixNumberOfRows; i++)
     {
         MatrixIndexes.Add(i);
     }
 }
        public void FindUniqueDigits()
        {
            // 1
            var digit = UniqueValues.Single(uv => uv.Key.Length == 2);

            Digits.Add(1, digit.Key);
            // 7
            digit = UniqueValues.SingleOrDefault(uv => uv.Key.Length == 3);
            Digits.Add(7, digit.Key);
            // 4
            digit = UniqueValues.SingleOrDefault(uv => uv.Key.Length == 4);
            Digits.Add(4, digit.Key);
            // 8
            digit = UniqueValues.SingleOrDefault(uv => uv.Key.Length == 7);
            Digits.Add(8, digit.Key);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FreeSpokenDigitsDataset" /> class.
        /// </summary>
        ///
        /// <param name="path">The path where datasets will be stored. If null or empty, the dataset
        /// will be saved on a subfolder called "data" in the current working directory.</param>
        ///
        public FreeSpokenDigitsDataset(string path)
        {
            this.basePath  = path;
            this.webClient = ExtensionMethods.NewWebClient();
            this.Records   = new RecordCollection(this);

            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            foreach (string line in GetFileList())
            {
                if (line.Contains("\"path\":"))
                {
                    string   name   = line.Split(new[] { "path\":" }, StringSplitOptions.None)[1].Trim(' ', '"');
                    string[] parts  = name.Replace(".wav", "").Split('_');
                    var      record = new Record(
                        digit: int.Parse(parts[0]),
                        speaker: parts[1],
                        index: int.Parse(parts[2]));

                    if (this.Records.Contains(record))
                    {
                        throw new Exception();
                    }
                    this.Records.Add(record);
                }
            }

            this.Digits    = new SortedSet <int>();
            this.Speakers  = new SortedSet <string>();
            this.FileNames = new SortedSet <string>();
            foreach (Record r in Records)
            {
                Digits.Add(r.Digit);
                Speakers.Add(r.Speaker);
                FileNames.Add(r.FileName);
            }

            // From README.md: "The test set officially consists of the first 10% of the recordings.
            // Recordings numbered 0-4 (inclusive) are in the test and 5-49 are in the training set."
            Testing  = new RecordCollection(this, Records.Where(x => x.Index >= 0 && x.Index <= 4));
            Training = new RecordCollection(this, Records.Where(x => x.Index >= 5 && x.Index <= 49));
        }
        public void FindGand9()
        {
            var coll = UniqueValues.Where(uv => uv.Key.Length == 6).ToList();

            foreach (var uv in coll)
            {
                var hs  = new HashSet <char>(uv.Key.ToCharArray());
                var chs = new List <char>(Digits[4].ToCharArray());
                chs.Add(A);
                hs.ExceptWith(chs);
                if (hs.Count == 1)
                {
                    G = hs.Single();
                    Digits.Add(9, uv.Key);
                    return;
                }
            }
        }
示例#8
0
 public int this[int i]
 {
     get
     {
         return(Digits.Count > i ? Digits[i] : 0);
     }
     set
     {
         if (Digits.Count < i)
         {
             Digits[i] = value;
         }
         var j = Digits.Count;
         while (j < i)
         {
             Digits.Add(0);
             j++;
         }
         Digits.Add(value);
     }
 }
        public void FindTwoThreeFive()
        {
            var hs1  = new HashSet <char>(Digits[1].ToCharArray());
            var coll = UniqueValues.Where(uv => uv.Key.Length == 5).ToList();

            foreach (var uv in coll)
            {
                var hs = new HashSet <char>(uv.Key.ToCharArray());
                if (hs1.IsProperSubsetOf(hs))
                {
                    Digits.Add(3, uv.Key);
                }
                else if (hs.Contains(C))
                {
                    Digits.Add(2, uv.Key);
                }
                else
                {
                    Digits.Add(5, uv.Key);
                }
            }
        }
示例#10
0
        public BigNumber(string digitString)
        {
            if (digitString == null)
            {
                throw new ArgumentNullException("Parameter shouldn`t be null");
            }

            var reversedString = digitString.Reverse().ToList();


            foreach (var digit in reversedString)
            {
                if (!Char.IsDigit(digit))
                {
                    if (!IsSign(digit))
                    {
                        throw new ArgumentException("Number contains invalid symbols");
                    }
                    SetSigne(digit);
                }

                Digits.Add(ConvertCharToDigit(digit));
            }
        }