Пример #1
0
        public static void Show()
        {
            //new virtual abstract的测试
            Poly.Test();

            //里氏替换原则
            Chinese chinese = new Chinese()
            {
                Name = "chenia",
                Age  = 25,
            };

            chinese.Speak();
            chinese.Sleep();

            Japnese japnese = new Japnese()
            {
                Name = "桥本环奈",
                Age  = 20,
            };

            japnese.Speak();
            japnese.Sleep();

            //Cat不会说话,不能继承people类
            Cat cat = new Cat();
        }
Пример #2
0
        public async Task <IActionResult> AnalyzeAsync(string chinese)
        {
            (Exception inputException, _) = Chinese.ValidateSingleChineseCharacter(chinese, nameof(chinese));
            if (inputException != null)
            {
                this.logger.LogWarning("Received {chinese} is invalid. {message}", chinese, inputException.Message);
#if DEBUG
                return(this.BadRequest(inputException));
#else
                return(this.BadRequest());
#endif
            }

            if (!(this.Request.Headers.TryGetValue(nameof(Chinese), out StringValues codePointString) &&
                  int.TryParse(codePointString.ToString(), out int codePoint) &&
                  codePoint == char.ConvertToUtf32(chinese, 0)))
            {
#if DEBUG
                return(this.BadRequest("Received code point is invalid."));
#else
                return(this.BadRequest());
#endif
            }

            this.logger.LogInformation("Received {chinese} to analyze.", chinese);

            AnalyzeResult[] results;
            Stopwatch       stopwatch = Stopwatch.StartNew();
            try
            {
                if (this.etymologyCache.TryGetValue(codePoint, out AnalyzeResult[] cachedResults))
Пример #3
0
        public static List <string> GetRankedMonsters(string name = "ALL")
        {
            List <string> monsters;
            var           culture = Constants.CultureInfo.TwoLetterISOLanguageName;

            switch (culture)
            {
            case "fr":
                monsters = French.GetRankedMonster(name);
                break;

            case "ja":
                monsters = Japanese.GetRankedMonster(name);
                break;

            case "de":
                monsters = German.GetRankedMonster(name);
                break;

            case "zh":
                monsters = Chinese.GetRankedMonster(name);
                break;

            default:
                monsters = English.GetRankedMonster(name);
                break;
            }

            return(monsters);
        }
Пример #4
0
        Dictionary <Chinese, List <Pinyin> > corrections2dict(List <Tuple <string, bool, string> > corr)
        {
            Dictionary <Chinese, List <Pinyin> > output = new Dictionary <Chinese, List <Pinyin> >();

            foreach (Tuple <string, bool, string> x in corr)
            {
                Chinese chinese = x.Item1;
                Pinyin  pinyin  = CEdictpinyin2pinyin(x.Item3);
                bool    enabled = x.Item2;
                if (enabled)
                {
                    if (output.ContainsKey(chinese))
                    {
                        output[chinese].Add(pinyin);
                    }
                    else
                    {
                        output.Add(chinese, new List <Pinyin>()
                        {
                            pinyin
                        });
                    }
                }
            }

            return(output);
        }
Пример #5
0
        static void Main(string[] args)
        {
            Console.Write("輸入:");
            string  input  = Console.ReadLine();
            Chinese output = int.Parse(input);

            Console.WriteLine($"輸出:{output.Value}");
            Console.ReadLine();
        }
Пример #6
0
 public async Task AddQuote(Chinese item)
 {
     try
     {
         await _context.Chinese.InsertOneAsync(item);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #7
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();
 }
Пример #8
0
        /// <summary>
        /// </summary>
        /// <param name="cultureInfo"> </param>
        public static void Update(CultureInfo cultureInfo)
        {
            var culture = cultureInfo.TwoLetterISOLanguageName;
            ResourceDictionary dictionary;

            if (Constants.Supported.Contains(culture))
            {
                switch (culture)
                {
                case "fr":
                    dictionary = French.Context();
                    break;

                case "ja":
                    dictionary = Japanese.Context();
                    break;

                case "de":
                    dictionary = German.Context();
                    break;

                case "zh":
                    dictionary = Chinese.Context();
                    break;

                case "ru":
                    dictionary = Russian.Context();
                    break;

                case "ko":
                    dictionary = Korean.Context();
                    break;

                default:
                    dictionary = English.Context();
                    break;
                }
            }
            else
            {
                dictionary = English.Context();
            }
            var locale = dictionary.Cast <DictionaryEntry>()
                         .ToDictionary(item => (string)item.Key, item => (string)item.Value);

            AppViewModel.Instance.Locale = locale;
            foreach (var pluginInstance in App.Plugins.Loaded.Cast <PluginInstance>()
                     .Where(pluginInstance => pluginInstance.Loaded))
            {
                pluginInstance.Instance.Locale = locale;
            }
        }
Пример #9
0
        private static Tuple <int, Dictionary <Chinese, List <Pinyin> > > LoadDicionary(string dictionarypath)
        {
            Dictionary <Chinese, List <Pinyin> > dictout = new Dictionary <Chinese, List <Pinyin> >();
            int lenghtout = 0;

            try
            {
                FileStream   fin    = new FileStream(dictionarypath, FileMode.Open);
                StreamReader stream = new StreamReader(fin, Encoding.UTF8);
                string       line;
                while ((line = stream.ReadLine()) != null)                  // Read through the Text file
                {
                    if (line.Length > 0 && line[0] != '#')                  //ignore commented lines and off lines
                    {
                        string[] dictline = line.Split(new char[] { ' ' }); // split line on spaces
                        Chinese  simp     = dictline[0];
                        Chinese  trad     = dictline[1];

                        lenghtout = Math.Max(simp.Length, lenghtout); // Find the Longest word

                        string CEpinyin = "";                         // make string of pinyin
                        for (int i = 0; i != simp.Length; i++)
                        {
                            CEpinyin += dictline[2 + i] + " ";
                        }

                        Pinyin pinyin = CEdictpinyin2pinyin(CEpinyin);
                        foreach (string simptrad in new string[] { simp, trad })
                        { // add it to the Map
                            if (!dictout.ContainsKey(simptrad))
                            {
                                dictout.Add(simptrad, new List <Pinyin>());
                                dictout[simptrad].Add(pinyin);
                            }
                            else
                            if (!dictout[simptrad].Contains(pinyin))
                            {
                                dictout[simptrad].Add(pinyin);
                            }
                        }
                    }
                }
                fin.Close();
            }
            catch (FileNotFoundException e)
            {
                System.Windows.Forms.MessageBox.Show("Dictionary could not be found at '" + Path.GetFullPath(dictionarypath)
                                                     + "'. FileNotFoundException (" + e.Message + ") Thrown.");
            }

            return(new Tuple <int, Dictionary <Chinese, List <Pinyin> > >(lenghtout, dictout));
        }
Пример #10
0
            /// <summary>
            /// 取得景點資料
            /// </summary>
            /// <param name="lat">緯度</param>
            /// <param name="lng">經度</param>
            /// <param name="locationRadius">半徑範圍</param>
            /// <returns></returns>
            public static IList <TravelAttractionEntity> Get(float lat, float lng, int locationRadius = 1)
            {
                IList <TravelAttractionEntity> list = null;

                using (var openData = new Chinese())
                {
                    var table = openData.GetByLatLng(lat, lng, locationRadius);

                    list = table.ToList <TravelAttractionEntity>();
                }

                return(list);
            }
Пример #11
0
            /// <summary>
            /// 取得景點資料
            /// </summary>
            /// <param name="serialNo">The serial no.</param>
            /// <returns></returns>
            public static TravelAttractionEntity Get(string serialNo)
            {
                TravelAttractionEntity entity = null;

                using (var openData = new Chinese())
                {
                    var table = openData.GetById(serialNo);

                    entity = table.ToList <TravelAttractionEntity>().FirstOrDefault();
                }

                return(entity);
            }
Пример #12
0
        // override object.Equals
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            Weekday w = (Weekday)obj;

            return(Id == w.Id &&
                   English.EqualsExT(w.English) &&
                   Chinese.EqualsExT(w.Chinese) &&
                   Japanese.EqualsExT(w.Japanese));
        }
Пример #13
0
        /// <summary>
        /// </summary>
        /// <param name="cultureInfo"> </param>
        public static void Update(CultureInfo cultureInfo)
        {
            var culture = cultureInfo.TwoLetterISOLanguageName;
            Dictionary <string, string> dictionary;

            if (Constants.Supported.Contains(culture))
            {
                switch (culture)
                {
                case "fr":
                    dictionary = French.Context();
                    break;

                case "ja":
                    dictionary = Japanese.Context();
                    break;

                case "de":
                    dictionary = German.Context();
                    break;

                case "zh":
                    dictionary = Chinese.Context();
                    break;

                case "ru":
                    dictionary = Russian.Context();
                    break;

                case "ko":
                    dictionary = Korean.Context();
                    break;

                default:
                    dictionary = English.Context();
                    break;
                }
            }
            else
            {
                dictionary = English.Context();
            }

            AppViewModel.Instance.Locale = dictionary;
            foreach (PluginInstance pluginInstance in App.Plugins.Loaded.Cast <PluginInstance>().Where(pluginInstance => pluginInstance.Loaded))
            {
                pluginInstance.Instance.Locale = dictionary;
            }
        }
Пример #14
0
        public void DecreaseImmunity(int percent, Chinese chinese)
        {
            if (NameInfactedVirus != null)
            {
                PercentageOfImmunity -= NameInfactedVirus.Damage;
            }
            else
            {
                PercentageOfImmunity -= percent;
            }

            if (PercentageOfImmunity == 0)
            {
                chinese.KillTheChinese();
            }
        }
Пример #15
0
        public void Defence(int damage, Chinese chinese, Virus virus)
        {
            int currentDamage = damage;

            if (IsInFected)
            {
                currentDamage += extaDamage;
            }

            DecreaseImmunity(currentDamage, chinese);

            if (PercentageOfImmunity <= 40 && NameInfactedVirus == null)
            {
                IsInFected        = true;
                NameInfactedVirus = virus;
            }
        }
Пример #16
0
        public IEnumerable <string> Process(string mp3dir)
        {
            FileInfo[] files = new DirectoryInfo(mp3dir).GetFiles("*.mp3");
            foreach (FileInfo fi in files)
            {
                string oldFilename = fi.Name.Replace("£¨", "(").Replace("£©", ")").Replace("£¬", "").Replace(" ", "");
                string newFilename = Chinese.GetSpells(oldFilename);

                if (!fi.Name.Equals(newFilename))
                {
                    Console.Out.WriteLine(fi.Name + "-->" + newFilename);
                    fi.MoveTo(fi.DirectoryName + "\\" + newFilename);
                }
            }

            return(new List <string>());
        }
Пример #17
0
 /// <summary>
 /// 获取首字母
 /// </summary>
 /// <param name="title"></param>
 /// <returns></returns>
 public static string GetTitleIndex(string title)
 {
     if (!string.IsNullOrEmpty(title))
     {
         string firstChar = Chinese.Get(title.Replace("供应", "").Substring(0, 1)).ToUpper().Trim();
         if (!string.IsNullOrEmpty(firstChar))
         {
             char index = Convert.ToChar(firstChar);
             if (IsFullWidth(index))
             {
                 char result = (char)(index - 65248);
                 return(result.ToString());
             }
             return(firstChar);
         }
     }
     return("");
 }
Пример #18
0
        /// <summary>
        /// </summary>
        /// <param name="cultureInfo"> </param>
        public static Dictionary <string, string> Update(CultureInfo cultureInfo)
        {
            var culture = cultureInfo.TwoLetterISOLanguageName;
            Dictionary <string, string> dictionary;

            if (Constants.Supported.Contains(culture))
            {
                switch (culture)
                {
                case "fr":
                    dictionary = French.Context();
                    break;

                case "ja":
                    dictionary = Japanese.Context();
                    break;

                case "de":
                    dictionary = German.Context();
                    break;

                case "zh":
                    dictionary = Chinese.Context();
                    break;

                case "ru":
                    dictionary = Russian.Context();
                    break;

                default:
                    dictionary = English.Context();
                    break;
                }
            }
            else
            {
                dictionary = English.Context();
            }

            var e = dictionary.ToDictionary(val => val.Key, val => val.Value);

            return(e);
        }
Пример #19
0
        /// <summary>
        /// </summary>
        /// <param name="cultureInfo"> </param>
        public static Dictionary <string, string> Update(CultureInfo cultureInfo)
        {
            var culture = cultureInfo.TwoLetterISOLanguageName;
            ResourceDictionary dictionary;

            if (Constants.Supported.Contains(culture))
            {
                switch (culture)
                {
                case "fr":
                    dictionary = French.Context();
                    break;

                case "ja":
                    dictionary = Japanese.Context();
                    break;

                case "de":
                    dictionary = German.Context();
                    break;

                case "zh":
                    dictionary = Chinese.Context();
                    break;

                case "ru":
                    dictionary = Russian.Context();
                    break;

                default:
                    dictionary = English.Context();
                    break;
                }
            }
            else
            {
                dictionary = English.Context();
            }

            return(dictionary.Cast <DictionaryEntry>().ToDictionary(item => (string)item.Key, item => (string)item.Value));
        }
Пример #20
0
        /// <summary>
        /// 获取汉字首字母
        /// </summary>
        /// <param name="text">获取文本框数值</param>
        /// <param name="only">只返回汉字部分</param>
        /// <returns>返回每个汉字首字母</returns>
        public static string GetFirstPinYin(string text, bool only)
        {
            StringBuilder sb = new StringBuilder();

            foreach (char ch in text)
            {
                HanZi hz = Chinese.GetHanZi(ch);
                if (hz == null)
                {
                    if (only == false)
                    {
                        sb.Append(ch);
                    }
                }
                else
                {
                    sb.Append(hz.FirstPinYin);
                }
            }

            return(sb.ToString());
        }
Пример #21
0
 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);
     }
 }
 public void Initialize()
 {
     _chinese = new Chinese();
 }
Пример #23
0
 public void Attack(Chinese chinese)
 {
     chinese.DefenseImmunity(Damage, this);
 }
Пример #24
0
        /*
         * 适配器模式: 将一个类的接口转换成客户希望的另一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。--《设计模式》Gof
         *
         * 使用频率:★★★★☆
         *
         * 模式的组成:
         *
         * (1)目标角色(Target):定义Client使用的与特定领域相关的接口。如: [IHDMIInterfaceTarget,ICanSayEnglish]
         *
         * (2)客户角色(Client):与符合Target接口的对象协同。 如: [GraphicsCard,English],可有可无
         *
         * (3)被适配角色(Adaptee):定义一个已经存在并已经使用的接口,这个接口需要适配。如: [VGAInterface,Chinese]
         *
         * (4)适配器角色(Adapter) :适配器模式的核心。它将对被适配Adaptee角色已有的接口转换为目标角色Target匹配的接口。对Adaptee的接口与Target接口进行适配。
         *
         *  如: [VGAToHDMIAdapter,Translator]
         */

        static void Main(string[] args)
        {
            //买了新显卡,先显卡需要一个IHDMIInterfaceTarget的接口实现,即能输出HDMI信号的口
            //但是电脑只有VGA的口,又不想扔掉,于是买了一个转接适配器,把VGA的口接到适配器上
            var adapter = new VGAToHDMIAdapter(new VGAInterface());

            //于是乎,我们就有了一个IHDMIInterfaceTarget的口(因为适配器肯定实现了IHDMIInterfaceTarget的接口功能)就可以接入了
            IHDMIInterfaceTarget hdmiTarget = adapter;

            //显示一下接受到的HDMI信号
            hdmiTarget.DisplayHDMISignal();

            Console.WriteLine("==============================");

            //当然,如果你有钱可以重新买一个HDMI的接口线
            IHDMIInterfaceTarget hdmiTarget2 = new HDMIInterface();

            hdmiTarget2.DisplayHDMISignal();

            Console.WriteLine("==============================");
            //新显卡急需一个IHDMIInterfaceTarget标准的对象才能工作
            GraphicsCard graphics = new GraphicsCard();

            //用适配器的做的 和 真正的hdmi接口的 都可以
            graphics.Work(adapter);
            graphics.Work(hdmiTarget2);

            Console.WriteLine("==============================");


            /*
             * 看一个中国人,英国人和翻译官的例子
             * 中国人(Adaptee)要和英国人(Client)交流,但是中国人说的话英国人听不懂,需要一个翻译官(Adapter)来翻译成听的懂的英文或能说英语的人(Target)
             *
             */

            //不经过翻译官,直接问
            var chinese = new Chinese("你好,早饭吃了吗");
            var english = new English();

            english.Answer(chinese.Hello);

            Console.WriteLine("==============================");
            //翻译官来帮助 一下
            ICanSayEnglish translator = new Translator(new Chinese("你好,早饭吃了吗"));
            //翻译出来英文的hello
            var englishHello = translator.SayEnglish();

            english.Answer(englishHello);

            Console.ReadKey();

            /*
             * 总结:
             * 1.目标对象 IHDMIInterfaceTarget,被适配者VGAToHDMIAdapter,适配器 VGAToHDMIAdapter。
             * 2.适配器拥有目标对象的操作,并且接受被适配者,内部处理两者的适配关系。
             * 3.适配器模式和代理模式的区别是:代理模式是中间对象和原对象有相同的操作,适配器模式是中间对象和目标对象有相同的操作。
             *
             *
             * 中心思想:当我们有一个老的功能,要接入一个新的功能时,我们又不想把老的功能去掉或者是还需要用到老的功能,但是和新功能接口又不匹配,我们就可以
             * 引入一个中间适配器去处理一下,达到老功能能用,新接口又不损坏。
             *
             */
        }
Пример #25
0
        public async Task <IActionResult> Post([FromBody] Chinese value)
        {
            await _chineseQManager.AddQuote(value);

            return(Ok());
        }