Example #1
0
        public async Task RunAtTimeOf(DateTime now)
        {
            var config = _ctx.JobGettingConfig.FirstOrDefault();

            if (config == null)
            {
                return;
            }
            _logger.LogInformation("KeyPhraseGeneratorJob Job Starts... ");

            string connectionString = Secrets.GetDBConnectionString(_configuration);

            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                MySqlCommand command = new MySqlCommand(@"
                   SELECT `JobPostings`.Id, `JobPostings`.Description FROM `jobtransparency`.`JobPostings`
                  WHERE `JobPostings`.Id NOT IN(SELECT `KeyPhrase`.JobPostingId FROM `jobtransparency`.`KeyPhrase`)", connection);
                command.CommandTimeout = config.SQLCommandTimeOut;

                try
                {
                    connection.Open();
                    var reader = await command.ExecuteReaderAsync();

                    while (reader.Read())
                    {
                        var Description = (string)reader[1];
                        var Id          = (int)reader[0];
                        if (Description.Length <= 5)
                        {
                            continue;
                        }

                        Description = new string(Description.Where(c => !char.IsPunctuation(c)).ToArray());

                        KeyPhrasesWrapperDTO wrapper = await _NLTKService.ExtractKeyPhrases(Description);

                        if (wrapper != null && wrapper.rank_list != null && wrapper.rank_list.Count > 0)
                        {
                            List <KeyPhrase> ListKeyPhrase = new List <KeyPhrase>();
                            _logger.LogInformation("List<KeyPhrase> ListKeyPhrase");
                            foreach (KeyPhraseDTO item in wrapper.rank_list)
                            {
                                if (item.Affinty > config.MinAffintyScore)
                                {
                                    ListKeyPhrase.Add(new KeyPhrase
                                    {
                                        Affinty      = item.Affinty,
                                        Text         = item.Text,
                                        JobPostingId = Id
                                    });
                                }


                                _logger.LogInformation($"item.Affinty {item.Affinty}");
                                _logger.LogInformation($"item.Text {item.Text}");
                            }

                            _KeyPharseRepository.CreateKeyPhrases(ListKeyPhrase);
                            _logger.LogInformation("_KeyPharseRepository.CreateKeyPhrases(ListKeyPhrase);");
                        }
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "KeyPhraseGeneratorJob Ends... ");
                }
            }

            _logger.LogInformation("KeyPhraseGeneratorJob Ends... ");
        }