<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace SIL.WritingSystems
{
	/// <summary>
	/// A trivial implementation of the interface.
	/// </summary>
	public class DefaultKeyboardController : IKeyboardController
	{
		/// <summary>
		/// A common definition of the trivial thing all the Get methods currently return.
		/// </summary>
		private readonly DefaultKeyboardDefinition _trivialKeyboard = new DefaultKeyboardDefinition("en-US_English", "English");

		public IKeyboardDefinition GetKeyboard(string id)
		{
			return _trivialKeyboard;
		}

		public IKeyboardDefinition GetKeyboard(string layoutName, string locale)
		{
			return _trivialKeyboard;
		}

		public IKeyboardDefinition GetKeyboard(WritingSystemDefinition writingSystem)
		{
			return _trivialKeyboard;
		}

		public IKeyboardDefinition GetKeyboard(IInputLanguage language)
		{
			return _trivialKeyboard;
		}

		public void SetKeyboard(IKeyboardDefinition keyboard)
		{
		}

		public void SetKeyboard(string id)
		{
		}

		public void SetKeyboard(string layoutName, string locale)
		{
		}

		public void SetKeyboard(WritingSystemDefinition writingSystem)
		{
		}

		public void SetKeyboard(IInputLanguage language)
		{
		}

		/// <summary>
		/// Activates the keyboard of the default input language
		/// </summary>
		public void ActivateDefaultKeyboard()
		{
		}

		public IEnumerable<IKeyboardDefinition> AllAvailableKeyboards
		{
			get {return new IKeyboardDefinition[0];}
		}

		public void UpdateAvailableKeyboards()
		{
		}

		public virtual IKeyboardDefinition DefaultForWritingSystem(WritingSystemDefinition ws)
		{
			return _trivialKeyboard;
		}

		public IKeyboardDefinition LegacyForWritingSystem(WritingSystemDefinition ws)
		{
			return null;
		}

		/// <summary>
		/// Creates and returns a keyboard definition object based on the layout and locale.
		/// </summary>
		/// <remarks>The keyboard controller implementing this method will have to check the
		/// availability of the keyboard and what engine provides it.</remarks>
		public virtual IKeyboardDefinition CreateKeyboardDefinition(string id, KeyboardFormat format, IEnumerable<string> urls)
		{
			_trivialKeyboard.Format = format;
			
			// Clear any exisiting URL list
			_trivialKeyboard.Urls.Clear();

			foreach (string url in urls)
			{
				_trivialKeyboard.Urls.Add(url);
			}
			return _trivialKeyboard;
		}

		/// <summary>
		/// Gets the currently active keyboard
		/// </summary>
		public IKeyboardDefinition ActiveKeyboard { get; set; }

		#region Implementation of IDisposable
		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
		/// </summary>
		public void Dispose()
		{
			GC.SuppressFinalize(this);
			// nothing else to do
		}
		#endregion
	}
}<commit_msg>Provide more complete implementation of IKeyboardController for DefaultKeyboardController<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace SIL.WritingSystems
{
	/// <summary>
	/// A trivial implementation of the interface.
	/// </summary>
	public class DefaultKeyboardController : IKeyboardController
	{
		/// <summary>
		/// A common definition of the trivial thing all the Get methods currently return.
		/// </summary>
		private readonly DefaultKeyboardDefinition _defaultKeyboard = new DefaultKeyboardDefinition("en-US_English", "English");
		private readonly Dictionary<string, DefaultKeyboardDefinition> _keyboards = new Dictionary<string, DefaultKeyboardDefinition>();

		public DefaultKeyboardController()
		{
			_keyboards[_defaultKeyboard.Id] = _defaultKeyboard;
		}

		public IKeyboardDefinition GetKeyboard(string id)
		{
			DefaultKeyboardDefinition keyboard;
			if (_keyboards.TryGetValue(id, out keyboard))
				return keyboard;
			return null;
		}

		public IKeyboardDefinition GetKeyboard(string layoutName, string locale)
		{
			return _keyboards.Values.FirstOrDefault(k => k.Layout == layoutName && k.Locale == locale);
		}

		public IKeyboardDefinition GetKeyboard(WritingSystemDefinition writingSystem)
		{
			return writingSystem.LocalKeyboard;
		}

		public IKeyboardDefinition GetKeyboard(IInputLanguage language)
		{
			return GetKeyboard(language.LayoutName, language.Culture.Name);
		}

		public void SetKeyboard(IKeyboardDefinition keyboard)
		{
			ActiveKeyboard = keyboard;
		}

		public void SetKeyboard(string id)
		{
			ActiveKeyboard = GetKeyboard(id);
		}

		public void SetKeyboard(string layoutName, string locale)
		{
			ActiveKeyboard = GetKeyboard(layoutName, locale);
		}

		public void SetKeyboard(WritingSystemDefinition writingSystem)
		{
			ActiveKeyboard = GetKeyboard(writingSystem);
		}

		public void SetKeyboard(IInputLanguage language)
		{
			ActiveKeyboard = GetKeyboard(language);
		}

		/// <summary>
		/// Activates the keyboard of the default input language
		/// </summary>
		public void ActivateDefaultKeyboard()
		{
			ActiveKeyboard = _defaultKeyboard;
		}

		public IEnumerable<IKeyboardDefinition> AllAvailableKeyboards
		{
			get { return _keyboards.Values; }
		}

		public void UpdateAvailableKeyboards()
		{
		}

		public virtual IKeyboardDefinition DefaultForWritingSystem(WritingSystemDefinition ws)
		{
			return LegacyForWritingSystem(ws) ?? _defaultKeyboard;
		}

		public IKeyboardDefinition LegacyForWritingSystem(WritingSystemDefinition ws)
		{
			return null;
		}

		/// <summary>
		/// Creates and returns a keyboard definition object based on the layout and locale.
		/// </summary>
		/// <remarks>The keyboard controller implementing this method will have to check the
		/// availability of the keyboard and what engine provides it.</remarks>
		public virtual IKeyboardDefinition CreateKeyboardDefinition(string id, KeyboardFormat format, IEnumerable<string> urls)
		{
			DefaultKeyboardDefinition keyboard;
			if (!_keyboards.TryGetValue(id, out keyboard))
			{
				string[] parts = id.Split('_');
				string locale = parts[0];
				string layout = parts.Length > 1 ? parts[1] : null;
				keyboard = new DefaultKeyboardDefinition(id, layout, layout, locale, false);
				_keyboards[id] = keyboard;
			}

			keyboard.Format = format;
			
			// Clear any exisiting URL list
			keyboard.Urls.Clear();
			foreach (string url in urls)
				keyboard.Urls.Add(url);
			return keyboard;
		}

		/// <summary>
		/// Gets the currently active keyboard
		/// </summary>
		public IKeyboardDefinition ActiveKeyboard { get; set; }

		public void Reset()
		{
			_keyboards.Clear();
			_keyboards[_defaultKeyboard.Id] = _defaultKeyboard;
		}

		#region Implementation of IDisposable
		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
		/// </summary>
		public void Dispose()
		{
			GC.SuppressFinalize(this);
			// nothing else to do
		}
		#endregion
	}
}
{'fraction_non_alphanumeric': 0.08881770529994176, 'fraction_numerical': 0.0005824111822947001, 'mean_word_length': 3.9346264367816093, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7550117', 'n_tokens_mistral': 2158, 'n_tokens_neox': 1916, 'n_words': 526}