예제 #1
0
        private async Task <IList <SatResult> > SolveInstances(IList <SatInstance> instances, bool savePlotInfo)
        {
            var options = GetOptions(savePlotInfo);

            numberOfInstancesTotal    = instances.Count;
            numberOfFinishedInstances = 0;

            var results = await Task.Factory.StartNew(() =>
            {
                var performanceTester = new PerformanceTester();
                performanceTester.RaiseInstanceCalculationFinished += OnInstanceCalculationFinished;
                var res = performanceTester.SolveWithPerformanceTest(instances, options);
                return(res);
            }
                                                      );

            foreach (var result in results)
            {
                result.ResultLabel = CustomRowLabel.Text;
            }

            AddEpsilonValues(results);

            ProgressLabel.Content = "Calculations done!";
            return(results);
        }
예제 #2
0
        private async void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            using (var performanceTester = new PerformanceTester())
            {
                try
                {
                    //var response = await _container.Resolve<IRequestTask>().GetAsync(new TestAsyncRequest());

                    var tasks = new List <Task>();

                    for (var i = 0; i < 10; i++)
                    {
                        tasks.Add(_container.Resolve <IRequestTask>().GetAsync(new TestSyncRequest()));
                        tasks.Add(_container.Resolve <IRequestTask>().GetAsync(new TestAsyncRequest()));
                    }

                    await Task.WhenAll(tasks);
                }
                catch (Exception ex)
                {
                    throw;
                }

                var elapsed = performanceTester.Result.TotalSeconds;
            }
        }
예제 #3
0
        /// <summary>
        /// Setup extended tagger that includes POS, lemma and entity analysis
        /// </summary>
        private void SetupExtendedTagger()
        {
            PerformanceTester.StartMET("NLP");
            // Get path to Stanford NLP models
            var jarRoot = Path.Combine(Utility.GetResourcesFolder(), @"stanford-corenlp-3.9.2-models");

            // Turn off logging
            RedwoodConfiguration.current().clear().apply();
            var props = new java.util.Properties();

            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner");
            // Makes Named Entity Recognition work in the library
            props.setProperty("ner.useSUTime", "0");
            props.put("ner.applyFineGrained", "0");
            props.put("ner.fine.regexner.mapping", jarRoot + @"\edu\stanford\nlp\models\kbp\english\");
            // Set current directory
            var curDir          = Environment.CurrentDirectory;
            var modelsDirectory = curDir + "\\" + jarRoot + @"\edu\stanford\nlp\models";

            Directory.SetCurrentDirectory(jarRoot);

            // Load Stanford NLP
            Tagger = new StanfordCoreNLP(props);
            PerformanceTester.StopMET("NLP");
        }
예제 #4
0
        public static void TestHammingPerformance()
        {
            Console.WriteLine("Starting first test.");
            Stopwatch t1 = new Stopwatch();

            t1.Start();
            for (int i = 0; i < 1000000; i++)
            {
                PerformanceTester.CalculateFitnessLoop("HELLO WORLD, MY NAME IS STEVEN.",
                                                       "JFHHE WOERDL MS ERQE IS OEEVTN.");
            }
            t1.Stop();

            Console.WriteLine("Starting second test.");
            Stopwatch t2 = new Stopwatch();

            t2.Start();
            for (int i = 0; i < 1000000; i++)
            {
                PerformanceTester.CalculateFitnessByte("HELLO WORLD, MY NAME IS STEVEN.",
                                                       "JFHHE WOERDL MS ERQE IS OEEVTN.");
            }
            t2.Stop();
            Console.WriteLine($"First test: {t1.ElapsedMilliseconds}. Second test: {t2.ElapsedMilliseconds}");
        }
예제 #5
0
파일: RequestTask.cs 프로젝트: ganesum/Naru
        private TResponse Execute <TResponse>(Request <TResponse> request)
            where TResponse : Response
        {
            using (var performanceTester = new PerformanceTester())
            {
                request.Id = Guid.NewGuid().ToString();

                _log.Debug(string.Format("Start RequestTask {0}, Id - {1}", request.GetType(), request.Id));

                using (var requestDispatcher = _requestDispatcherFactory())
                {
                    var response = requestDispatcher.Get <TResponse>(request);

                    if (response.Exception != null)
                    {
                        throw new RequestException(response.Exception.Message);
                    }

                    _log.Debug(string.Format("Finished RequestTask {0}, Id - {1}. Duration {2}",
                                             request.GetType(),
                                             request.Id,
                                             performanceTester.Result.Milliseconds));

                    return(response);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Get sentences from the given message text
        /// </summary>
        /// <param name="text">The message text</param>
        /// <returns>A list with the sentences</returns>
        public List <object> GetSentences(string text)
        {
            PerformanceTester.StartMET("GetSentences");
            var annotation = new Annotation(text);

            Tagger.annotate(annotation);
            Sentences = annotation.get(new CoreAnnotations.SentencesAnnotation().getClass()) as ArrayList;
            PerformanceTester.StopMET("GetSentences");
            return(new List <object>(Sentences.toArray()));
        }
예제 #7
0
        public void Run()
        {
            using (PerformanceTester.Start(PrintPerformance))
            {
                PrintHeader();
                if (_opts.GotInputFile)
                {
                    _ticketFile = BillettServiceXmlFile.LoadFile(_opts.InputFile);
                    if (_opts.DumpArgs)
                    {
                        DumpArgs();
                    }
                    if (_opts.OutputCsv)
                    {
                        Export <SeterToCsv>(_opts.CsvOutputFile);
                    }
                    if (_opts.OutputLedigFile)
                    {
                        Export <LedigFile>(_opts.LedigTextFile);
                    }
                    if (_opts.OutputOpptattFile)
                    {
                        Export <OpptattFile>(_opts.OpptattTextFile);
                    }
                    if (_opts.OutputXmlFile)
                    {
                        WriteXml();
                    }
                    if (_opts.PerformSeatQuery)
                    {
                        Export <SeatQuery>(_opts.SeatQuery);
                    }
                    Export <SeatQuery>("NB:8");
                    if (_opts.PrintCountSummary)
                    {
                        PrintCountSummary();
                    }
                    //PrintCountSummary();

                    Print("Ingen gyldige outputs angitt.", _outputsUsed == 0);
                }
                else
                {
                    Print("Manglende eller ugyldig inputfil");
                }
            }

            if (_opts.Hate)
            {
                PrintHate();
            }

            Console.ReadKey();
        }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        PerformanceTester pt = (PerformanceTester)target;

        GUILayout.Label($"Flock Size: {pt.FlockSize}");

        if (GUILayout.Button("Increase Flock Size"))
        {
            pt.IncreaseFlockSize();
        }
    }
예제 #9
0
        static void Main(string[] args)
        {
            PerformanceTester tester = new PerformanceTester();

            Console.WriteLine("Standard Tests");
            ShowResults(tester.Run(Assembly.GetExecutingAssembly()));

            Console.WriteLine("Multiple Iteration Tests");
            ShowResults(tester.Run(Assembly.GetExecutingAssembly(), 5));

            Console.WriteLine("Multiple Iteration Tests with Averaged Results");
            tester.AverageResults = true;
            ShowResults(tester.Run(Assembly.GetExecutingAssembly(), 5));
        }
예제 #10
0
        /// <summary>
        /// Tag the given message text
        /// </summary>
        /// <param name="text">The message text</param>
        /// <returns>A list with the tagged words</returns>
        public List <TaggedWord> Tag(string text, bool useSavedSentences = false)
        {
            PerformanceTester.StartMET("Tagging");
            var list = new List <TaggedWord>();

            ArrayList sentences = null;

            if (useSavedSentences && Sentences != null)
            {
                sentences = Sentences;
            }
            else
            {
                var annotation = new Annotation(text);
                Tagger.annotate(annotation);
                sentences = annotation.get(new CoreAnnotations.SentencesAnnotation().getClass()) as ArrayList;
            }
            foreach (CoreMap sentence in sentences)
            {
                var tokens = sentence.get(new
                                          CoreAnnotations.TokensAnnotation().getClass()) as ArrayList;
                foreach (CoreLabel token in tokens)
                {
                    var original = token.get(new CoreAnnotations.OriginalTextAnnotation().getClass());
                    var after    = token.get(new CoreAnnotations.AfterAnnotation().getClass());
                    var before   = token.get(new CoreAnnotations.BeforeAnnotation().getClass());
                    var word     = token.get(new CoreAnnotations.TextAnnotation().getClass());
                    var pos      = token.get(new CoreAnnotations.PartOfSpeechAnnotation().getClass());
                    //var ner = token.get(new CoreAnnotations.NamedEntityTagAnnotation().getClass());
                    //var lemma = token.get(new CoreAnnotations.LemmaAnnotation().getClass());

                    var taggedWord = new TaggedWord()
                    {
                        Word     = word.ToString(),
                        Original = original.ToString(),
                        WhiteSpaceCharacterAfter  = after.ToString(),
                        WhiteSpaceCharacterBefore = before.ToString(),
                        POSStringIdentifier       = pos.ToString(),
                        //Lemma = lemma.ToString(),
                        //NERStringIdentifier = ner.ToString()
                    };
                    list.Add(taggedWord);
                }
            }

            PerformanceTester.StopMET("Tagging");

            return(list);
        }
예제 #11
0
파일: Handler.cs 프로젝트: smwhit/Naru
        public override Response Handle(TRequest request)
        {
            using (var performanceTester = new PerformanceTester())
            {
                Log.Debug(string.Format("Started processing request {0}, Id - {1}", typeof(TRequest).FullName, request.Id));

                var response = Execute(request);

                Log.Debug(string.Format("Finished processing request {0}, Id - {1}. Duration {2}",
                                        typeof(TRequest).FullName,
                                        request.Id,
                                        performanceTester.Result.Milliseconds));

                return(response);
            }
        }
예제 #12
0
        //*************************************************/
        // METHODS
        //*************************************************/
        #region Methods

        /// <summary>
        /// Setup tagger including POS
        /// </summary>
        private void SetupTagger()
        {
            PerformanceTester.StartMET("NLP");
            // Get path to Stanford NLP models
            var jarRoot = Path.Combine(Utility.GetResourcesFolder(), @"stanford-corenlp-3.9.2-models");

            // Turn off logging
            RedwoodConfiguration.current().clear().apply();
            // Set properties
            var props = new java.util.Properties();

            props.setProperty("annotators", "tokenize, ssplit, pos");
            // Set current directory
            var curDir          = Environment.CurrentDirectory;
            var modelsDirectory = curDir + "\\" + jarRoot + @"\edu\stanford\nlp\models";

            Directory.SetCurrentDirectory(jarRoot);
            // Load Stanford NLP
            Tagger = new StanfordCoreNLP(props);
            PerformanceTester.StopMET("NLP");
        }
예제 #13
0
        public Task <TResponse> GetAsync <TResponse>(ISyncRequest <TResponse> request)
            where TResponse : ISyncResponse
        {
            return(Task.Factory.StartNew(() =>
            {
                using (var performanceTester = new PerformanceTester())
                {
                    try
                    {
                        request.Id = Guid.NewGuid();

                        _log.Debug(string.Format("Start RequestTask {0}, Id - {1}", request.GetType(), request.Id));

                        using (var routerServiceProxy = _syncRouterServiceProxyFactory())
                        {
                            var response = routerServiceProxy.Execute(request);

                            _log.Debug(string.Format("Finished RequestTask {0}, Id - {1}. Duration {2}",
                                                     request.GetType(),
                                                     request.Id,
                                                     performanceTester.Result.Milliseconds));

                            return (TResponse)response;
                        }
                    }
                    catch (FaultException <GenericFault> faultException)
                    {
                        throw new RequestException(string.Format("RequestTask failed for {0}, Id - {1}. Reason '{2}'",
                                                                 request.GetType(),
                                                                 request.Id,
                                                                 faultException.Detail.Message),
                                                   faultException);
                    }
                    catch (Exception exception)
                    {
                        throw new RequestException(string.Format("RequestTask failed for {0}, Id - {1}", request.GetType(), request.Id), exception);
                    }
                }
            }));
        }
        public override void HandleData(CommandLineOptions options)
        {
            //Process and load input instances
            if (!ProcessInputInstances(out var instances, options.InputFile, InputFieldParser.ParseConstructiveKnapsackInstance))
            {
                return;
            }

            var strategy = GetConstructiveStrategy(options.Strategy);

            if (typeof(ConstructiveFPTAS).IsInstanceOfType(strategy))
            {
                AddAproxToInstances(instances, options);
            }

            //var results = strategy.SolveAll(instances, options.Strategy, options.DataSetName);
            var results = PerformanceTester.SolveWithPerformanceTest(instances, strategy, options);

            //Compare with the reference solution if specified
            if (options.ReferenceFile != null)
            {
                if (!ValidateResults <ConstructiveResult, KnapsackInstance>(results, options.ReferenceFile, SolutionValidator.ConstructiveComparator))
                {
                    return;
                }
            }



            //Output the solution
            try
            {
                OutputWriter.WriteConstructiveResults(results, options.OutputFile);
            }
            catch (IOException e)
            {
                Console.WriteLine($"Error while writing into the output file: {e.Message}");
            }
        }
예제 #15
0
        private async Task <IList <KnapsackResult> > SolveInstances(IList <KnapsackInstance> instances, bool savePlotInfo)
        {
            var options = GetOptions();

            options.SavePlotInfo = savePlotInfo;

            numberOfInstancesTotal = int.Parse(NumberOfInstances.Text);
            var instanceOffset = int.Parse(InstanceOffset.Text);

            numberOfFinishedInstances = 0;

            var results = await Task.Factory.StartNew(() =>
            {
                var performanceTester = new PerformanceTester();
                performanceTester.RaiseInstanceCalculationFinished += OnInstanceCalculationFinished;
                return(performanceTester.SolveWithPerformanceTest(instances.Skip(instanceOffset).Take(numberOfInstancesTotal).ToList(), options));
            }
                                                      );

            ProgressLabel.Content = "Calculations done!";

            return(results);
        }
예제 #16
0
        /// <summary>
        /// Analyze a given list of search strings
        /// </summary>
        /// <param name="list">The list with the search strings</param>
        /// <returns>A message result</returns>
        private MessageResult AnalyzeSearchStrings(List <string> list)
        {
            List <MessageObject> messages  = new List <MessageObject>();
            List <Material>      materials = null;

            try
            {
                PerformanceTester.StartMET("Analyze search strings");

                foreach (var str in list)
                {
                    // Checking for bot command
                    if (RunCommand(str))
                    {
                        return(new MessageResult());
                    }

                    // Search for term and topic
                    Term term = null; Topic topic = null;
                    Entity.GetTermAndTopic(out term, out topic, str);

                    if (topic == null && term == null)
                    {
                        continue;
                    }

                    // Get materials
                    // A term and a topic has the same name
                    if (term != null && topic != null)
                    {
                        PerformanceTester.StopMET("Analyze search strings");
                        messages.Add(new MessageObject(term, topic));
                        return(new MessageResult(messages.ToArray()));
                    }
                    // Get materials for a topic
                    else if (topic != null)
                    {
                        materials = Entity.GetMaterials(topicId: topic.Id);
                    }
                    // Get materials for a term
                    else
                    {
                        materials = Entity.GetMaterials(term.Id);
                    }

                    PerformanceTester.StopMET("Analyze search strings");

                    if (materials.Count == 0)
                    {
                        return(new MessageResult(Properties.Resources.no_materials_found));
                    }

                    // Add bot message
                    messages.Add(new MessageObject(string.Format(Properties.Resources.this_is_what_i_found_about, term != null ? term.Name.ToLower() : topic.Name.ToLower())));
                    // Add materials
                    foreach (var material in materials)
                    {
                        messages.Add(new MessageObject(material));
                    }

                    return(new MessageResult(messages.ToArray()));
                }

                PerformanceTester.StopMET("Analyze search strings");

                // One noun
                if (list.Count == 1)
                {
                    return(new MessageResult(string.Format(Properties.Resources.i_do_not_know_anything_about_that_noun, list[0], GetTopics())));
                }
                // More nouns
                else
                {
                    return(new MessageResult(string.Format(Properties.Resources.i_do_not_know_anything_about_those_nouns, GetTopics())));
                }
            }
            catch (Exception mes)
            {
                return(new MessageResult(mes.Message));
            }
        }
예제 #17
0
        /// <summary>
        /// Analyze a text message from the user
        /// </summary>
        /// <param name="text"></param>
        /// <returns>A message result</returns>
        private MessageResult AnalyzeText(string text)
        {
            try
            {
                var tempText = text.ToLower();

                // Get sentences that has been written
                var sentences = NLPHelper.GetSentences(tempText);

                // Does not support more than one sentence
                if (sentences.Count > 1)
                {
                    return(new MessageResult(Properties.Resources.i_cannot_process_more_than_one_sentence));
                }

                // Tagging on the given words
                List <TaggedWord> wordList = null;

                // Function for tagging
                Action <bool> tagging = (useSavedSentences) =>
                {
                    // Insert a question mark at the end of a text
                    if (!tempText.EndsWith("?"))
                    {
                        tempText += "?";
                    }
                    // Tag the words in the text
                    wordList = NLPHelper.Tag(tempText, useSavedSentences);
                };

                PerformanceTester.StartMET("Use calculator");
                // If text has any numbers use the calculator
                string output;
                if (SimpleCalculatorHelper.CheckInput(ref tempText, out output))
                {
                    // If text is not math command
                    if (output == null)
                    {
                        var input = tempText;

                        tagging(false);

                        if (wordList.Any(x => x.IsWHWord || x.IsVerb))
                        {
                            // Skip the WH-words and verbs in the beginning when using calculator
                            var context = wordList
                                          .SkipWhile(x => x.IsWHWord || x.IsVerb)
                                          .Where(x => x.POSStringIdentifier != ".")
                                          .ToList();
                            // Get text
                            var joined = context.ListToString();
                            // If sentence starts with a WH word insert an equal sign
                            if (wordList.FirstOrDefault().IsWHWord)
                            {
                                input = joined.Insert(0, "=");
                            }
                        }

                        // Use calculator
                        output = SimpleCalculatorHelper.UseCalculator(input);
                        PerformanceTester.StopMET("Use calculator");
                    }

                    // If output is not null write the calculator result to the user
                    if (output != null)
                    {
                        return(new MessageResult()
                        {
                            Messages = new MessageObject[] { new MessageObject(output) }
                        });
                    }
                }
                PerformanceTester.StopMET("Use calculator");

                tagging(true);

                PerformanceTester.StartMET("Analyze word list");
                // Analyze the input
                var analyzeResult = AnalyzeWordList(wordList);
                PerformanceTester.StopMET("Analyze word list");

                // If success
                if (analyzeResult.IsSuccess)
                {
                    // Analyze the search strings
                    return(AnalyzeSearchStrings(analyzeResult.SearchStrings));
                }
                // If error
                else
                {
                    return(new MessageResult(analyzeResult.ErrorMessage));
                }
            }
            catch (Exception mes)
            {
                return(new MessageResult(mes.Message));
            }
        }