<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using Arkivverket.Arkade.Core.ExternalModels.Addml;
using Arkivverket.Arkade.Core.Util;

namespace Arkivverket.Arkade.Core.Base
{
    public class ArchiveDetails
    {
        public string ArchiveCreators => GetArchiveCreators();
        public string ArchivalPeriod => GetArchivalPeriod();
        public string SystemName => GetSystemName();
        public string SystemType => GetSystemType();
        public virtual string ArchiveStandard => GetArchiveStandardVersion();
        public Dictionary<string, IEnumerable<string>> DocumentedXmlUnits => GetDocumentedXmlUnits();
        public Dictionary<string, IEnumerable<string>> StandardXmlUnits => GetStandardXmlUnits();

        private readonly addml _addml;

        public ArchiveDetails(addml addml)
        {
            _addml = addml;
        }

        private string GetArchiveCreators()
        {
            try
            {
                IEnumerable<additionalElement> archiveCreators = GetAdditionalElements(
                    GetContextAdditionalElementsRoot(), "recordCreator"
                );

                return string.Join(", ", archiveCreators.Select(a => a.value));
            }
            catch
            {
                return string.Empty;
            }
        }

        private string GetArchivalPeriod()
        {
            try
            {
                additionalElement archivalPeriodElement = GetAdditionalElements(
                    GetContentAdditionalElementsRoot(), "archivalPeriod"
                ).FirstOrDefault();

                property startDate = archivalPeriodElement?.properties.FirstOrDefault(p => p.name.Equals("startDate"));
                property endDate = archivalPeriodElement?.properties.FirstOrDefault(p => p.name.Equals("endDate"));

                return $"{startDate?.value} - {endDate?.value}";
            }
            catch
            {
                return string.Empty;
            }
        }

        private string GetSystemName()
        {
            try
            {
                return GetAdditionalElements(GetContextAdditionalElementsRoot(), "systemName").FirstOrDefault()?.value;
            }
            catch
            {
                return string.Empty;
            }
        }

        private string GetSystemType()
        {
            try
            {
                return GetAdditionalElements(GetContextAdditionalElementsRoot(), "systemType").FirstOrDefault()?.value;
            }
            catch
            {
                return string.Empty;
            }
        }

        private string GetArchiveStandardVersion()
        {
            try
            {
                dataObject archiveExtractionElement = _addml.dataset[0].dataObjects.dataObject[0];

                string archiveExtractionTypeVersion = archiveExtractionElement.properties
                    .FirstOrDefault(property => property.name == "info")?.properties
                    .FirstOrDefault(property => property.name == "type")?.properties
                    .FirstOrDefault(property => property.name == "version")?.value;

                return $"{archiveExtractionTypeVersion}";
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }

        private Dictionary<string, IEnumerable<string>> GetDocumentedXmlUnits()
        {
            var documentedXmlUnits = new Dictionary<string, IEnumerable<string>>();

            try
            {
                dataObject archiveExtractionElement = _addml.dataset[0].dataObjects.dataObject[0];
                List<dataObject> fileElements = archiveExtractionElement.dataObjects.dataObject.ToList();

                foreach (dataObject fileElement in fileElements)
                {
                    string xmlFileName = fileElement.properties
                        .FirstOrDefault(property => property.name == "file")?.properties
                        .FirstOrDefault(property => property.name == "name")?.value;

                    if (string.IsNullOrEmpty(xmlFileName))<commit_msg>Make sure archive standard version is stored at first query<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using Arkivverket.Arkade.Core.ExternalModels.Addml;
using Arkivverket.Arkade.Core.Util;

namespace Arkivverket.Arkade.Core.Base
{
    public class ArchiveDetails
    {
        private string _archiveStandard;

        public string ArchiveCreators => GetArchiveCreators();
        public string ArchivalPeriod => GetArchivalPeriod();
        public string SystemName => GetSystemName();
        public string SystemType => GetSystemType();
        public virtual string ArchiveStandard => _archiveStandard?? GetArchiveStandardVersion();
        public Dictionary<string, IEnumerable<string>> DocumentedXmlUnits => GetDocumentedXmlUnits();
        public Dictionary<string, IEnumerable<string>> StandardXmlUnits => GetStandardXmlUnits();

        private readonly addml _addml;

        public ArchiveDetails(addml addml)
        {
            _addml = addml;
        }

        private string GetArchiveCreators()
        {
            try
            {
                IEnumerable<additionalElement> archiveCreators = GetAdditionalElements(
                    GetContextAdditionalElementsRoot(), "recordCreator"
                );

                return string.Join(", ", archiveCreators.Select(a => a.value));
            }
            catch
            {
                return string.Empty;
            }
        }

        private string GetArchivalPeriod()
        {
            try
            {
                additionalElement archivalPeriodElement = GetAdditionalElements(
                    GetContentAdditionalElementsRoot(), "archivalPeriod"
                ).FirstOrDefault();

                property startDate = archivalPeriodElement?.properties.FirstOrDefault(p => p.name.Equals("startDate"));
                property endDate = archivalPeriodElement?.properties.FirstOrDefault(p => p.name.Equals("endDate"));

                return $"{startDate?.value} - {endDate?.value}";
            }
            catch
            {
                return string.Empty;
            }
        }

        private string GetSystemName()
        {
            try
            {
                return GetAdditionalElements(GetContextAdditionalElementsRoot(), "systemName").FirstOrDefault()?.value;
            }
            catch
            {
                return string.Empty;
            }
        }

        private string GetSystemType()
        {
            try
            {
                return GetAdditionalElements(GetContextAdditionalElementsRoot(), "systemType").FirstOrDefault()?.value;
            }
            catch
            {
                return string.Empty;
            }
        }

        private string GetArchiveStandardVersion()
        {
            try
            {
                dataObject archiveExtractionElement = _addml.dataset[0].dataObjects.dataObject[0];

                string archiveExtractionTypeVersion = archiveExtractionElement.properties
                    .FirstOrDefault(property => property.name == "info")?.properties
                    .FirstOrDefault(property => property.name == "type")?.properties
                    .FirstOrDefault(property => property.name == "version")?.value;

                _archiveStandard = archiveExtractionTypeVersion;
                return archiveExtractionTypeVersion;
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }

        private Dictionary<string, IEnumerable<string>> GetDocumentedXmlUnits()
        {
            var documentedXmlUnits = new Dictionary<string, IEnumerable<string>>();

            try
            {
                dataObject archiveExtractionElement = _addml.dataset[0].dataObjects.dataObject[0];
                List<dataObject> fileElements = archiveExtractionElement.dataObjects.dataObject.ToList();

                foreach (dataObject fileElement in fileElements)
                {
                    string xmlFileName = fileElement.properties
                        .FirstOrDefault(property => property.name == "file")?.properties
                        .FirstOrDefault(property => property.name == "name")?.value;

                    if (string.IsNullOrEmpty(xmlFileName))
{'fraction_non_alphanumeric': 0.08440410232229165, 'fraction_numerical': 0.0009430625957797949, 'mean_word_length': 1.7834645669291338, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4663692', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1871, 'n_words': 358}