<commit_before>﻿using System.Collections.Generic;

namespace MathExpressionSolver.Tokens
{
    public interface ITokenFactory<T>
    {
        Dictionary<string, T> CustomVariables { get; set; }
        IFactorableBracketsToken<T> CreateBrackets(IFactorableToken<T>[][] arguments);
        IFactorableBracketsToken<T> CrateFunction(string funcName, IFactorableToken<T>[][] arguments);
        IFactorableToken<T> CreateValue(string s);
        IFactorableToken<T> CreateVariable(string s);
        IFactorableToken<T> CreateOperator(string s);

    }

    public class TokenFactory<T> : ITokenFactory<T>
    {
        public Dictionary<string, T> CustomVariables { get; set; }

        public virtual IFactorableBracketsToken<T> CreateBrackets(IFactorableToken<T>[][] arguments)
        {
            IFactorableBracketsToken<T> bracketToken = new BracketToken<T>();
            bracketToken.BracketedTokens[0] = arguments[0];
            return bracketToken;
        }

        public virtual IFactorableBracketsToken<T> CrateFunction(string funcName, IFactorableToken<T>[][] arguments)
        {
            IFactorableBracketsToken<T> bracketToken;
            switch (funcName)
            {
                case "exp":
                    bracketToken = (IFactorableBracketsToken<T>)new ExpToken();
                    break;
                case "if":
                    bracketToken = (IFactorableBracketsToken<T>)new IfToken();
                    break;
                case "ln":
                    bracketToken = (IFactorableBracketsToken<T>)new LnFunc();
                    break;
                case "sin":
                    bracketToken = (IFactorableBracketsToken<T>)new SinFunc();
                    break;
                case "cos":
                    bracketToken = (IFactorableBracketsToken<T>)new CosFunc();
                    break;
                case "tan":
                    bracketToken = (IFactorableBracketsToken<T>)new TanFunc();
                    break;
                case "sqrt":
                    bracketToken = (IFactorableBracketsToken<T>)new SqrtFunc();
                    break;
                default:
                    throw new TokenizerException("No function named " + funcName + " exists.");
            }
            bracketToken.BracketedTokens = arguments;
            return bracketToken;
        }

        public virtual IFactorableToken<T> CreateValue(string s)
        {
            return (IFactorableToken<T>)new ItemToken<double>() { Child = double.Parse(s) };
        }

        public virtual IFactorableToken<T> CreateVariable(string s)<commit_msg>Code cleanup.<commit_after>﻿using System.Collections.Generic;

namespace MathExpressionSolver.Tokens
{
    public interface ITokenFactory<T>
    {
        Dictionary<string, T> CustomVariables { get; set; }
        IFactorableBracketsToken<T> CreateBrackets(IFactorableToken<T>[][] arguments);
        IFactorableBracketsToken<T> CrateFunction(string s, IFactorableToken<T>[][] arguments);
        IFactorableToken<T> CreateValue(string s);
        IFactorableToken<T> CreateVariable(string s);
        IFactorableToken<T> CreateOperator(string s);

    }

    public class TokenFactory<T> : ITokenFactory<T>
    {
        public Dictionary<string, T> CustomVariables { get; set; }

        public virtual IFactorableBracketsToken<T> CreateBrackets(IFactorableToken<T>[][] arguments)
        {
            IFactorableBracketsToken<T> bracketToken = new BracketToken<T>();
            bracketToken.BracketedTokens[0] = arguments[0];
            return bracketToken;
        }

        public virtual IFactorableBracketsToken<T> CrateFunction(string s, IFactorableToken<T>[][] arguments)
        {
            IFactorableBracketsToken<T> bracketToken;
            switch (s)
            {
                case "exp":
                    bracketToken = (IFactorableBracketsToken<T>)new ExpToken();
                    break;
                case "if":
                    bracketToken = (IFactorableBracketsToken<T>)new IfToken();
                    break;
                case "ln":
                    bracketToken = (IFactorableBracketsToken<T>)new LnFunc();
                    break;
                case "sin":
                    bracketToken = (IFactorableBracketsToken<T>)new SinFunc();
                    break;
                case "cos":
                    bracketToken = (IFactorableBracketsToken<T>)new CosFunc();
                    break;
                case "tan":
                    bracketToken = (IFactorableBracketsToken<T>)new TanFunc();
                    break;
                case "sqrt":
                    bracketToken = (IFactorableBracketsToken<T>)new SqrtFunc();
                    break;
                default:
                    throw new TokenizerException("No function named " + s + " exists.");
            }
            bracketToken.BracketedTokens = arguments;
            return bracketToken;
        }

        public virtual IFactorableToken<T> CreateValue(string s)
        {
            return (IFactorableToken<T>)new ItemToken<double>() { Child = double.Parse(s) };
        }

        public virtual IFactorableToken<T> CreateVariable(string s)
{'fraction_non_alphanumeric': 0.09325928762926082, 'fraction_numerical': 0.0007659900421294523, 'mean_word_length': 1.9525155455059355, 'pattern_counts': {'":': 14, '<': 63, '<?xml version=': 0, '>': 63, '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': '4906612', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1306, 'n_words': 264}