Example #1
0
        /// <summary>
        /// Implemented by concrete subclasses, this performs the final conversion from a non-null JSON value to
        /// a value of type T.
        /// </summary>
        /// <param name="reader">The JSON reader to pull data from</param>
        /// <param name="serializer">The serializer to use for nested serialization</param>
        /// <returns>The deserialized value of type T.</returns>
        protected override OffsetDateTime ReadJsonImpl(JsonReader reader, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.String)
            {
                throw new InvalidNodaDataException(
                          $"Unexpected token parsing {typeof(OffsetDateTime).Name}. Expected String, got {reader.TokenType}.");
            }
            string text = reader.Value.ToString();

            var mainResult = Patterns
                             .Select(x => x.Parse(text))
                             .FirstOrDefault(z => z.Success);

            if (mainResult?.Success == true)
            {
                return(mainResult.Value);
            }

            var secondaryResult = AlternatePatterns
                                  .Select(z => z.Parse(text))
                                  .FirstOrDefault(z => z.Success);

            if (secondaryResult?.Success == true)
            {
                return(secondaryResult.Value.WithOffset(Offset.Zero));
            }
            return(Patterns.First().Parse(text).Value);
        }
        private void Initialize()
        {
            if (!_isInitialized)
            {
                _filteredPatterns = Filters != null?
                                    Patterns.Where(p => Filters.All(f => f.PassFilter(p))).ToArray() :
                                        Patterns.ToArray();

                _data = new ClassifierData
                {
                    ClassFeature      = Patterns.First().ClassFeature,
                    TrainingInstances = TrainingInstances,
                    AllPatterns       = _filteredPatterns,
                };
                if (SelectionPolicy != null)
                {
                    SelectionPolicy.Data = _data;
                }
                if (VotesAggregator != null)
                {
                    VotesAggregator.Data = _data;
                }
                if (VotesNormalizer != null)
                {
                    VotesNormalizer.Data = _data;
                }
            }
            _isInitialized = true;
        }
Example #3
0
            private IDictionary <string, int> GetDigitsForPatterns()
            {
                IDictionary <string, int> decodedPatterns = new Dictionary <string, int>();

                string one   = Patterns.First(x => x.Length == 2);
                string four  = Patterns.First(x => x.Length == 4);
                string seven = Patterns.First(x => x.Length == 3);
                string eight = Patterns.First(x => x.Length == 7);
                string three = Patterns.First(x => x.Length == 5 && ContainsNumberPattern(x, seven));
                string nine  = Patterns.First(x => x.Length == 6 && ContainsNumberPattern(x, three));
                string zero  = Patterns.First(x => x.Length == 6 && ContainsNumberPattern(x, seven) && x != nine);
                string six   = Patterns.First(x => x.Length == 6 && x != nine && x != zero);
                string five  = Patterns.First(x => x.Length == 5 && x != three && ContainsNumberPattern(six, x));
                string two   = Patterns.First(x => x.Length == 5 && x != three && x != five);

                decodedPatterns.Add(one, 1);
                decodedPatterns.Add(two, 2);
                decodedPatterns.Add(three, 3);
                decodedPatterns.Add(four, 4);
                decodedPatterns.Add(five, 5);
                decodedPatterns.Add(six, 6);
                decodedPatterns.Add(seven, 7);
                decodedPatterns.Add(eight, 8);
                decodedPatterns.Add(nine, 9);
                decodedPatterns.Add(zero, 0);

                return(decodedPatterns);
            }
Example #4
0
        public MainViewModel()
        {
            Cultures = ExploreHelper.AllCultures;

            SelectedCulture = CultureInfo.InvariantCulture;

            Properties       = ExploreHelper.AllProperties;
            SelectedProperty = Properties.First();

            Patterns        = ExploreHelper.AllPatterns;
            SelectedPattern = Patterns.First();
        }
Example #5
0
        public MainViewModel()
        {
            Cultures = ExploreHelper.AllCultures;

            SelectedCulture = CultureInfo.InvariantCulture;

            Properties        = ExploreHelper.AllProperties;
            GroupedProperites = CollectionViewSource.GetDefaultView(Properties);
            GroupedProperites.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
            SelectedProperty = Properties.First();

            Patterns        = ExploreHelper.AllPatterns;
            SelectedPattern = Patterns.First();
        }
        public string Translate(string input)
        {
            Pattern pattern = Patterns.First(p => Regex.IsMatch(input, p.Input));

            return(Regex.Replace(input, pattern.Input, pattern.Replacement));
        }
Example #7
0
 /// <summary>
 /// Writes the formatted value to the writer.
 /// </summary>
 /// <param name="writer">The writer to write JSON data to</param>
 /// <param name="value">The value to serializer</param>
 /// <param name="serializer">The serializer to use for nested serialization</param>
 protected override void WriteJsonImpl(JsonWriter writer, OffsetDateTime value, JsonSerializer serializer)
 {
     _validator?.Invoke(value);
     writer.WriteValue(Patterns.First().Format(value));
 }
Example #8
0
 /// <summary>
 /// Writes the formatted value to the writer.
 /// </summary>
 /// <param name="writer">The writer to write JSON data to</param>
 /// <param name="value">The value to serializer</param>
 /// <param name="serializer">The serializer to use for nested serialization</param>
 protected override void WriteJsonImpl(JsonWriter writer, Instant value, JsonSerializer serializer)
 {
     writer.WriteValue(Patterns.First().Format(value));
 }