<commit_before>﻿#region License

/*
    Copyright [2011] [<NAME>]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#endregion

using System;
using System.Linq;
using Gherkin3;

namespace PicklesDoc.Pickles
{
    public class LanguageServices
    {
        private readonly string language;
        private readonly GherkinDialectProvider dialectProvider;

        public LanguageServices(Configuration configuration)
            : this(configuration.Language)
        {
        }

        public LanguageServices(string language = "en")
        {
            this.language = language;

            this.dialectProvider = new GherkinDialectProvider();

            this.whenStepKeywordsLazy = new Lazy<string[]>(() => this.GetLanguage().WhenStepKeywords.Select(s => s.Trim()).ToArray());
        }

        private readonly Lazy<string[]> whenStepKeywordsLazy;

        public string[] WhenStepKeywords
        {
            get
            {
                return this.whenStepKeywordsLazy.Value;
            }
        }

        public string[] GivenStepKeywords { get { return this.GetLanguage().GivenStepKeywords; } }
        public string[] ThenStepKeywords { get { return this.GetLanguage().ThenStepKeywords; } }
        public string[] AndStepKeywords { get { return this.GetLanguage().AndStepKeywords; } }
        public string[] ButStepKeywords { get { return this.GetLanguage().ButStepKeywords; } }

        private string[] GetBackgroundKeywords()
        {
            return this.GetLanguage().BackgroundKeywords;
        }

        public string GetKeyword(string key)
        {
            var keywords = this.GetBackgroundKeywords();

            return keywords.FirstOrDefault();
        }

        private GherkinDialect GetLanguage()
        {
            string l = string.IsNullOrWhiteSpace(this.language) ? "en" : this.language;

            return this.dialectProvider.GetDialect(l, null);
        }
    }
}<commit_msg>Move logic to constructor<commit_after>﻿#region License

/*
    Copyright [2011] [<NAME>]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#endregion

using System;
using System.Linq;
using Gherkin3;

namespace PicklesDoc.Pickles
{
    public class LanguageServices
    {
        private readonly string language;
        private readonly GherkinDialectProvider dialectProvider;

        public LanguageServices(Configuration configuration)
            : this(configuration.Language)
        {
        }

        public LanguageServices(string language = "en")
        {
            this.language = string.IsNullOrWhiteSpace(language) ? "en" : language;

            this.dialectProvider = new GherkinDialectProvider();

            this.whenStepKeywordsLazy = new Lazy<string[]>(() => this.GetLanguage().WhenStepKeywords.Select(s => s.Trim()).ToArray());
        }

        private readonly Lazy<string[]> whenStepKeywordsLazy;

        public string[] WhenStepKeywords
        {
            get
            {
                return this.whenStepKeywordsLazy.Value;
            }
        }

        public string[] GivenStepKeywords { get { return this.GetLanguage().GivenStepKeywords; } }
        public string[] ThenStepKeywords { get { return this.GetLanguage().ThenStepKeywords; } }
        public string[] AndStepKeywords { get { return this.GetLanguage().AndStepKeywords; } }
        public string[] ButStepKeywords { get { return this.GetLanguage().ButStepKeywords; } }

        private string[] GetBackgroundKeywords()
        {
            return this.GetLanguage().BackgroundKeywords;
        }

        public string GetKeyword(string key)
        {
            var keywords = this.GetBackgroundKeywords();

            return keywords.FirstOrDefault();
        }

        private GherkinDialect GetLanguage()
        {
            string l = this.language;

            return this.dialectProvider.GetDialect(l, null);
        }
    }
}
{'fraction_non_alphanumeric': 0.08338430173292559, 'fraction_numerical': 0.003669724770642202, 'mean_word_length': 2.5168458781362006, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5381818', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1228, 'n_words': 363}