Ejemplo n.º 1
0
        public SelectionResult Select(Dictionary <string, string> jsonModelsToIds, List <int> sequence)
        {
            List <string>          errors = new List <string>();
            List <IHsmModelHolder> models = new List <IHsmModelHolder>();

            foreach (KeyValuePair <string, string> entry in jsonModelsToIds)
            {
                IHsmModel  model     = _jsonModelFactory.CreateModel(entry.Value);
                IValidator validator = _validatorFactory.CreateModelValidator(model);
                validator.Validate();
                if (validator.HasErrors())
                {
                    errors.AddRange(validator.GetErrors());
                    continue;
                }
                else
                {
                    models.Add(new HsmModelHolder(entry.Key, model));
                }
            }

            if (errors.Count > 0)
            {
                return(SelectionResult.Failure(errors));
            }

            IModelSelector  modelSelector = _modelSelectorFactory.CreateModelSelector(_modelSelectorType, _selectionCriterionType);
            IHsmModelHolder selectedModel = modelSelector.Select(sequence, models);

            return(SelectionResult.Success(selectedModel.Name));
        }
Ejemplo n.º 2
0
        public GenerationResult Generate(String jsonModel, int length)
        {
            IHsmModel  model     = _jsonModelFactory.CreateModel(jsonModel);
            IValidator validator = _validatorFactory.CreateModelValidator(model);

            validator.Validate();

            if (validator.HasErrors())
            {
                GenerationResult.Failure(validator.GetErrors());
            }

            IGenerator generator = _generatorFactory.CreateModelGenerator(model, _pseudoRandomNumberGenerator);

            return(GenerationResult.Success(generator.Generate(length)));
        }
Ejemplo n.º 3
0
        public EvaluationResult Evaluate(string jsonModel, List <int> sequence)
        {
            IHsmModel  model     = _jsonModelFactory.CreateModel(jsonModel);
            IValidator validator = _validatorFactory.CreateModelValidator(model);

            validator.Validate();

            if (validator.HasErrors())
            {
                return(EvaluationResult.Failure(validator.GetErrors()));
            }

            IProbabilityCalculator probabilityCalculator = _probabilityCalculatorFactory.CreateProbabilityCalculator(model, sequence);

            return(EvaluationResult.Success(probabilityCalculator.Calculate()));
        }