<commit_before>﻿/*
 * Copyright (c) 2010-2018 Achim 'ahzf' Friedland <<EMAIL>>
 * This file is part of Illias <http://www.github.com/Vanaheimr/Illias>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#region Usings

using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using org.GraphDefined.Vanaheimr.Illias;

#endregion

namespace org.GraphDefined.Vanaheimr.Illias
{

    /// <summary>
    /// JSON I/O.
    /// </summary>
    public static class AddressExtentions
    {

        #region ToJSON(this Address)

        public static JObject ToJSON(this Address _Address)

            => _Address != null
                   ? JSONObject.Create(
                         new JProperty("@context", "https://opendata.social/contexts/UsersAPI+json/address"),
                         _Address.FloorLevel.   ToJSON("floorLevel"),
                         _Address.HouseNumber.  ToJSON("houseNumber"),
                         _Address.Street.       ToJSON("street"),
                         _Address.PostalCode.   ToJSON("postalCode"),
                         _Address.PostalCodeSub.ToJSON("postalCodeSub"),
                         _Address.City.         ToJSON("city"),
                         _Address.Country != null
                              ? _Address.Country.Alpha3Code.ToJSON("country")
                              : null,
                         _Address.Comment.      ToJSON("comment")
                     )
                   : null;

        #endregion

        #region ToJSON(this Address, JPropertyKey)

        public static JProperty ToJSON(this Address Address, String JPropertyKey)

            => Address != null
                   ? new JProperty(JPropertyKey,
                                   Address.ToJSON())
                   : null;

        #endregion

        #region ToJSON(this Addresses, JPropertyKey)

        public static JArray ToJSON(this IEnumerable<Address> Addresses)

            => Addresses?.Any() == true
                   ? new JArray(Addresses.SafeSelect(ToJSON))
                   : null;

        #endregion

        #region ToJSON(this Addresses, JPropertyKey)

        public static JProperty ToJSON(this IEnumerable<Address> Addresses, String JPropertyKey)

            => Addresses != null
                   ? new JProperty(JPropertyKey,
                                   Addresses.ToJSON())
                   : null;

        #endregion

        public static Boolean TryParseAddress(this String Text, out Address Address)
            => Address.TryParseJSON(JObject.Parse(Text), out Address);

    }

    /// <summary>
    /// A WWCP address.
    /// </summary>
    public class Address : ACustomData,
                           IEquatable<Address>,
                           IComparable<Address>,
                           IComparable
    {

        #region Properties

        /// <summary>
        /// The name of the street.
        /// </summary>
        public String      Street           { get; }

        /// <summary>
        /// The house number.
        /// </summary>
        public String      HouseNumber      { get; }

        /// <summary>
        /// The floor level.
        /// </summary>
        public String      FloorLevel       { get; }

        /// <summary>
        /// The postal code.
        /// </summary>
        public String      PostalCode       { get; }

        /// <summary>
        /// The postal code sub.
        /// </summary>
        public String      PostalCodeSub    { get; }

        /// <summary>
        /// The city.
        /// </summary>
        public I18NString  City             { get; }

        /// <summary>
        /// The country.
        /// </summary>
        public Country     Country          { get; }

        /// <summary>
        /// An optional text/comment to describe the address.
        /// </summary>
        public I18NString  Comment          { get; }

        #endregion

        #region Constructor(s)

        /// <summary>
        /// Create a new address.
        /// </summary>
        /// <param name="Street">The name of the street.</param>
        /// <param name="HouseNumber">The house number.</param>
        /// <param name="FloorLevel">The floor level.</param>
        /// <param name="PostalCode">The postal code</param>
        /// <param name="PostalCodeSub">The postal code sub</param>
        /// <param name="City">The city.</param>
        /// <param name="Country">The country.</param>
        /// <param name="Comment">An optional text/comment to describe the address.</param>
        /// 
        /// <param name="CustomData">An optional dictionary of customer-specific data.</param>
        private Address(String                               Street,
                        String                               HouseNumber,
                        String                               FloorLevel,
                        String                               PostalCode,
                        String                               PostalCodeSub,
                        I18NString                           City,
                        Country                              Country,
                        I18NString                           Comment      = null,

                        IReadOnlyDictionary<String, Object>  CustomData   = null)

            : base(CustomData)

        {

            this.Street         = Street        ?? "";
            this.HouseNumber    = HouseNumber   ?? "";
            this.FloorLevel     = FloorLevel    ?? "";<commit_msg>Make address constructor public<commit_after>﻿/*
 * Copyright (c) 2010-2018 Achim 'ahzf' Friedland <<EMAIL>>
 * This file is part of Illias <http://www.github.com/Vanaheimr/Illias>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#region Usings

using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using org.GraphDefined.Vanaheimr.Illias;

#endregion

namespace org.GraphDefined.Vanaheimr.Illias
{

    /// <summary>
    /// JSON I/O.
    /// </summary>
    public static class AddressExtentions
    {

        #region ToJSON(this Address)

        public static JObject ToJSON(this Address _Address)

            => _Address != null
                   ? JSONObject.Create(
                         new JProperty("@context", "https://opendata.social/contexts/UsersAPI+json/address"),
                         _Address.FloorLevel.   ToJSON("floorLevel"),
                         _Address.HouseNumber.  ToJSON("houseNumber"),
                         _Address.Street.       ToJSON("street"),
                         _Address.PostalCode.   ToJSON("postalCode"),
                         _Address.PostalCodeSub.ToJSON("postalCodeSub"),
                         _Address.City.         ToJSON("city"),
                         _Address.Country != null
                              ? _Address.Country.Alpha3Code.ToJSON("country")
                              : null,
                         _Address.Comment.      ToJSON("comment")
                     )
                   : null;

        #endregion

        #region ToJSON(this Address, JPropertyKey)

        public static JProperty ToJSON(this Address Address, String JPropertyKey)

            => Address != null
                   ? new JProperty(JPropertyKey,
                                   Address.ToJSON())
                   : null;

        #endregion

        #region ToJSON(this Addresses, JPropertyKey)

        public static JArray ToJSON(this IEnumerable<Address> Addresses)

            => Addresses?.Any() == true
                   ? new JArray(Addresses.SafeSelect(ToJSON))
                   : null;

        #endregion

        #region ToJSON(this Addresses, JPropertyKey)

        public static JProperty ToJSON(this IEnumerable<Address> Addresses, String JPropertyKey)

            => Addresses != null
                   ? new JProperty(JPropertyKey,
                                   Addresses.ToJSON())
                   : null;

        #endregion

        public static Boolean TryParseAddress(this String Text, out Address Address)
            => Address.TryParseJSON(JObject.Parse(Text), out Address);

    }

    /// <summary>
    /// A WWCP address.
    /// </summary>
    public class Address : ACustomData,
                           IEquatable<Address>,
                           IComparable<Address>,
                           IComparable
    {

        #region Properties

        /// <summary>
        /// The name of the street.
        /// </summary>
        public String      Street           { get; }

        /// <summary>
        /// The house number.
        /// </summary>
        public String      HouseNumber      { get; }

        /// <summary>
        /// The floor level.
        /// </summary>
        public String      FloorLevel       { get; }

        /// <summary>
        /// The postal code.
        /// </summary>
        public String      PostalCode       { get; }

        /// <summary>
        /// The postal code sub.
        /// </summary>
        public String      PostalCodeSub    { get; }

        /// <summary>
        /// The city.
        /// </summary>
        public I18NString  City             { get; }

        /// <summary>
        /// The country.
        /// </summary>
        public Country     Country          { get; }

        /// <summary>
        /// An optional text/comment to describe the address.
        /// </summary>
        public I18NString  Comment          { get; }

        #endregion

        #region Constructor(s)

        /// <summary>
        /// Create a new address.
        /// </summary>
        /// <param name="Street">The name of the street.</param>
        /// <param name="HouseNumber">The house number.</param>
        /// <param name="FloorLevel">The floor level.</param>
        /// <param name="PostalCode">The postal code</param>
        /// <param name="PostalCodeSub">The postal code sub</param>
        /// <param name="City">The city.</param>
        /// <param name="Country">The country.</param>
        /// <param name="Comment">An optional text/comment to describe the address.</param>
        /// 
        /// <param name="CustomData">An optional dictionary of customer-specific data.</param>
        public Address(String                               Street,
                       String                               HouseNumber,
                       String                               FloorLevel,
                       String                               PostalCode,
                       String                               PostalCodeSub,
                       I18NString                           City,
                       Country                              Country,
                       I18NString                           Comment      = null,

                       IReadOnlyDictionary<String, Object>  CustomData   = null)

            : base(CustomData)

        {

            this.Street         = Street        ?? "";
            this.HouseNumber    = HouseNumber   ?? "";
            this.FloorLevel     = FloorLevel    ?? "";
{'fraction_non_alphanumeric': 0.1011558324452824, 'fraction_numerical': 0.003442905156160341, 'mean_word_length': 1.3158694001518603, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 109, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3196446', 'n_tokens_mistral': 3014, 'n_tokens_neox': 2851, 'n_words': 781}