Beispiel #1
0
        /// <summary>
        /// Takes in the words of a mnemonic sentence and it rebuilds the word index, having the valid index allows us to hot swap between languages/word lists :)
        /// </summary>
        /// <param name="wordsInMnemonicSentence">
        /// a string array containing each word in the mnemonic sentence
        /// </param>
        /// <returns>
        /// The word index that can be used to build the mnemonic sentence
        /// </returns>
        private List <int> RebuildWordIndexes(string[] wordsInMnemonicSentence)
        {
            List <int> wordIndexList = new List <int>();
            string     langName      = CEmptyString;

            Wordlist wordlist;

            switch (this.language)
            {
            case Language.English:
                wordlist = new English();
                langName = "English";
                break;

            case Language.Japanese:
                wordlist = new Japanese();
                langName = "Japanese";
                break;

            case Language.Spanish:
                wordlist = new Spanish();
                langName = "Spanish";
                break;

            case Language.ChineseSimplified:
                wordlist = new ChineseSimplified();
                langName = "Chinese Simplified";
                break;

            case Language.ChineseTraditional:
                wordlist = new ChineseTraditional();
                langName = "Chinese Traditional";
                break;

            case Language.French:
                wordlist = new French();
                langName = "French";
                break;

            default:
                wordlist = new English();
                langName = "English";
                break;
            }

            foreach (string s in wordsInMnemonicSentence)
            {
                int idx = -1;

                if (!wordlist.WordExists(s, out idx))
                {
                    throw new MnemonicException("Word " + s + " is not in the wordlist for language " + langName + " cannot continue to rebuild entropy from wordlist");
                }

                wordIndexList.Add(idx);
            }

            return(wordIndexList);
        }
Beispiel #2
0
        public void TestResumenListaConUnCuadradoEsp()
        {
            var cuadrados = new List <IFormaGeometrica> {
                new Cuadrado(5)
            };

            var resumen = Spanish.Imprimir(cuadrados);

            Assert.AreEqual("<h1>Reporte de Formas</h1>1 Cuadrado | Área 25 | Perímetro 20 <br/>TOTAL:<br/>1 formas Perímetro 20 Área 25", resumen);
        }
Beispiel #3
0
 public async Task AddQuote(Spanish item)
 {
     try
     {
         await _context.Spanish.InsertOneAsync(item);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #4
0
        /// <summary>
        /// Uses the Wordlist Index to create a sentence ow words provided by the wordlist of this objects language attribute
        /// </summary>
        /// <returns>A sentence of words</returns>
        private string GetMnemonicSentence()
        {
            // trap for words that were not in the word list when built. If custom words were used, we will not support the rebuild as we don't have the words
            if (this.wordIndexList.Contains(-1))
            {
                throw new MnemonicException("the wordlist index contains -1 which means words were used in the mnemonic sentence that cannot be found in the wordlist and the index to sentence feature cannot be used. Perhaps a different language wordlist is needed?");
            }

            string   mSentence = CEmptyString;
            Wordlist wordlist;

            switch (this.language)
            {
            case Language.English:
                wordlist = new English();
                break;

            case Language.Japanese:
                wordlist = new Japanese();
                break;

            case Language.Spanish:
                wordlist = new Spanish();
                break;

            case Language.ChineseSimplified:
                wordlist = new ChineseSimplified();
                break;

            case Language.ChineseTraditional:
                wordlist = new ChineseTraditional();
                break;

            case Language.French:
                wordlist = new French();
                break;

            default:
                wordlist = new English();
                break;
            }

            for (int i = 0; i < this.wordIndexList.Count; i++)
            {
                mSentence += wordlist.GetWordAtIndex(this.wordIndexList[i]);
                if (i + 1 < this.wordIndexList.Count)
                {
                    mSentence += " ";
                }
            }

            return(mSentence);
        }
Beispiel #5
0
 public bool DoesContainText(string text)
 {
     return(!string.IsNullOrEmpty(French) && French.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
            !string.IsNullOrEmpty(English) && English.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
            !string.IsNullOrEmpty(Portugese) && Portugese.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
            !string.IsNullOrEmpty(Russish) && Russish.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
            !string.IsNullOrEmpty(German) && German.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
            !string.IsNullOrEmpty(Japanish) && Japanish.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
            !string.IsNullOrEmpty(Dutsh) && Dutsh.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 |
            !string.IsNullOrEmpty(Spanish) && Spanish.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
            !string.IsNullOrEmpty(Italian) && Italian.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1);
 }
Beispiel #6
0
 /// <summary>
 /// Clears all string lists within this container.
 /// </summary>
 public void Clear()
 {
     English.Clear();
     Japanese.Clear();
     German.Clear();
     French.Clear();
     Spanish.Clear();
     Italian.Clear();
     Korean.Clear();
     Chinese.Clear();
     Portuguese.Clear();
 }
Beispiel #7
0
        public void TestResumenTrapeciosEsp()
        {
            var formas = new List <IFormaGeometrica>
            {
                new TrapecioRectangulo(8, 5, 4),      // a = 26, p = 22
                new TrapecioRectangulo(6, 2, 3),      // a = 12, p = 16
                new TrapecioRectangulo(9.5m, 6.5m, 4) // a = 32, p = 25
            };

            var resumen = Spanish.Imprimir(formas);

            Assert.AreEqual("<h1>Reporte de Formas</h1>3 Trapecios | Área 70 | Perímetro 63 <br/>TOTAL:<br/>3 formas Perímetro 63 Área 70", resumen);
        }
Beispiel #8
0
        public bool DoesContainText(string text, Languages lang)
        {
            if (lang == Languages.All)
            {
                return(DoesContainText(text));
            }

            return((lang == Languages.French && !string.IsNullOrEmpty(French) && French.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1) ||
                   (lang == Languages.English && !string.IsNullOrEmpty(English) && English.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1) ||
                   (lang == Languages.Portugese && !string.IsNullOrEmpty(Portugese) && Portugese.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1) ||
                   (lang == Languages.Russish && !string.IsNullOrEmpty(Russish) && Russish.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1) ||
                   (lang == Languages.German && !string.IsNullOrEmpty(German) && German.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1) ||
                   (lang == Languages.Japanish && !string.IsNullOrEmpty(Japanish) && Japanish.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1) ||
                   (lang == Languages.Dutsh && !string.IsNullOrEmpty(Dutsh) && Dutsh.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1) ||
                   (lang == Languages.Spanish && !string.IsNullOrEmpty(Spanish) && Spanish.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1) ||
                   (lang == Languages.Italian && !string.IsNullOrEmpty(Italian) && Italian.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1));
        }
Beispiel #9
0
        public void TestResumenListaConMasTiposEsp()
        {
            var formas = new List <IFormaGeometrica>
            {
                new Cuadrado(5),
                new Circulo(3),
                new TrianguloEquilatero(4),
                new Cuadrado(2),
                new TrianguloEquilatero(9),
                new Circulo(2.75m),
                new TrianguloEquilatero(4.2m)
            };

            var resumen = Spanish.Imprimir(formas);

            Assert.AreEqual(
                "<h1>Reporte de Formas</h1>2 Cuadrados | Área 29 | Perímetro 28 <br/>2 Círculos | Área 13,01 | Perímetro 18,06 <br/>3 Triángulos | Área 49,64 | Perímetro 51,6 <br/>TOTAL:<br/>7 formas Perímetro 97,66 Área 91,65",
                resumen);
        }
        public static ILanguage GetLanguage(ELanguages eLanguages)
        {
            ILanguage _iLanguage;

            switch (eLanguages)
            {
            case ELanguages.English:
                _iLanguage = new English();
                break;

            case ELanguages.Spanish:
                _iLanguage = new Spanish();
                break;

            default:
                throw new Exception("Unsupported Language.");
            }

            return(_iLanguage);
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            Console.Title        = "Object Oriented Design Assignment 7:  Adapter Pattern";
            Console.WindowHeight = 30;
            Console.WindowWidth  = 50;
            //Create Language objects:
            HumanLanguage   English = new English();
            HumanLanguage   French  = new French();
            HumanLanguage   Spanish = new Spanish();
            MachineLanguage Binary  = new Binary();

            //This is the adapter for the binary language:
            HumanLanguage BinaryAdapter = new BinaryAdapter(Binary);

            Console.WriteLine("*************************************");
            Console.WriteLine("*************************************");
            Console.WriteLine("*  Welcome to the Speech Simulator  *");
            Console.WriteLine("*  Listed below are the words for   *");
            Console.WriteLine("*  'Hello' in various languages     *");
            Console.WriteLine("*************************************");
            Console.WriteLine("*************************************");
            Console.WriteLine();

            //Print out hello in each language
            Console.WriteLine("English:  ");
            English.sayHello();
            Console.WriteLine();
            Console.WriteLine("French:  ");
            French.sayHello();
            Console.WriteLine();
            Console.WriteLine("Spanish:  ");
            Spanish.sayHello();
            Console.WriteLine();

            //The adapter makes it possible for the binary object to sayHello:
            Console.WriteLine("Machine:  ");
            BinaryAdapter.sayHello();
            Console.ReadKey();
        }
Beispiel #12
0
        private static void UseSpecification()
        {
            var spec1 = new Spanish();
            var spec2 = new English();

            var spanish = 0;
            var english = 0;

            foreach (var customer in _customerDao.ListOfCustomers)
            {
                if (spec1.IsSatisfiedBy(customer))
                {
                    spanish++;
                }
                else if (spec2.IsSatisfiedBy(customer))
                {
                    english++;
                }
            }

            Console.WriteLine($"Total english = {english} and total spanish = {spanish}");
        }
 internal void LanguagePacksReadFromCache(Halo2.CacheFile c)
 {
     if (!English.IsLoaded)
     {
         English.ReadFromCache(c);
     }
     if (!Japanese.IsLoaded)
     {
         Japanese.ReadFromCache(c);
     }
     if (!German.IsLoaded)
     {
         German.ReadFromCache(c);
     }
     if (!French.IsLoaded)
     {
         French.ReadFromCache(c);
     }
     if (!Spanish.IsLoaded)
     {
         Spanish.ReadFromCache(c);
     }
     if (!Italian.IsLoaded)
     {
         Italian.ReadFromCache(c);
     }
     if (!Korean.IsLoaded)
     {
         Korean.ReadFromCache(c);
     }
     if (!Chinese.IsLoaded)
     {
         Chinese.ReadFromCache(c);
     }
     if (!Portuguese.IsLoaded)
     {
         Portuguese.ReadFromCache(c);
     }
 }
        static void Main(string[] args)
        {
            Employee Jack = new Employee();

            Jack.SetFullName("Jack Jackson");
            Jack.SetSalary(300000);
            //Employee Jack = new Employee("Jack Jackson", 300000);

            //inherited classes
            ITExecutives Jill = new ITExecutives();

            Jill.SetFullName("Jill White");
            Jill.SetSalary(400000);

            // SalesExecutive John = new SalesExecutive();
            //wont work since no parameterless ctor exists

            SalesExecutive John = new SalesExecutive("John Parker", 300000, 120);

            John.Sales = 20;

            EmployeeInfo(Jack);
            EmployeeInfo(Jill);
            EmployeeInfo(John);

            ///////////////////////////

            //LivingBeing x = new LivingBeing();

            Humans  human = new Humans();
            Cow     cow   = new Cow();
            Cat     cat   = new Cat();
            French  frman = new French();
            Spanish spman = new Spanish();

            List <LivingBeing> livingBeings = new List <LivingBeing>();

            livingBeings.Add(human);
            livingBeings.Add(cat);
            livingBeings.Add(cow);
            livingBeings.Add(frman);
            livingBeings.Add(spman);

            Talk(livingBeings);
            ///////////

            //casting


            Car Nissan = new Car {
                RegNos = 122, TopSpeed = 120
            };
            Car Audi = new Car {
                RegNos = 221, TopSpeed = 170
            };
            Truck Tata = new Truck {
                RegNos = 1011, IsLoaded = false, NoOfTyres = 10
            };
            Truck Mazda = new Truck {
                RegNos = 50501, IsLoaded = true, NoOfTyres = 8
            };
            List <Vehicle> vehicles = new List <Vehicle>
            {
                Nissan,
                Audi,
                Tata,
                Mazda
            };

            VehicleGarrage(vehicles);
            Console.ReadKey();
        }
Beispiel #15
0
        /////// <summary>
        /////// An asynchronous static method to create a new BIP39 from random entropy. The random entropy creation is CPU intensive so is run in its own Task and we await as per async pattern.
        /////// </summary>
        /////// <param name="entropySize">The size in bits of the entropy to be created</param>
        /////// <param name="passphrase">The optional passphrase. Please ensure NFKD Normalized, Empty string will be used if not provided as per spec</param>
        /////// <param name="language">The optional language. If no language is provided English will be used</param>
        /////// <returns>A BIP39 object</returns>
        ////public static async Task<BIP39> GetBIP39Async(int entropySize = cMinimumEntropyBits, string passphrase = cEmptyString, Language language = Language.English)
        ////{
        ////    byte[] entropyBytes = await Utilities.GetRandomBytesAsync(entropySize / cBitsInByte);
        ////    return new BIP39(entropyBytes, passphrase, language);
        ////}

        /// <summary>
        /// Takes in a string[] of words and detects the language that has the highest number of matching words.
        /// </summary>
        /// <param name="words">
        /// The words of which you wish to derive a language
        /// </param>
        /// <returns>
        /// The best attempt at a guessed Language
        /// </returns>
        public static Language AutoDetectLanguageOfWords(string[] words)
        {
            English            eng = new English();
            Japanese           jp  = new Japanese();
            Spanish            es  = new Spanish();
            French             fr  = new French();
            ChineseSimplified  cnS = new ChineseSimplified();
            ChineseTraditional cnT = new ChineseTraditional();

            List <int> languageCount = new List <int>(new[] { 0, 0, 0, 0, 0, 0 });
            int        index;

            foreach (string s in words)
            {
                if (eng.WordExists(s, out index))
                {
                    // english is at 0
                    languageCount[0]++;
                }

                if (jp.WordExists(s, out index))
                {
                    // japanese is at 1
                    languageCount[1]++;
                }

                if (es.WordExists(s, out index))
                {
                    // spanish is at 2
                    languageCount[2]++;
                }

                if (cnS.WordExists(s, out index))
                {
                    // chinese simplified is at 3
                    languageCount[3]++;
                }

                if (cnT.WordExists(s, out index) && !cnS.WordExists(s, out index))
                {
                    // chinese traditional is at 4
                    languageCount[4]++;
                }

                if (fr.WordExists(s, out index))
                {
                    // french is at 5
                    languageCount[5]++;
                }
            }

            // no hits found for any language unknown
            if (languageCount.Max() == 0)
            {
                return(Language.Unknown);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 0)
            {
                return(Language.English);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 1)
            {
                return(Language.Japanese);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 2)
            {
                return(Language.Spanish);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 3)
            {
                if (languageCount[4] > 0)
                {
                    // has traditional characters so not simplified but instead traditional
                    return(Language.ChineseTraditional);
                }

                return(Language.ChineseSimplified);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 4)
            {
                return(Language.ChineseTraditional);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 5)
            {
                return(Language.French);
            }

            return(Language.Unknown);
        }
Beispiel #16
0
        /// <summary>
        /// This is run each time the app runs, but won't do anything after the first run.
        /// </summary>
        public void CreateDatabase()
        {
            try
            {
                if (!File.Exists(Settings.DatabaseFile))
                {
                    string categoriesSql = "CREATE TABLE \"categories\" (" +
                                           "\"id\" INTEGER PRIMARY KEY AUTOINCREMENT," +
                                           "\"name\" TEXT NOT NULL," +
                                           "\"active\" INTEGER DEFAULT 0," +
                                           "\"inbuilt\" INTEGER DEFAULT 0)";

                    string questionsSql = "CREATE TABLE questions (" +
                                          "\"id\" INTEGER PRIMARY KEY AUTOINCREMENT," +
                                          "\"categoryid\" INTEGER," +
                                          "\"title\" TEXT," +
                                          "\"answer\" TEXT," +
                                          "\"order\" INTEGER DEFAULT 0," +
                                          "\"lastasked\" INTEGER DEFAULT 0," +
                                          "\"nextaskon\" INTEGER DEFAULT 0," +
                                          "\"previousinterval\" INTEGER DEFAULT 0," +
                                          "\"interval\" INTEGER DEFAULT 0," +
                                          "\"askcount\" INTEGER DEFAULT 0," +
                                          "\"responsequality\" INTEGER DEFAULT 0," +
                                          "\"easinessfactor\" REAL DEFAULT 0)";

                    // Create the file
                    SqliteConnection.CreateFile(Settings.DatabaseFile);

                    // And the schema
                    using (SqliteConnection connection = new SqliteConnection(Settings.DatabaseConnection))
                    {
                        connection.Open();
                        using (SqliteCommand command = new SqliteCommand(connection))
                        {
                            command.CommandText = categoriesSql;
                            command.ExecuteNonQuery();

                            command.CommandText = questionsSql;
                            command.ExecuteNonQuery();

                            // Default category
                            command.CommandText = Default.Sql();
                            command.ExecuteNonQuery();

#if GERMAN
                            command.CommandText = German.Sql();
                            command.ExecuteNonQuery();
#elif SPANISH
                            command.CommandText = Spanish.Sql();
                            command.ExecuteNonQuery();
#elif FRENCH
                            command.CommandText = French.Sql();
                            command.ExecuteNonQuery();
#endif
                        }
                    }
                }
            }
            catch (IOException ex)
            {
                Logger.Fatal("Unable to delete the database file {0}: \n{1}", Settings.DatabaseFile, ex);
                throw;
            }
            catch (SqliteException ex)
            {
                Logger.Fatal("Unable to create the database: \n{0}", ex);
                throw;
            }
        }
Beispiel #17
0
        public static Language AutoDetectLanguage(string[] words)
        {
            var languageCount = new List <int>(new[] { 0, 0, 0, 0, 0, 0, 0 });
            int index;

            foreach (var s in words)
            {
                if (English.WordExists(s, out index))
                {
                    //english is at 0
                    languageCount[0]++;
                }

                if (Japanese.WordExists(s, out index))
                {
                    //japanese is at 1
                    languageCount[1]++;
                }

                if (Spanish.WordExists(s, out index))
                {
                    //spanish is at 2
                    languageCount[2]++;
                }

                if (ChineseSimplified.WordExists(s, out index))
                {
                    //chinese simplified is at 3
                    languageCount[3]++;
                }

                if (ChineseTraditional.WordExists(s, out index) && !ChineseSimplified.WordExists(s, out index))
                {
                    //chinese traditional is at 4
                    languageCount[4]++;
                }

                if (French.WordExists(s, out index))
                {
                    languageCount[5]++;
                }

                if (PortugueseBrazil.WordExists(s, out index))
                {
                    //portuguese_brazil is at 6
                    languageCount[6]++;
                }
            }

            //no hits found for any language unknown
            if (languageCount.Max() == 0)
            {
                return(Language.Unknown);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 0)
            {
                return(Language.English);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 1)
            {
                return(Language.Japanese);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 2)
            {
                return(Language.Spanish);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 3)
            {
                if (languageCount[4] > 0)
                {
                    //has traditional characters so not simplified but instead traditional
                    return(Language.ChineseTraditional);
                }

                return(Language.ChineseSimplified);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 4)
            {
                return(Language.ChineseTraditional);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 5)
            {
                return(Language.French);
            }

            if (languageCount.IndexOf(languageCount.Max()) == 6)
            {
                return(Language.PortugueseBrazil);
            }

            return(Language.Unknown);
        }
Beispiel #18
0
        public async Task <IActionResult> Post([FromBody] Spanish value)
        {
            await _spanishQManager.AddQuote(value);

            return(Ok());
        }
Beispiel #19
0
        public static Language AutoDetectLanguage(string[] words)
        {
            List <int> languageCount = new List <int>(new int[] { 0, 0, 0, 0, 0, 0, 0 });
            int        index;

            foreach (string s in words)
            {
                if (Japanese.WordExists(s, out index))
                {
                    languageCount[1]++;
                }
                if (Spanish.WordExists(s, out index))
                {
                    //spanish is at 2
                    languageCount[2]++;
                }
                if (ChineseSimplified.WordExists(s, out index))
                {
                    languageCount[3]++;
                }
                if (French.WordExists(s, out index))
                {
                    languageCount[5]++;
                }
            }
            if (languageCount.Max() == 0)
            {
                return(Language.Unknown);
            }
            if (languageCount.IndexOf(languageCount.Max()) == 0)
            {
                return(Language.English);
            }
            else if (languageCount.IndexOf(languageCount.Max()) == 1)
            {
                return(Language.Japanese);
            }
            else if (languageCount.IndexOf(languageCount.Max()) == 2)
            {
                return(Language.Spanish);
            }
            else if (languageCount.IndexOf(languageCount.Max()) == 3)
            {
                if (languageCount[4] > 0)
                {
                    return(Language.ChineseTraditional);
                }
                return(Language.ChineseSimplified);
            }
            else if (languageCount.IndexOf(languageCount.Max()) == 4)
            {
                return(Language.ChineseTraditional);
            }
            else if (languageCount.IndexOf(languageCount.Max()) == 5)
            {
                return(Language.French);
            }
            else if (languageCount.IndexOf(languageCount.Max()) == 6)
            {
                return(Language.PortugueseBrazil);
            }
            return(Language.Unknown);
        }
Beispiel #20
0
 public void TestResumenListaVaciaEsp()
 {
     Assert.AreEqual("<h1>Lista vacía de formas!</h1>", Spanish.Imprimir(new List <IFormaGeometrica>()));
 }
Beispiel #21
0
 public SpanishToEnglish(Spanish _spanish)
 {
     this._spanish = _spanish;
 }