<commit_before>﻿using System.Collections.Generic;

namespace FuzzyLogic
{
	public class FuzzyVariable
	{
		private IDictionary<string, IFuzzySet> _memberSets;
		private double _min;
		private double _max;

		public FuzzyVariable()
		{
			_memberSets = new Dictionary<string, IFuzzySet>();
		}

		public void AddSet(string name, IFuzzySet set)
		{
			if (_memberSets.ContainsKey(name))
			{
				_memberSets[name] = set;
			}
			else
			{
				_memberSets.Add(name, set);
			}

			if (_min > set.Min)
			{
				_min = set.Min;
			}
			if (_max < set.Max)
			{
				_max = set.Max;
			}
		}

		public void Fuzzify(double value)
		{
			foreach (IFuzzySet set in _memberSets.Values)
			{
				set.Value = set.CalculateValue(value);
			}
		}

		public double DeFuzzifyMaxAv()
		{
			double bottom = 0;
			double top = 0;

			foreach (IFuzzySet set in _memberSets.Values)
			{
				bottom += set.Value;
				top += set.Peak * set.Value;
			}
			if (bottom == 0)
			{
				return 0;
			}
			return top / bottom;
		}

		public IFuzzySet AddTriangularSet(
			string name, double min, double peak, double max)
		{
			IFuzzySet set = new Triangle(peak, peak - min, max - peak);
			AddSet(name, set);
			return set;
		}

		public IFuzzySet addLeftShoulderSet(string name, float min, float peak, float max) {
			IFuzzySet set = new LeftShoulder(peak, peak - min, max - peak);
			AddSet(name, set);
			return set;
		}

		public IFuzzySet addRightShoulderSet(string name, float min, float peak, float max) {
			IFuzzySet set = new RightShoulder(peak, peak - min, max - peak);
			AddSet(name, set);
			return set;
		}
	}
}
<commit_msg>Refactored FuzzyVariable a la C#.<commit_after>﻿using System.Collections.Generic;

namespace FuzzyLogic
{
	public class FuzzyVariable
	{
		private IDictionary<string, IFuzzySet> _memberSets;
		private double _min;
		private double _max;

		public FuzzyVariable()
		{
			_memberSets = new Dictionary<string, IFuzzySet>();
		}

		public void AddSet(string name, IFuzzySet set)
		{
			if (_memberSets.ContainsKey(name))
			{
				_memberSets[name] = set;
			}
			else
			{
				_memberSets.Add(name, set);
			}

			if (_min > set.Min)
			{
				_min = set.Min;
			}
			if (_max < set.Max)
			{
				_max = set.Max;
			}
		}

		public void Fuzzify(double value)
		{
			foreach (IFuzzySet set in _memberSets.Values)
			{
				set.Value = set.CalculateValue(value);
			}
		}

		public double DeFuzzifyMaxAv()
		{
			double bottom = 0;
			double top = 0;

			foreach (IFuzzySet set in _memberSets.Values)
			{
				bottom += set.Value;
				top += set.Peak * set.Value;
			}
			if (bottom == 0)
			{
				return 0;
			}
			return top / bottom;
		}

		public IFuzzySet AddTriangularSet(string name,
			double min, double peak, double max)
		{
			IFuzzySet set = new Triangle(peak, peak - min, max - peak);
			AddSet(name, set);
			return set;
		}

		public IFuzzySet AddLeftShoulderSet(string name,
			double min, double peak, double max)
		{
			IFuzzySet set = new LeftShoulder(peak, peak - min, max - peak);
			AddSet(name, set);
			return set;
		}

		public IFuzzySet AddRightShoulderSet(string name,
			double min, double peak, double max)
		{
			IFuzzySet set = new RightShoulder(peak, peak - min, max - peak);
			AddSet(name, set);
			return set;
		}
	}
}

{'fraction_non_alphanumeric': 0.10335766423357665, 'fraction_numerical': 0.0023357664233576644, 'mean_word_length': 2.3359298928919183, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3682276', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1154, 'n_words': 305}