Example #1
0
        /// <inheritdoc />
        Task <EqulivalenceClass> IAnonimizationApi.CreateEqulivalenceClass(EqulivalenceClass equlivalenceClass)
        {
            var arguments = new object[] { equlivalenceClass };
            var func      = requestBuilder.BuildRestResultFuncForMethod("CreateEqulivalenceClass", new Type[] { typeof(EqulivalenceClass) });

            return((Task <EqulivalenceClass>)func(Client, arguments));
        }
        private bool IsMatching(EqulivalenceClass equlivalenceClass, Dictionary <string, object> document)
        {
            foreach (var categoricField in equlivalenceClass.CategoricAttributes)
            {
                var value = document[categoricField.Key] as string;
                if (value != categoricField.Value)
                {
                    return(false);
                }
            }

            foreach (var intervalField in equlivalenceClass.IntervalAttributes)
            {
                var value = document[intervalField.Key] as double?;
                if (!intervalField.Value.Contains(value))
                {
                    return(false);
                }
            }

            return(true);
        }
        private async Task <EqulivalenceClass> CreateEqulivalenceClass(Dataset dataset, Dictionary <string, object> document)
        {
            var newClass = new EqulivalenceClass();

            foreach (var categoricField in dataset.GetCategoricFields())
            {
                newClass.CategoricAttributes.Add(categoricField.Name, document[categoricField.Name] as string);
            }



            foreach (var intervalField in dataset.GetIntervalFields())
            {
                NumericRange range;
                var          exactValue = (double)document[intervalField.Name];
                var          size       = intervalField.PreferedSize;

                if (size != 0)
                {
                    range = new NumericRange(exactValue - size / 2, exactValue + size / 2);
                }
                else
                {
                    range = NumericRange.CreateDefault(exactValue);
                }

                newClass.IntervalAttributes.Add(intervalField.Name, range);
            }

            var result = await Api.CreateEqulivalenceClass(newClass);

            //Check if the equlivalence class was created
            await Api.GetMatchingEqulivalenceClasses(document);

            return(result);
        }
        public static void Write(this EqulivalenceClass equlivalenceClass)
        {
            string output = JsonConvert.SerializeObject(equlivalenceClass);

            Console.WriteLine(output);
        }