<commit_before>﻿using System;
using System.Globalization;
using System.Text.RegularExpressions;

namespace Wkx
{
    internal class EwktReader : WktReader
    {
        protected Dimensions? dimensions;

        internal EwktReader(string value)
            : base(value)
        {
        }

        internal override Geometry Read()
        {
            Match match = MatchRegex(@"^SRID=(\d+);");

            Geometry geometry = base.Read();

            if (match.Success)
                geometry.Srid = int.Parse(match.Groups[1].Value);

            geometry.Dimensions = dimensions.HasValue ? dimensions.Value : Dimensions.XY;

            return geometry;
        }

        protected override Point MatchCoordinate(Dimensions dimensions)
        {
            Match match = MatchRegex(@"^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)");

            if (match.Success)
            {
                dimensions = Dimensions.XYZM;
                return new Point(double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[4].Value, CultureInfo.InvariantCulture));
            }

            match = MatchRegex(@"^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)");

            if (match.Success)
            {
                if (dimensions.HasFlag(Dimensions.M))
                {
                    dimensions = Dimensions.XYM;
                    return new Point(double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture), null, double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture));
                }
                else
                {
                    dimensions = Dimensions.XYZ;
                    return new Point(double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture));
                }
            }

            dimensions = Dimensions.XY;
            match = MatchRegex(@"^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)");
            return new Point(double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture));            
        }
    }
}<commit_msg>Fixed bug in EwktReader with saving geometry dimension<commit_after>﻿using System;
using System.Globalization;
using System.Text.RegularExpressions;

namespace Wkx
{
    internal class EwktReader : WktReader
    {
        protected Dimensions? geometryDimensions;

        internal EwktReader(string value)
            : base(value)
        {
        }

        internal override Geometry Read()
        {
            Match match = MatchRegex(@"^SRID=(\d+);");

            Geometry geometry = base.Read();

            if (match.Success)
                geometry.Srid = int.Parse(match.Groups[1].Value);

            geometry.Dimensions = geometryDimensions.HasValue ? geometryDimensions.Value : Dimensions.XY;

            return geometry;
        }

        protected override Point MatchCoordinate(Dimensions dimensions)
        {
            Match match = MatchRegex(@"^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)");

            if (match.Success)
            {
                geometryDimensions = Dimensions.XYZM;
                return new Point(double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[4].Value, CultureInfo.InvariantCulture));
            }

            match = MatchRegex(@"^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)\s+(-?\d+\.?\d*)");

            if (match.Success)
            {
                if (dimensions.HasFlag(Dimensions.M))
                {
                    geometryDimensions = Dimensions.XYM;
                    return new Point(double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture), null, double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture));
                }
                else
                {
                    geometryDimensions = Dimensions.XYZ;
                    return new Point(double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture));
                }
            }

            geometryDimensions = Dimensions.XY;
            match = MatchRegex(@"^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)");
            return new Point(double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture), double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture));            
        }
    }
}
{'fraction_non_alphanumeric': 0.14727599281580522, 'fraction_numerical': 0.005188585112751946, 'mean_word_length': 2.1325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6162903', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1385, 'n_words': 205}