Example #1
0
    /// <summary>
    /// 判断两个字符串的相似度, 1.0 为完全相同
    /// <summary>
    public static decimal Similarity(string lhs, string rhs)
    {
        var strc = new StringCompute();

        strc.Compute(lhs, rhs);
        return(strc.ComputeResult.Rate);
    }
Example #2
0
        public void Simple_Compute_Test()
        {
            var compute = new StringCompute("世界,你好。", "你好,世界。");

            compute.Compute();
            var computeResult = compute.ComputeResult;

            computeResult.Rate.ShouldBe(0.4285714285714285714285714286M);
            computeResult.Difference.ShouldBe(4);
            computeResult.UseTime.ShouldNotBeNull();
            computeResult.ComputeTimes.ShouldBe("36");
        }
Example #3
0
            private string[] TextHandler(List <string> OriText, int Chapter = 13)
            {
                var    Exl      = 读取并分析分类表();
                var    SaveText = new List <string>();
                var    TempText = new List <string>();
                bool   StartRec = false;
                string Name     = "";
                var    Command  = new HashSet <string>();
                var    Add      = new List <string>();

                foreach (var Oridat in OriText)
                {
                    if (Oridat.StartsWith("&"))
                    {
                        Command.Add(Oridat);
                    }

                    if (StartRec)
                    {
                        if (Oridat == "“哈哈,那么本人就恭敬不如从命了,")
                        {
                            //  Console.WriteLine();
                        }

                        if (Oridat[Oridat.Length - 1] != '”')
                        {
                            Add.Add(Oridat);
                            TempText.Add(Oridat);
                            continue;
                        }
                        Add.Add(Oridat);
                        bool FindCheck     = false;
                        var  ContinueCheck = Add.FirstOrDefault(X => X.IndexOf("{{不停}}", StringComparison.Ordinal) != -1);
                        if (ContinueCheck == null)
                        {
                            var BreakCheck = Add.FirstOrDefault(X => X.IndexOf("{{跳过}}", StringComparison.Ordinal) != -1);
                            if (BreakCheck == null)
                            {
                                foreach (var VARIABLE in Add)
                                {
                                    var Ret = Search(VARIABLE);
                                    if (Ret != null)
                                    {
                                        CheckTextExists(Ret);
                                        FindCheck = true;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                FindCheck = true;
                            }
                        }
                        else
                        {
                            foreach (var VARIABLE in Add)
                            {
                                var Ret = Search(VARIABLE.Replace(@"{{不停}}", ""));
                                if (Ret != null)
                                {
                                    CheckTextExists(Ret);
                                    FindCheck = true;
                                    break;
                                }
                            }
                        }

                        if (!FindCheck)
                        {
                            Console.WriteLine($"未找到文本,行数:{OriText.IndexOf(Oridat)}");
                        }

                        string Search(string T)
                        {
                            T = T.Replace("“", "").Replace("”", "");
                            return(Exl[Name].FirstOrDefault(x =>
                            {
                                String.Compute(T, x.Value);
                                return (float)String.ComputeResult.Rate > 0.8;
                            }).Key ?? Exl[Name]
                                   .FirstOrDefault(x => x.Value.IndexOf(T, StringComparison.Ordinal) != -1).Key);
                        }

                        /* string Zwei;
                         * if (Ein.IndexOf(@"{{不停}}", StringComparison.Ordinal) != -1)
                         * {
                         *
                         *   Ein = Ein.Replace(@"{{不停}}", "");
                         *
                         *   Zwei = Exl[Name].FirstOrDefault(x => x.Value.IndexOf(Ein, StringComparison.Ordinal) != -1)
                         *       .Key;
                         *   CheckTextExists();
                         * }
                         * else if (Ein.IndexOf(@"{{跳过}}", StringComparison.Ordinal) == -1)
                         * {
                         *   Zwei = Exl[Name].FirstOrDefault(x =>
                         *   {
                         *       String.Compute(Ein, x.Value);
                         *       return (float) String.ComputeResult.Rate > 0.8;
                         *   }).Key;
                         *   if (Zwei == null)
                         *   {
                         *       Zwei = Exl[Name]
                         *           .FirstOrDefault(x => x.Value.IndexOf(Ein, StringComparison.Ordinal) != -1).Key;
                         *   }
                         *
                         *   CheckTextExists();
                         * }*/

                        void CheckTextExists(string Zwei)
                        {
                            if (!string.IsNullOrWhiteSpace(Zwei))
                            {
                                var AddS = $"&{NameList[Name]}={Chapter}_{Zwei}.ogg";
                                if (!Command.Contains(AddS))
                                {
                                    SaveText.Add(AddS);
                                }
                                Exl[Name].Remove(Zwei);
                            }
                            else
                            {
                                Console.WriteLine($"未找到文本,行数:{SaveText.Count}");
                            }
                        }

                        StartRec = false;
                    }

                    if (Oridat.StartsWith("【"))
                    {
                        Name = Oridat.Replace("【", "").Replace("】", "");
                        if (!string.IsNullOrWhiteSpace(Name))
                        {
                            if (Exl.ContainsKey(Name))
                            {
                                //SaveText.AddRange(Add.ToArray());
                                Add.Clear();
                                SaveText.AddRange(TempText.ToArray());
                                TempText.Clear();
                                StartRec = true;
                            }
                        }
                    }

                    TempText.Add(Oridat);
                }

                SaveText.AddRange(TempText.ToArray());
                return(SaveText.ToArray());
            }
Example #4
0
        private void CheckCoinNews()
        {
            ConfigManager.Instance().pushProblemCount += 1;
            if (ConfigManager.Instance().pushProblemCount > (4 * 60 * 60 / ConfigManager.pushNewsConfig.LoopCheckTime))
            {
                var msg = ConfigManager.Instance().problem.description + "\n" + ConfigManager.Instance().problem.example;
                _mahuaApi.SendGroupMessage("417955323", msg);
                ConfigManager.Instance().pushProblemCount = 0;
            }

            var re = _newsService.RequestBiQuanApi();

            NewsResult msg1 = null;
            NewsResult msg2 = null;
            NewsResult msg3 = null;
            NewsResult msg4 = null;

            if (re[0] != null && !re[0].Content.Equals(lastMsg1))
            {
                lastMsg1 = re[0].Content;
                msg1     = re[0];
            }
            else
            {
                msg1 = null;
            }

            if (re[1] != null && !re[1].Content.Equals(lastMsg2))
            {
                lastMsg2 = re[1].Content;
                msg2     = re[1];
            }
            else
            {
                msg2 = null;
            }

            if (re[2] != null && !re[2].Content.Equals(lastMsg3))
            {
                lastMsg3 = re[2].Content;
                msg3     = re[2];
            }
            else
            {
                msg3 = null;
            }

            if (re[3] != null && !re[3].Content.Equals(lastMsg4))
            {
                lastMsg4 = re[3].Content;
                msg4     = re[3];
            }
            else
            {
                msg4 = null;
            }

            if (ConfigManager.pushNewsConfig.UsCompute)
            {
                if (msg1 != null)
                {
                    StringCompute stringcompute1 = new StringCompute();
                    stringcompute1.Compute(msg1.Content, lastMsg2);
                    if ((float)stringcompute1.ComputeResult.Rate > ConfigManager.pushNewsConfig.ComputeRate)
                    {
                        msg1 = null;
                    }
                }
                if (msg2 != null)
                {
                    StringCompute stringcompute1 = new StringCompute();
                    stringcompute1.Compute(msg2.Content, lastMsg1);
                    if ((float)stringcompute1.ComputeResult.Rate > ConfigManager.pushNewsConfig.ComputeRate)
                    {
                        msg2 = null;
                    }
                }

                if (msg1 != null && msg2 != null)
                {
                    StringCompute stringcompute1 = new StringCompute();
                    stringcompute1.Compute(msg1.Content, msg2.Content);
                    if ((float)stringcompute1.ComputeResult.Rate > ConfigManager.pushNewsConfig.ComputeRate)
                    {
                        msg2 = null;
                    }
                }
            }

            var reMsg = string.Empty;

            if (msg1 != null)
            {
                if (msg1.NewsLevel == NewsLevel.Normal)
                {
                    normalMsgList.Add(msg1.From + msg1.Title + "\n");
                }
                else
                {
                    reMsg += msg1.From + msg1.Title + "\n";
                }
            }
            if (msg2 != null)
            {
                if (msg2.NewsLevel == NewsLevel.Normal)
                {
                    normalMsgList.Add(msg2.From + msg2.Content + "\n");
                }
                else
                {
                    reMsg += msg2.From + msg2.Title + "\n";
                }
            }
            if (msg3 != null)
            {
                if (msg3.NewsLevel == NewsLevel.Normal)
                {
                    normalMsgList.Add(msg3.From + msg3.Title + "\n");
                }
                else
                {
                    reMsg += msg3.From + msg3.Title + "\n";
                }
            }
            if (msg4 != null)
            {
                if (msg4.NewsLevel == NewsLevel.Normal)
                {
                    normalMsgList.Add(msg4.From + msg4.Title + "\n");
                }
                else
                {
                    reMsg += msg4.From + msg4.Title + "\n";
                }
            }

            if (!string.IsNullOrEmpty(reMsg))
            {
                //查询币圈
                reMsg += _coinmarketcapService.GetTicker("btc").Result;
                reMsg += "\n" + _huobiService.LegalTender().Result;

                //涨跌幅排名
                //reMsg += "\n【OK涨幅排名】"+_coinService.GetOkexTopTracks();
                //reMsg += "\n【OK跌幅排名】" + _coinService.GetOkexBottomTracks();

                if (sendCount != 0)
                {
                    foreach (var group in ConfigManager.pushNewsConfig.CoinNewsPushGroupList)
                    {
                        _mahuaApi.SendGroupMessage(group, reMsg + "\n第" + sendCount + "次主动推送消息");
                    }
                }
                sendCount++;
            }

            if (nowNormalNewsPushIntervalCount < ConfigManager.pushNewsConfig.NormalNewsPushIntervalCount)
            {
                nowNormalNewsPushIntervalCount++;
            }
            else
            {
                if (sendCount != 0)
                {
                    var normalMsg = string.Empty;
                    foreach (var item in normalMsgList)
                    {
                        normalMsg += item;
                    }
                    normalMsgList.Clear();


                    if (!string.IsNullOrEmpty(normalMsg))
                    {
                        //查询币圈
                        normalMsg += _coinmarketcapService.GetTicker("btc").Result;
                        normalMsg += "\n" + _huobiService.LegalTender().Result;

                        foreach (var group in ConfigManager.pushNewsConfig.CoinNewsPushGroupList)
                        {
                            _mahuaApi.SendGroupMessage(group, normalMsg + "\n第" + sendCount + "次主动推送消息");
                        }
                    }
                }
                sendCount++;
                nowNormalNewsPushIntervalCount = 0;
            }
        }
Example #5
0
        private void TextHandler(TxtFile OriText, Dictionary <string, Dictionary <string, string> > Exl)
        {
            var    TempText = new List <string>();
            bool   StartRec = false;
            string Name     = "";
            var    Command  = new HashSet <string>();
            var    Add      = new List <string>();

            foreach (var Oridat in OriText.Ori)
            {
                if (Oridat.StartsWith("&"))
                {
                    Command.Add(Oridat);
                }

                if (StartRec)
                {
                    if (Oridat[Oridat.Length - 1] != '”')
                    {
                        Add.Add(Oridat);
                        TempText.Add(Oridat);
                        continue;
                    }
                    Add.Add(Oridat);
                    var ContinueCheck = Add.FirstOrDefault(X => X.IndexOf("{{不停}}", StringComparison.Ordinal) != -1);
                    if (ContinueCheck == null)
                    {
                        var BreakCheck = Add.FirstOrDefault(X => X.IndexOf("{{跳过}}", StringComparison.Ordinal) != -1);
                        if (BreakCheck == null)
                        {
                            var Find = false;
                            foreach (var VARIABLE in Add)
                            {
                                var Ret = Search(VARIABLE);
                                if (Ret != null)
                                {
                                    CheckTextExists(Ret);
                                    Find = true;
                                    break;
                                }
                            }
                            if (!Find)
                            {
                                OriText.Log.Add($"原始文本未找到语音,行数:{OriText.Save.Count}");
                            }
                        }
                    }
                    else
                    {
                        var Find = false;
                        foreach (var VARIABLE in Add)
                        {
                            var Ret = Search(VARIABLE.Replace(@"{{不停}}", ""));
                            if (Ret != null)
                            {
                                CheckTextExists(Ret);
                                Find = true;
                                break;
                            }
                        }
                        if (!Find)
                        {
                            OriText.Log.Add($"原始文本未找到语音,行数:{OriText.Save.Count}");
                        }
                    }

                    string Search(string T)
                    {
                        StringCompute String = new StringCompute();

                        T = T.Replace("“", "").Replace("”", "");
                        return(Exl[Name].FirstOrDefault(x =>
                        {
                            String.Compute(T, x.Value);
                            return (float)String.ComputeResult.Rate > 0.8;
                        }).Key ?? Exl[Name]
                               .FirstOrDefault(x => x.Value.IndexOf(T, StringComparison.Ordinal) != -1).Key);
                    }

                    void CheckTextExists(string Zwei)
                    {
                        if (!string.IsNullOrWhiteSpace(Zwei))
                        {
                            var AddS = $"&{Name_List[Name]}={OriText.Cap}_{Zwei}.ogg";
                            if (!Command.Contains(AddS))
                            {
                                OriText.Save.Add(AddS);
                            }
                            Exl[Name].Remove(Zwei);
                        }
                    }

                    StartRec = false;
                }

                if (Oridat.StartsWith("【"))
                {
                    Name = Oridat.Replace("【", "").Replace("】", "");
                    if (!string.IsNullOrWhiteSpace(Name))
                    {
                        if (Exl.ContainsKey(Name))
                        {
                            Add.Clear();
                            OriText.Save.AddRange(TempText.ToArray());
                            TempText.Clear();
                            StartRec = true;
                        }
                    }
                }

                TempText.Add(Oridat);
            }
            OriText.Save.AddRange(TempText.ToArray());
        }