コード例 #1
0
ファイル: Performer.cs プロジェクト: nsideris/RedisQueue.Net
 protected Performer()
 {
     Status = new PerformResult {
         Outcome = Outcome.NotStarted
     };
     TaskStorage = new Dictionary <string, string>();
 }
コード例 #2
0
        public PerformResult Perform(int maxCycles, List <string> correctSentences, List <TestSentence> errorSentences, List <TestSentence> warningSentences)
        {
            // Get corpus from sentences
            string corpus = "";

            for (int i = 0; i < correctSentences.Count; i++)
            {
                corpus += correctSentences[i];
            }

            // Get words from training text
            var tokenizer = new Tokenizer();
            var tokens    = tokenizer.Tokenize(corpus).Where(w => w.Type == Tokenizer.TokenType.Word);
            var words     = tokens.Select(t => t.Text).ToList();

            // Update status
            string output = "Checking corpus size..." + Environment.NewLine;

            output += "Sentences: " + correctSentences.Count + Environment.NewLine;
            output += "Words: " + words.Count + Environment.NewLine;
            Status.Update(output);

            // Create new instances of all engines
            Global.LevenshteinSP = new SpellingChecker.Levenshtein.Engine();
            Global.NGramSP       = new SpellingChecker.NGram.Engine();
            Global.HtmSP         = new SpellingChecker.HTM.Engine();

            // Train all engines
            Global.LevenshteinSP.Train(corpus);
            Global.NGramSP.Train(corpus);
            Global.HtmSP.Train(corpus, maxCycles);

            // Check accuracy for each type of error
            var performResult = new PerformResult();

            performResult.SequencesCount = correctSentences.Count;
            performResult.WordsCount     = words.Count;
            performResult.Error          = this.Check(IssueType.Error, correctSentences, errorSentences);
            performResult.Warning        = this.Check(IssueType.Warning, correctSentences, warningSentences);

            return(performResult);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var airport = new Airport(NumberOfRunways, NumberOfParkingStands);
            // Now spin a number of threads simulating some aircrafts.

            var aircraftClients = new List <Thread>();
            var randomizer      = new Random();

            for (int i = 0; i < NumberOfClients; i++)
            {
                var worker = new Thread(() => {
                    Guid aircraftId        = Guid.NewGuid();
                    bool landingSuccessful = false;

                    while (!landingSuccessful)
                    {
                        Console.WriteLine("Worker " + aircraftId.ToString() + " is attempting a landing.");

                        /////////////////////////////////////////////////////////////////////////////////////////////////////////
                        // Attempt calling into Airport.RequestLanding until landing token is successfully received.
                        // Repeat otherwise.
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////
                        RequestResult landingRequestResult = airport.RequestLanding(aircraftId);
                        while (landingRequestResult.state != RequestResult.RequestState.Proceed)
                        {
                            Thread.Sleep(200 * randomizer.Next(RandomDelayMax));
                            landingRequestResult = airport.RequestLanding(aircraftId);
                        }
                        Console.WriteLine("Worker " + aircraftId.ToString() + " received a landing token.");

                        // Wait some random time. In some cases the token will expire, that's OK.
                        Thread.Sleep(1000 * randomizer.Next((int)Airport.TokenValiditySeconds * 2));

                        /////////////////////////////////////////////////////////////////////////////////////////////////////////
                        // Attempt calling into Airport.PerformLanding and break out of the loop if it's successful.
                        // Allow the loop to repeat otherwise.
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////
                        PerformResult landingPerformResult = airport.PerformLanding((LandingRequestToken)landingRequestResult.token);
                        if (landingPerformResult == PerformResult.Success)
                        {
                            landingSuccessful = true;
                        }
                        if (!landingSuccessful)
                        {
                            Console.WriteLine("Worker " + aircraftId.ToString() + " landing token expired. It will try again.");
                        }
                    }

                    Console.WriteLine("Worker " + aircraftId.ToString() + " has successfully landed.");

                    // Sleep for at least the time of landing operation plus some random time
                    Thread.Sleep((int)(1000 * (Airport.OperationDurationSeconds + randomizer.Next(RandomDelayMax))));

                    Console.WriteLine("Worker " + aircraftId.ToString() + " is attempting a take-off.");

                    bool takeOffSuccessful = false;

                    while (!takeOffSuccessful)
                    {
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////
                        // Attempt calling into Airport.RequestTakeoff until take-off token is successfully received.
                        // Repeat otherwise.
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////

                        RequestResult takeOffRequestResult = airport.RequestTakeOff(aircraftId);
                        while (takeOffRequestResult.state != RequestResult.RequestState.Proceed)
                        {
                            Thread.Sleep(200 * randomizer.Next(RandomDelayMax));
                            takeOffRequestResult = airport.RequestTakeOff(aircraftId);
                        }
                        Console.WriteLine("Worker " + aircraftId.ToString() + " received a take-off token.");

                        // Wait some random time. In some cases the token will expire, that's OK.
                        Thread.Sleep(1000 * randomizer.Next((int)Airport.TokenValiditySeconds * 2));

                        /////////////////////////////////////////////////////////////////////////////////////////////////////////
                        // Attempt calling into Airport.PerformTakeoff and break out of the loop if it's successful.
                        // Allow the loop to repeat otherwise.
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////

                        PerformResult takeOffPerformResult = airport.PerformTakeOff((TakeOffRequestToken)takeOffRequestResult.token);
                        if (takeOffPerformResult == PerformResult.Success)
                        {
                            takeOffSuccessful = true;
                        }

                        if (!takeOffSuccessful)
                        {
                            Console.WriteLine("Worker " + aircraftId.ToString() + " take-off token expired. It will try again.");
                        }
                    }

                    Console.WriteLine("Worker " + aircraftId.ToString() + " has successfully departed.");
                });

                worker.Start();
                aircraftClients.Add(worker);
            }

            foreach (var client in aircraftClients)
            {
                client.Join();
            }

            Console.WriteLine("All done. Simulation terminating.");
        }
コード例 #4
0
		protected Performer()
		{
			Status = new PerformResult { Outcome = Outcome.NotStarted };
			TaskStorage = new Dictionary<string, string>();
		}