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

namespace Kip
{
    /// <summary>
    /// Represents a PrintCapabilities document defined in the Print Schema
    /// Specification.
    /// </summary>
    public sealed class Capabilities : IEquatable<Capabilities>
    {

        #region Constructors

        /// <summary>
        /// Constructs with children: <see cref="Feature"/>,
        /// <see cref="ParameterDef"/> and/or <see cref="Property"/>.
        /// </summary>
        public Capabilities(params CapabilitiesChild[] elements)
        {
            var features = ImmutableNamedElementCollection.CreateFeatureCollectionBuilder();
            var parameters = ImmutableNamedElementCollection.CreateParameterDefCollectionBuilder();
            var properties = ImmutableNamedElementCollection.CreatePropertyCollectionBuilder();

            foreach (var e in elements)
            {
                e.Apply(
                    onFeature: x => features.Add(x),
                    onParameterDef: x => parameters.Add(x),
                    onProperty: x => properties.Add(x));
            }

            _features = features.ToImmutable();
            _parameters = parameters.ToImmutable();
            _properties = properties.ToImmutable();
            _declaredNamespaces = NamespaceDeclarationCollection.Default;
        }

        internal Capabilities(
            ImmutableNamedElementCollection<Feature> features,
            ImmutableNamedElementCollection<ParameterDef> parameters,
            ImmutableNamedElementCollection<Property> properties,
            NamespaceDeclarationCollection namespaceDeclarations)
        {
            _features = features;
            _parameters = parameters;
            _properties = properties;
            _declaredNamespaces = namespaceDeclarations;
        }

        #endregion

        #region Features

        private readonly ImmutableNamedElementCollection<Feature> _features
            = ImmutableNamedElementCollection.CreateFeatureCollection();
        public IReadOnlyNamedElementCollection<Feature> Features
        {
            get { return _features; }
        }

        public IReadOnlyList<Option> this[FeatureName name]
        {
            get
            {
                if (name == null) throw new ArgumentNullException(nameof(name));
                return _features[name].Options();
            }
        }

        public IReadOnlyList<Option> Get(FeatureName name)
        {
            return _features.Get(name)?.Options();
        }

        public Capabilities Update(FeatureName name, Func<Option, Option> func)
        {
            var ft = _features.Get(name);
             if (ft == null) return this;

            return new Capabilities(_features.SetItem(ft.Update(func)), _parameters, _properties, _declaredNamespaces);
        }

        public IReadOnlyList<Option> this[FeatureName name1, FeatureName name2]
        {
            get
            {
                if (name1 == null) throw new ArgumentNullException(nameof(name1));
                if (name2 == null) throw new ArgumentNullException(nameof(name2));
                return _features[name1][name2];
            }
        }

        public IReadOnlyList<Option> Get(FeatureName name1, FeatureName name2)
        {
            return _features.Get(name1)?.Get(name2);
        }

        #endregion

        #region Parameters

        private readonly ImmutableNamedElementCollection<ParameterDef> _parameters
            = ImmutableNamedElementCollection.CreateParameterDefCollection();
        public IReadOnlyNamedElementCollection<ParameterDef> Parameters
        {
            get { return _parameters; }
        }
<commit_msg>Implement Property accessor<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;

namespace Kip
{
    /// <summary>
    /// Represents a PrintCapabilities document defined in the Print Schema
    /// Specification.
    /// </summary>
    public sealed class Capabilities : IEquatable<Capabilities>
    {

        #region Constructors

        /// <summary>
        /// Constructs with children: <see cref="Feature"/>,
        /// <see cref="ParameterDef"/> and/or <see cref="Property"/>.
        /// </summary>
        public Capabilities(params CapabilitiesChild[] elements)
        {
            var features = ImmutableNamedElementCollection.CreateFeatureCollectionBuilder();
            var parameters = ImmutableNamedElementCollection.CreateParameterDefCollectionBuilder();
            var properties = ImmutableNamedElementCollection.CreatePropertyCollectionBuilder();

            foreach (var e in elements)
            {
                e.Apply(
                    onFeature: x => features.Add(x),
                    onParameterDef: x => parameters.Add(x),
                    onProperty: x => properties.Add(x));
            }

            _features = features.ToImmutable();
            _parameters = parameters.ToImmutable();
            _properties = properties.ToImmutable();
            _declaredNamespaces = NamespaceDeclarationCollection.Default;
        }

        internal Capabilities(
            ImmutableNamedElementCollection<Feature> features,
            ImmutableNamedElementCollection<ParameterDef> parameters,
            ImmutableNamedElementCollection<Property> properties,
            NamespaceDeclarationCollection namespaceDeclarations)
        {
            _features = features;
            _parameters = parameters;
            _properties = properties;
            _declaredNamespaces = namespaceDeclarations;
        }

        #endregion

        #region Features

        private readonly ImmutableNamedElementCollection<Feature> _features
            = ImmutableNamedElementCollection.CreateFeatureCollection();
        public IReadOnlyNamedElementCollection<Feature> Features
        {
            get { return _features; }
        }

        public IReadOnlyList<Option> this[FeatureName name]
        {
            get
            {
                if (name == null) throw new ArgumentNullException(nameof(name));
                return _features[name].Options();
            }
        }

        public IReadOnlyList<Option> Get(FeatureName name)
        {
            return _features.Get(name)?.Options();
        }

        public Capabilities Update(FeatureName name, Func<Option, Option> func)
        {
            var ft = _features.Get(name);
             if (ft == null) return this;

            return new Capabilities(_features.SetItem(ft.Update(func)), _parameters, _properties, _declaredNamespaces);
        }

        public Value this[FeatureName name1, PropertyName name2]
        {
            get
            {
                if (name1 == null) throw new ArgumentNullException(nameof(name1));
                if (name2 == null) throw new ArgumentNullException(nameof(name2));
                return _features[name1][name2];
            }
        }

        public Value Get(FeatureName name1, PropertyName name2)
        {
            if (name1 == null) throw new ArgumentNullException(nameof(name1));
            if (name2 == null) throw new ArgumentNullException(nameof(name2));
            return _features.Get(name1)?.Get(name2);
        }

        public IReadOnlyList<Option> this[FeatureName name1, FeatureName name2]
        {
            get
            {
                if (name1 == null) throw new ArgumentNullException(nameof(name1));
                if (name2 == null) throw new ArgumentNullException(nameof(name2));
                return _features[name1][name2];
            }
        }

        public IReadOnlyList<Option> Get(FeatureName name1, FeatureName name2)
        {
            return _features.Get(name1)?.Get(name2);
        }

        #endregion

        #region Parameters

        private readonly ImmutableNamedElementCollection<ParameterDef> _parameters
            = ImmutableNamedElementCollection.CreateParameterDefCollection();
        public IReadOnlyNamedElementCollection<ParameterDef> Parameters
        {
            get { return _parameters; }
        }

{'fraction_non_alphanumeric': 0.08337390457643622, 'fraction_numerical': 0.004868549172346641, 'mean_word_length': 2.100754716981132, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 49, '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': '5243550', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1904, 'n_words': 431}