<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Linq;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace EDILibrary
{

    [Obsolete("Use " + nameof(EdiObject) + " instead.", true)]
    // ReSharper disable once InconsistentNaming
    public class IEdiObject
    {
    }

    [DataContract]
    public class EdiObject
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string MigName { get; set; }
        [DataMember]
        public string Key { get; set; }

        [DataMember]
        public string Edi { get; set; }
        public EdiObject Parent { get; private set; }
        XElement template;
        [DataMember]
        public List<EdiObject> Children { get; set; }
        public List<EdiObject> SelfOrChildren
        {
            get { var list = Children.Take(Children.Count).ToList(); list.Add(this); return list; }
        }
        [DataMember]
        public Dictionary<string, List<string>> Fields { get; set; }
        [DataMember]
        public Dictionary<string, string> MigFields { get; set; }
        [DataMember]
        public Dictionary<string, string> EdiFields { get; set; }
        public EdiObject(EDIEnums enumValue, XElement temp, string keyValue) : this(EDIEnumHelper.GetDescription(enumValue), temp, keyValue)
        {

        }
        public EdiObject(string name, XElement temp, string keyValue)
        {
            Name = name;
            Children = new List<EdiObject>();
            Fields = new Dictionary<string, List<string>>();
            MigFields = new Dictionary<string, string>();
            EdiFields = new Dictionary<string, string>();
            template = temp;
            Key = keyValue;

        }
        protected static string GenerateKey(string objectName)
        {
            switch (objectName)
            {
                case "Dokument":
                case "Nachricht":
                case "Vorgang":
                    {
                        return Guid.NewGuid().ToString("N").Substring(0, 13).ToUpper();
                    }
                default:
                    {
                        return null;
                    }
            }
        }

        protected void ParseJSON(dynamic json)
        {

            foreach (var child in json.Children<JProperty>())
            {
                if (child.Value.GetType() == typeof(JArray))
                {
                    foreach (var childValue in child.Value)
                    {
                        var childNode = new EdiObject(child.Name, null, GenerateKey(child.Name));
                        childNode.ParseJSON(childValue);
                        if (childNode.Fields.Any() || childNode.Children.Any())
                        {
                            AddChild(childNode);
                        }
                    }
                }
                else
                {
                    if (child.Value != null && child.Value is JObject)
                    {
                        //go through the child properties and dot "." them together
                        foreach (var childprop in (child.Value as JObject).Properties())
                        {
                            //only allow one nest level, so only strings allowed here
                            if (childprop.Value != null && (childprop.Value.Type == JTokenType.Float))
                            {
                                Fields.Add(child.Name + "." + childprop.Name, new List<string> { childprop.Value.Value<float>().ToString() });
                            }
                            else if (childprop.Value != null && (childprop.Value.Type == JTokenType.String || childprop.Value.Type == JTokenType.Integer))
                            {
                                Fields.Add(child.Name + "." + childprop.Name, new List<string> { childprop.Value.Value<string>() });
                            }
                        }
                    }
                    else if (!(child.Value == null || child.Type == JTokenType.Null))
                    {
                        if (child.Value.Type == JTokenType.Float)
                        {
                            Fields.Add(child.Name, new List<string> { child.Value<float>().ToString() });
                        }
                        else
                        {
                            Fields.Add(child.Name, new List<string> { child.Value.ToString() });
                        }
                    }
                }
            }

        }
        public static EdiObject CreateFromJSON(string JSON)
        {
            dynamic json = JsonConvert.DeserializeObject(JSON);
            var doc = json["Dokument"][0];
            var root = new EdiObject(EDIEnums.Dokument, null, GenerateKey("Dokument"));
            root.ParseJSON(doc);
            return root;
        }

        public override string ToString()
        {
            return Name + "  " + Key;
        }
        protected static void Recurse(XElement elem, EdiObject child)
        {
            foreach (var (key, value) in child.Fields)
            {
                var f = new XElement("Field");
                f.SetAttributeValue("name", key);<commit_msg>next stop: formatters<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Linq;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace EDILibrary
{

    [Obsolete("Use " + nameof(EdiObject) + " instead.", true)]
    // ReSharper disable once InconsistentNaming
    public class IEdiObject
    {
    }

    [DataContract]
    public class EdiObject
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string MigName { get; set; }
        [DataMember]
        public string Key { get; set; }

        [DataMember]
        public string Edi { get; set; }
        public EdiObject Parent { get; private set; }
        XElement template;
        [DataMember]
        public List<EdiObject> Children { get; set; }
        public List<EdiObject> SelfOrChildren
        {
            get { var list = Children.Take(Children.Count).ToList(); list.Add(this); return list; }
        }
        [DataMember]
        public Dictionary<string, List<string>> Fields { get; set; }
        [DataMember]
        public Dictionary<string, string> MigFields { get; set; }
        [DataMember]
        public Dictionary<string, string> EdiFields { get; set; }
        public EdiObject(EDIEnums enumValue, XElement temp, string keyValue) : this(EDIEnumHelper.GetDescription(enumValue), temp, keyValue)
        {

        }
        public EdiObject(string name, XElement temp, string keyValue)
        {
            Name = name;
            Children = new List<EdiObject>();
            Fields = new Dictionary<string, List<string>>();
            MigFields = new Dictionary<string, string>();
            EdiFields = new Dictionary<string, string>();
            template = temp;
            Key = keyValue;

        }
        protected static string GenerateKey(string objectName)
        {
            switch (objectName)
            {
                case "Dokument":
                case "Nachricht":
                case "Vorgang":
                    {
                        return Guid.NewGuid().ToString("N").Substring(0, 13).ToUpper();
                    }
                default:
                    {
                        return null;
                    }
            }
        }

        protected void ParseJSON(dynamic json)
        {

            foreach (var child in json.Children<JProperty>())
            {
                if (child.Value.GetType() == typeof(JArray))
                {
                    foreach (var childValue in child.Value)
                    {
                        var childNode = new EdiObject(child.Name, null, GenerateKey(child.Name));
                        childNode.ParseJSON(childValue);
                        if (childNode.Fields.Any() || childNode.Children.Any())
                        {
                            AddChild(childNode);
                        }
                    }
                }
                else
                {
                    if (child.Value != null && child.Value is JObject)
                    {
                        //go through the child properties and dot "." them together
                        foreach (var childprop in (child.Value as JObject).Properties())
                        {
                            //only allow one nest level, so only strings allowed here
                            if (childprop.Value != null && (childprop.Value.Type == JTokenType.Float))
                            {
                                Fields.Add(child.Name + "." + childprop.Name, new List<string> { childprop.Value.Value<float>().ToString() });
                            }
                            else if (childprop.Value != null && (childprop.Value.Type == JTokenType.String || childprop.Value.Type == JTokenType.Integer))
                            {
                                Fields.Add(child.Name + "." + childprop.Name, new List<string> { childprop.Value.Value<string>() });
                            }
                        }
                    }
                    else if (!(child.Value == null || child.Type == JTokenType.Null))
                    {
                        if (child.Value.Type == JTokenType.Float)
                        {
                            Fields.Add(child.Name, new List<string> { child.Value.ToString("F3") });
                        }
                        else
                        {
                            Fields.Add(child.Name, new List<string> { child.Value.ToString() });
                        }
                    }
                }
            }

        }
        public static EdiObject CreateFromJSON(string JSON)
        {
            dynamic json = JsonConvert.DeserializeObject(JSON);
            var doc = json["Dokument"][0];
            var root = new EdiObject(EDIEnums.Dokument, null, GenerateKey("Dokument"));
            root.ParseJSON(doc);
            return root;
        }

        public override string ToString()
        {
            return Name + "  " + Key;
        }
        protected static void Recurse(XElement elem, EdiObject child)
        {
            foreach (var (key, value) in child.Fields)
            {
                var f = new XElement("Field");
                f.SetAttributeValue("name", key);
{'fraction_non_alphanumeric': 0.09796260117220207, 'fraction_numerical': 0.0008372871895060006, 'mean_word_length': 1.2809251007850626, 'pattern_counts': {'":': 6, '<': 40, '<?xml version=': 0, '>': 40, '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': '5866084', 'n_tokens_mistral': 2685, 'n_tokens_neox': 2560, 'n_words': 615}