示例#1
0
        public void Invoke(ShPlayer player, string jobName, ShPlayer target = null)
        {
            target = target ?? player;
            var jobs = new Dictionary <string, JobIndex>();

            foreach (JobIndex jobType in Enum.GetValues(typeof(JobIndex)))
            {
                jobs.Add(jobType.ToString(), jobType);
            }

            var wantedJob = jobs.FirstOrDefault(x => x.Key == jobName);

            if (wantedJob.Key == null)
            {
                if (Core.Instance.Settings.Levenshtein.SetJobMode == Configuration.Models.SettingsModel.LevenshteinMode.None)
                {
                    player.TS("job_notFound", jobName);
                    return;
                }
                wantedJob = jobs.OrderByDescending(x => LevenshteinDistance.CalculateSimilarity(x.Key, jobName)).FirstOrDefault();

                if (Core.Instance.Settings.Levenshtein.SetJobMode == Configuration.Models.SettingsModel.LevenshteinMode.Suggest)
                {
                    player.TS("job_notFound", jobName);
                    player.TS("levenshteinSuggest", wantedJob.Key);
                    return;
                }
            }
            target.svPlayer.SvTrySetJob(wantedJob.Value, true, false);
            player.TS("job_set", target.username.CleanerMessage(), jobName);
            if (target != player)
            {
                target.TS("new_job", player.username.CleanerMessage(), wantedJob.Key);
            }
        }
示例#2
0
        public void Invoke(ShPlayer player, string name, int amount = 1, ShPlayer target = null)
        {
            target = target ?? player;
            var item = Core.Instance.EntityHandler.Items.OrderByDescending(x => LevenshteinDistance.CalculateSimilarity(x.Key, name)).FirstOrDefault();

            target.TransferItem(DeltaInv.AddToMe, item.Value.index, amount, true);
            player.TS("player_give", target.username.SanitizeString(), item.Key, amount.ToString());
        }
示例#3
0
文件: Kit.cs 项目: ggggg/Core
        public void Invoke(ShPlayer player, string kit)
        {
            var obj = Core.Instance.KitHandler.List.FirstOrDefault(x => x.Name.Equals(kit, StringComparison.OrdinalIgnoreCase));

            if (obj == null)
            {
                if (Core.Instance.Settings.Levenshtein.KitMode == Configuration.Models.SettingsModel.LevenshteinMode.None)
                {
                    player.TS("expFileHandler_error_notFound", player.T(Core.Instance.KitHandler.Name), kit);
                    return;
                }
                obj = Core.Instance.KitHandler.List.OrderByDescending(x => LevenshteinDistance.CalculateSimilarity(x.Name, kit)).FirstOrDefault();

                if (Core.Instance.Settings.Levenshtein.KitMode == Configuration.Models.SettingsModel.LevenshteinMode.Suggest)
                {
                    player.TS("expFileHandler_error_notFound", player.T(Core.Instance.KitHandler.Name), kit);
                    player.TS("levenshteinSuggest", obj.Name);
                    return;
                }
            }
            if (!player.svPlayer.HasPermission($"{Core.Instance.Info.GroupNamespace}.{Core.Instance.KitHandler.Name}.{obj.Name}"))
            {
                player.TS("expFileHandler_error_noPermission", player.T(Core.Instance.KitHandler.Name), obj.Name);
                return;
            }
            if (obj.Disabled)
            {
                player.TS("expFileHandler_error_disabled", player.T(Core.Instance.KitHandler.Name), obj.Name);
                return;
            }
            if (player.HasCooldown(Core.Instance.KitHandler.Name, obj.Name))
            {
                player.TS("expFileHandler_error_cooldown", player.T(Core.Instance.KitHandler.Name), player.GetCooldown(Core.Instance.KitHandler.Name, obj.Name).ToString());
                return;
            }
            if (obj.Price > 0)
            {
                if (player.MyMoneyCount() < obj.Price)
                {
                    player.TS("expFileHandler_error_price", player.T(Core.Instance.KitHandler.Name), obj.Price.ToString(), player.MyMoneyCount().ToString());
                    return;
                }
                player.TransferMoney(DeltaInv.RemoveFromMe, obj.Price, true);
            }
            obj.GiveItems(player);
            if (obj.Delay > 0)
            {
                player.AddCooldown(Core.Instance.KitHandler.Name, obj.Name, obj.Delay);
            }
            player.SendChatMessage(
                player.TC(Core.Instance.KitHandler.Name + "_received", obj.Name) +
                (obj.Price > 0 ? player.TC(Core.Instance.KitHandler.Name + "_received_Price", obj.Price.ToString()) : "") +
                (obj.Delay > 0 ? player.TC(Core.Instance.KitHandler.Name + "_received_Delay", obj.Delay.ToString()) : ""));
        }
示例#4
0
        public void Invoke(ShPlayer player, string warp)
        {
            var obj = Core.Instance.WarpHandler.List.FirstOrDefault(x => x.Name.Equals(warp, StringComparison.OrdinalIgnoreCase));

            if (obj == null)
            {
                if (Core.Instance.Settings.Levenshtein.WarpMode == Configuration.Models.SettingsModel.LevenshteinMode.None)
                {
                    player.TS("expFileHandler_error_notFound", player.T(Core.Instance.WarpHandler.Name), warp);
                    return;
                }
                obj = Core.Instance.WarpHandler.List.OrderByDescending(x => LevenshteinDistance.CalculateSimilarity(x.Name, warp)).FirstOrDefault();

                if (Core.Instance.Settings.Levenshtein.WarpMode == Configuration.Models.SettingsModel.LevenshteinMode.Suggest)
                {
                    player.TS("expFileHandler_error_notFound", player.T(Core.Instance.WarpHandler.Name), warp);
                    player.TS("levenshteinSuggest", obj.Name);
                    return;
                }
            }
            if (!player.svPlayer.HasPermission($"{Core.Instance.Info.GroupNamespace}.{Core.Instance.WarpHandler.Name}.{obj.Name}"))
            {
                player.TS("expFileHandler_error_noPermission", player.T(Core.Instance.WarpHandler.Name), obj.Name);
                return;
            }
            if (obj.Disabled)
            {
                player.TS("expFileHandler_error_disabled", player.T(Core.Instance.WarpHandler.Name), obj.Name);
                return;
            }
            if (Core.Instance.WarpsCooldownHandler.IsCooldown(player.svPlayer, obj.Name, obj.Delay))
            {
                player.TS("expFileHandler_error_cooldown", player.T(Core.Instance.WarpHandler.Name), Core.Instance.WarpsCooldownHandler.GetCooldown(player.svPlayer, obj.Name, obj.Delay).ToString());
                return;
            }
            if (obj.Price > 0)
            {
                if (player.MyMoneyCount < obj.Price)
                {
                    player.TS("expFileHandler_error_price", player.T(Core.Instance.WarpHandler.Name), obj.Price.ToString(), player.MyMoneyCount.ToString());
                    return;
                }
                player.TransferMoney(DeltaInv.RemoveFromMe, obj.Price, true);
            }
            player.GetExtendedPlayer().ResetAndSavePosition(obj.Position.SerializableVector3.ToVector3(), obj.SerializableQuaternion.ToQuaternion(), obj.Position.PlaceIndex);
            if (obj.Delay > 0)
            {
                Core.Instance.WarpsCooldownHandler.AddCooldown(player.svPlayer, obj.Name);
            }
            player.SendChatMessage(
                player.TC(Core.Instance.WarpHandler.Name + "_teleported", obj.Name) +
                (obj.Price > 0 ? player.TC(Core.Instance.WarpHandler.Name + "_telported_Price", obj.Price.ToString()) : "") +
                (obj.Delay > 0 ? player.TC(Core.Instance.WarpHandler.Name + "_telported_Delay", obj.Delay.ToString()) : ""));
        }
示例#5
0
        public string CheckDuplidate()
        {
            //test
            string s1 = "By switching on and off, the __ can be used to represent the 1s and 0s that are foundation of all that goes on in the computer";
            string s2 = "what can be used to represent the 1s and 0s that are foundation of all that goes on in the computer?";

            s1 = StringUtils.NormalizeString(s1);
            s2 = StringUtils.NormalizeString(s2);

            double result12 = LevenshteinDistance.CalculateSimilarity(s1, s2);
            double result21 = LevenshteinDistance.CalculateSimilarity(s2, s1);

            return("S1-S2: " + result12 + " - S2-S1: " + result21);
        }
        public void CheckForSimilarityOfQuestionsTest()
        {
            List <ExamEntity> exams = DataGenerator.Initialize(null);

            ExamEntity theExam = exams.FirstOrDefault(e => e.Code.Equals("az-900", StringComparison.CurrentCultureIgnoreCase));

            List <QuestionEntity> allquestions = theExam.Questions;

            List <double> distances = new List <double>();

            List <Tuple <QuestionEntity, QuestionEntity, string> > duplicatesLists =
                new List <Tuple <QuestionEntity, QuestionEntity, string> >();

            List <Tuple <QuestionEntity, QuestionEntity, double> > distanceListAllQuestions =
                new List <Tuple <QuestionEntity, QuestionEntity, double> >();

            for (int i = 0; i < allquestions.Count; i++)
            {
                for (int j = i + 1; j < allquestions.Count; j++)
                {
                    QuestionEntity q1 = allquestions[i];
                    QuestionEntity q2 = allquestions[j];

                    string text1 = q1.ContentText.Replace(" ", string.Empty) + q1.AnswerText.Replace(" ", string.Empty);

                    string text2 = q2.ContentText.Replace(" ", string.Empty) + q2.AnswerText.Replace(" ", string.Empty);

                    string helperTextForDebug = $"{q1.Id + 1}{text1}{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}{q2.Id + 1}{text2}";

                    double distance = LevenshteinDistance.CalculateSimilarity(text1, text2);
                    distances.Add(Math.Round(distance, 2));
                    if (distance > 0.81)
                    {
                        duplicatesLists.Add(new Tuple <QuestionEntity, QuestionEntity, string>(
                                                q1, q2, distance.ToString()));

                        string textToSee = $"{text1} {Environment.NewLine}{Environment.NewLine} {text2}";
                    }

                    distanceListAllQuestions.Add(new Tuple <QuestionEntity, QuestionEntity, double>(
                                                     q1, q2, distance));
                }
            }
            string duplicateResultHelper = string.Join("\r\n\r\n\r\n", duplicatesLists.Select(s => s.Item1.ContentText + " ----- " + s.Item2.ContentText).ToList());

            distances = distances.OrderByDescending(d => d).ToList();

            distanceListAllQuestions = distanceListAllQuestions.OrderByDescending(d => d.Item3).ToList();
        }
        public void CheckForSimilarityOfCustomTextTest()
        {
            List <ExamEntity> exams = DataGenerator.Initialize(null);

            ExamEntity theExam = exams.FirstOrDefault(e => e.Code.Equals("AZ-900"));

            List <QuestionEntity> allquestions = theExam.Questions;

            List <double> distances = new List <double>();

            List <Tuple <QuestionEntity, QuestionEntity, string> > duplicatesLists =
                new List <Tuple <QuestionEntity, QuestionEntity, string> >();

            for (int i = 0; i < allquestions.Count; i++)
            {
                QuestionEntity q1 = allquestions[i];

                string text1 = q1.ContentText.Replace(" ", string.Empty) + q1.AnswerText.Replace(" ", string.Empty);

                string questionText = @"This question requires that you evaluate the underlined text to determine if it is correct.
When you are implementing a software as a service (SaaS) solution, you are responsible for configuring high availability.
Instructions: Review the underlined text. If it makes the statement correct, select If the statement is incorrect, select the answer choice that makes the statement correct.
A.No change is needed.
B.defining scalability rules
C.installing the SaaS solution
D.configuring the SaaS solution


";
                string answerText   = string.Empty;

                string text2 = questionText.Replace(" ", string.Empty); // + answerText.Replace(" ", string.Empty);

                string helperTextForDebug = $"{q1.Id + 1}{text1}{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}{q1.Id + 1}{text2}";

                double distance = LevenshteinDistance.CalculateSimilarity(text1, text2);
                distances.Add(Math.Round(distance, 2));
                if (distance > 0.81)
                {
                    duplicatesLists.Add(new Tuple <QuestionEntity, QuestionEntity, string>(
                                            q1, q1, distance.ToString()));

                    string textToSee = $"{text1} {Environment.NewLine}{Environment.NewLine} {text2}";
                }
            }
            distances = distances.OrderByDescending(d => d).ToList();
        }
        public void Test1()
        {
            //DbContextOptions<ExamAnswerContext> options = new DbContextOptions<ExamAnswerContext>();

            //using (ExamAnswerContext context = new ExamAnswerContext(options))
            //{
            //}
            //ExamEntity examEntity = examAnswerContext.Exams
            //   .Where(e => e.Provider.Equals(provider, StringComparison.InvariantCultureIgnoreCase) &&
            //       e.Code.Equals(examCode, StringComparison.InvariantCultureIgnoreCase))

            //   .Include(e => e.Questions)
            //   .ThenInclude(q => q.Contents)

            //   .Include(e => e.Questions)
            //   .ThenInclude(q => q.Answers)

            //   .Include(e => e.Questions)
            //   .ThenInclude(q => q.Explanations)

            //   .Include(e => e.Questions)
            //   .ThenInclude(q => q.References)

            //   .AsNoTracking()

            //   .FirstOrDefault();

            //var examViewModel = mapper.Map<ExamViewModel>(examEntity);

            double res = LevenshteinDistance.CalculateSimilarity(@"
 Universal Containers' current solution for managing its forecasts is cumbersome.

The sales managers do NOT have visibility into their teams' forecasts and are NOT able to update the forecasts. ",

                                                                 @" As a result, the managers are continually asking their sales representatives to provide updated forecast data via email or phone.

Which two solutions should a consultant recommend to help Universal Containers improve the management of their forecasts? (Choose two.) ");
        }
示例#9
0
        public void Invoke(ShPlayer player, string name, int amount = 1, ShPlayer target = null)
        {
            target = target ?? player;
            var item = Core.Instance.EntityHandler.Items.FirstOrDefault(x => x.Key == name);

            if (item.Value == null)
            {
                if (Core.Instance.Settings.Levenshtein.GiveMode == Configuration.Models.SettingsModel.LevenshteinMode.None)
                {
                    player.TS("give_notFound", name);
                    return;
                }
                item = Core.Instance.EntityHandler.Items.OrderByDescending(x => LevenshteinDistance.CalculateSimilarity(x.Key, name)).FirstOrDefault();
                if (Core.Instance.Settings.Levenshtein.GiveMode == Configuration.Models.SettingsModel.LevenshteinMode.Suggest)
                {
                    player.TS("give_notFound", name);
                    player.TS("levenshteinSuggest", item.Key);
                    return;
                }
            }
            target.TransferItem(DeltaInv.AddToMe, item.Value.index, amount, true);
            player.TS("player_give", target.username.CleanerMessage(), item.Key, amount.ToString());
        }
示例#10
0
        public void Invoke(ShPlayer player, string kit)
        {
            var file = Path.Combine(Core.Instance.Paths.KitsFolder, $"{kit}.json");

            if (!File.Exists(file))
            {
                player.TS("expFileHandler_error_notFound", player.T(Core.Instance.KitHandler.Name), kit);
                player.TS("levenshteinSuggest", Core.Instance.KitHandler.List.OrderByDescending(x => LevenshteinDistance.CalculateSimilarity(x.Name, kit)).FirstOrDefault().Name);
                return;
            }

            Core.Instance.KitHandler.DeleteExisting(kit);
            player.TS("expFileHandler_deleted", player.T(Core.Instance.KitHandler.Name), kit);
        }
示例#11
0
        public void Invoke(ShPlayer player, string name)
        {
            var vehicle = Core.Instance.EntityHandler.Vehicles.OrderByDescending(x => LevenshteinDistance.CalculateSimilarity(x.Key, name)).FirstOrDefault().Value;
            var pos     = player.GetPosition;

            Core.Instance.SvManager.AddNewEntity(vehicle, player.GetPlace, new Vector3(pos.x, pos.y + 7F, pos.z), player.GetRotation, respawnable: false);
            player.TS("player_vehicle_spawned", vehicle.name);
        }
示例#12
0
        private void cmdLevenshteinDistance_Click(object sender, EventArgs e)
        {
            var distance = LevenshteinDistance.CalculateSimilarity(txtFirstText.Text.Trim(), txtSecondText.Text.Trim());

            MessageBox.Show(distance.ToString("0.###"));
        }