<commit_before>﻿using System.Collections.Generic;
using Basement.BLFramework.Core.Context;
using Basement.Common;

namespace Basement.BLFramework.Core.Reference.Description
{
    public abstract class DescriptionBase : IDescription
    {
        public bool selectable { get; }
        public string key { get; }
        
        protected readonly RawNode node;
        
        private readonly WeakRef<IContext> _weakContext;
        private WeakRef<IDescription> _weakParent;
        private IDictionary<string, IDescription> _items;
        

        protected DescriptionBase(RawNode node, IContext context = null)
        {
            this.node = node;
            key = node.nodeKey;
            selectable = node.GetBool("selectable", true);

            if (context != null)
            {
                _weakContext = new WeakRef<IContext>(context);
            }
        }

        public string GetDescriptionPath()
        {
            var path = new List<string>();
            IDescription current = this;
            
            while (current != null)
            {
                path.Add(current.key);
                current = current.GetParent();
            }
            
            path.Reverse();
            return string.Join(".", path.ToArray());
        }

        public virtual void Initialization()
        {
        }

        protected IDictionary<string, IDescription> GetChildren()
        {
            return _items ?? (_items = new Dictionary<string, IDescription>());
        }
        
        public virtual IDescription GetChild(string collectionKey)
        {
            return GetChildren()[collectionKey];
        }

        public void AddChild(string collectionKey, IDescription child)
        {
            GetChildren().Add(collectionKey, child);
            child.SetParent(this);
        }

        public virtual void RemoveChild(string collectionKey)
        {
            var description = GetChildren()[collectionKey];
            description.SetParent(null);
            GetChildren().Remove(collectionKey);
        }<commit_msg>add generic GetChild to DescriptionBase<commit_after>﻿using System.Collections.Generic;
using Basement.BLFramework.Core.Context;
using Basement.Common;

namespace Basement.BLFramework.Core.Reference.Description
{
    public abstract class DescriptionBase : IDescription
    {
        public bool selectable { get; }
        public string key { get; }
        
        protected readonly RawNode node;
        
        private readonly WeakRef<IContext> _weakContext;
        private WeakRef<IDescription> _weakParent;
        private IDictionary<string, IDescription> _items;
        

        protected DescriptionBase(RawNode node, IContext context = null)
        {
            this.node = node;
            key = node.nodeKey;
            selectable = node.GetBool("selectable", true);

            if (context != null)
            {
                _weakContext = new WeakRef<IContext>(context);
            }
        }

        public string GetDescriptionPath()
        {
            var path = new List<string>();
            IDescription current = this;
            
            while (current != null)
            {
                path.Add(current.key);
                current = current.GetParent();
            }
            
            path.Reverse();
            return string.Join(".", path.ToArray());
        }

        public virtual void Initialization()
        {
        }

        protected IDictionary<string, IDescription> GetChildren()
        {
            return _items ?? (_items = new Dictionary<string, IDescription>());
        }
        
        public virtual IDescription GetChild(string collectionKey)
        {
            return GetChildren()[collectionKey];
        }

        public virtual T GetChild<T>(string collectionKey) where T : IDescription
        {
            return (T)GetChildren()[collectionKey];
        }

        public void AddChild(string collectionKey, IDescription child)
        {
            GetChildren().Add(collectionKey, child);
            child.SetParent(this);
        }

        public virtual void RemoveChild(string collectionKey)
        {
            var description = GetChildren()[collectionKey];
            description.SetParent(null);
            GetChildren().Remove(collectionKey);
        }
{'fraction_non_alphanumeric': 0.08514534218356604, 'fraction_numerical': 0.0, 'mean_word_length': 1.7816677275620625, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '2769264', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1010, 'n_words': 244}