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

namespace Simple.OData.Client
{
    public abstract class EdmPropertyType
    {
        public abstract string Name { get; }

        public static EdmPropertyType Parse(string s, IEnumerable<EdmComplexType> complexTypes, IEnumerable<EdmEntityType> entityTypes)
        {
            var result1 = TryParseCollectionType(s, complexTypes, entityTypes);
            if (result1.Item1)
            {
                return result1.Item2;
            }

            var result2 = TryParsePrimitiveType(s);
            if (result2.Item1)
            {
                return result2.Item2;
            }

            var result3 = TryParseComplexType(s, complexTypes);
            if (result3.Item1)
            {
                return result3.Item2;
            }

            var result4 = TryParseEntityType(s, entityTypes);
            if (result4.Item1)
            {
                return result4.Item2;
            }

            throw new ArgumentException(string.Format("Unrecognized type {0}", s));
        }

        private static Tuple<bool, EdmCollectionPropertyType> TryParseCollectionType(string s, IEnumerable<EdmComplexType> complexTypes, IEnumerable<EdmEntityType> entityTypes)
        {
            if (s.StartsWith("Collection(") && s.EndsWith(")"))
            {
                int start = s.IndexOf("(");
                int end = s.LastIndexOf(")");
                var baseType = EdmPropertyType.Parse(s.Substring(start + 1, end - start - 1), complexTypes, entityTypes);
                return new Tuple<bool, EdmCollectionPropertyType>(true, new EdmCollectionPropertyType() { BaseType = baseType });
            }
            else
            {
                return new Tuple<bool, EdmCollectionPropertyType>(false, null);
            }
        }

        private static Tuple<bool, EdmPrimitivePropertyType> TryParsePrimitiveType(string s)
        {
            var result = EdmType.TryParse(s);
            if (result.Item1)
            {
                return new Tuple<bool, EdmPrimitivePropertyType>(true, new EdmPrimitivePropertyType { Type = result.Item2 });
            }
            else
            {
                return new Tuple<bool, EdmPrimitivePropertyType>(false, null);
            }
        }

        private static Tuple<bool, EdmComplexPropertyType> TryParseComplexType(string s, IEnumerable<EdmComplexType> complexTypes)
        {
            var result = EdmComplexType.TryParse(s, complexTypes);
            if (!result.Item1)
                result = EdmComplexType.TryParse(s.Split('.').Last(), complexTypes);
            if (result.Item1)
            {
                return new Tuple<bool, EdmComplexPropertyType>(true, new EdmComplexPropertyType { Type = result.Item2 });
            }
            else
            {
                return new Tuple<bool, EdmComplexPropertyType>(false, null);
            }
        }

        private static Tuple<bool, EdmEntityPropertyType> TryParseEntityType(string s, IEnumerable<EdmEntityType> entityTypes)
        {
            var result = EdmEntityType.TryParse(s, entityTypes);
            if (!result.Item1)
                result = EdmEntityType.TryParse(s.Split('.').Last(), entityTypes);
            if (result.Item1)
            {
                return new Tuple<bool, EdmEntityPropertyType>(true, new EdmEntityPropertyType { Type = result.Item2 });
            }
            else
            {
                return new Tuple<bool, EdmEntityPropertyType>(false, null);
            }
        }
    }

    public class EdmPrimitivePropertyType : EdmPropertyType
    {
        public EdmType Type { get; set; }
        public override string Name { get { return Type == null ? null : Type.Name; } }
    }

    public class EdmComplexPropertyType : EdmPropertyType
    {
        public EdmComplexType Type { get; set; }
        public override string Name { get { return Type == null ? null : Type.Name; } }
    }

    public class EdmEntityPropertyType : EdmPropertyType
    {
        public EdmEntityType Type { get; set; }
        public override string Name { get { return Type == null ? null : Type.Name; } }
    }

    public class EdmCollectionPropertyType : EdmPropertyType
    {
        public EdmPropertyType BaseType { get; set; }
        public override string Name { get { return BaseType == null ? null : string.Format("Collection({0})", BaseType.Name); } }
    }
}
<commit_msg>Added EdmProprtyType.ToString.<commit_after>﻿using System;
using System.Linq;
using System.Collections.Generic;

namespace Simple.OData.Client
{
    public abstract class EdmPropertyType
    {
        public abstract string Name { get; }
        public override string ToString()
        {
            return this.Name;
        }

        public static EdmPropertyType Parse(string s, IEnumerable<EdmComplexType> complexTypes, IEnumerable<EdmEntityType> entityTypes)
        {
            var result1 = TryParseCollectionType(s, complexTypes, entityTypes);
            if (result1.Item1)
            {
                return result1.Item2;
            }

            var result2 = TryParsePrimitiveType(s);
            if (result2.Item1)
            {
                return result2.Item2;
            }

            var result3 = TryParseComplexType(s, complexTypes);
            if (result3.Item1)
            {
                return result3.Item2;
            }

            var result4 = TryParseEntityType(s, entityTypes);
            if (result4.Item1)
            {
                return result4.Item2;
            }

            throw new ArgumentException(string.Format("Unrecognized type {0}", s));
        }

        private static Tuple<bool, EdmCollectionPropertyType> TryParseCollectionType(string s, IEnumerable<EdmComplexType> complexTypes, IEnumerable<EdmEntityType> entityTypes)
        {
            if (s.StartsWith("Collection(") && s.EndsWith(")"))
            {
                int start = s.IndexOf("(");
                int end = s.LastIndexOf(")");
                var baseType = EdmPropertyType.Parse(s.Substring(start + 1, end - start - 1), complexTypes, entityTypes);
                return new Tuple<bool, EdmCollectionPropertyType>(true, new EdmCollectionPropertyType() { BaseType = baseType });
            }
            else
            {
                return new Tuple<bool, EdmCollectionPropertyType>(false, null);
            }
        }

        private static Tuple<bool, EdmPrimitivePropertyType> TryParsePrimitiveType(string s)
        {
            var result = EdmType.TryParse(s);
            if (result.Item1)
            {
                return new Tuple<bool, EdmPrimitivePropertyType>(true, new EdmPrimitivePropertyType { Type = result.Item2 });
            }
            else
            {
                return new Tuple<bool, EdmPrimitivePropertyType>(false, null);
            }
        }

        private static Tuple<bool, EdmComplexPropertyType> TryParseComplexType(string s, IEnumerable<EdmComplexType> complexTypes)
        {
            var result = EdmComplexType.TryParse(s, complexTypes);
            if (!result.Item1)
                result = EdmComplexType.TryParse(s.Split('.').Last(), complexTypes);
            if (result.Item1)
            {
                return new Tuple<bool, EdmComplexPropertyType>(true, new EdmComplexPropertyType { Type = result.Item2 });
            }
            else
            {
                return new Tuple<bool, EdmComplexPropertyType>(false, null);
            }
        }

        private static Tuple<bool, EdmEntityPropertyType> TryParseEntityType(string s, IEnumerable<EdmEntityType> entityTypes)
        {
            var result = EdmEntityType.TryParse(s, entityTypes);
            if (!result.Item1)
                result = EdmEntityType.TryParse(s.Split('.').Last(), entityTypes);
            if (result.Item1)
            {
                return new Tuple<bool, EdmEntityPropertyType>(true, new EdmEntityPropertyType { Type = result.Item2 });
            }
            else
            {
                return new Tuple<bool, EdmEntityPropertyType>(false, null);
            }
        }
    }

    public class EdmPrimitivePropertyType : EdmPropertyType
    {
        public EdmType Type { get; set; }
        public override string Name { get { return Type == null ? null : Type.Name; } }
    }

    public class EdmComplexPropertyType : EdmPropertyType
    {
        public EdmComplexType Type { get; set; }
        public override string Name { get { return Type == null ? null : Type.Name; } }
    }

    public class EdmEntityPropertyType : EdmPropertyType
    {
        public EdmEntityType Type { get; set; }
        public override string Name { get { return Type == null ? null : Type.Name; } }
    }

    public class EdmCollectionPropertyType : EdmPropertyType
    {
        public EdmPropertyType BaseType { get; set; }
        public override string Name { get { return BaseType == null ? null : string.Format("Collection({0})", BaseType.Name); } }
    }
}

{'fraction_non_alphanumeric': 0.09009802841722657, 'fraction_numerical': 0.007049234497191321, 'mean_word_length': 1.924315619967794, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, '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': '921161', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2377, 'n_words': 555}