public ResultSentence <EValidationResult> Validate(IWorldPL1Structure pL1Structure, Dictionary <string, string> dictVariables) { ResultSentence <EValidationResult> result = ResultSentence <EValidationResult> .CreateResult(true, EValidationResult.False); ConstDictionary constDict = pL1Structure.GetPl1Structure().GetConsts(); PredicateDictionary predDict = pL1Structure.GetPl1Structure().GetPredicates(); if (pL1Structure is IWorldSignature worldSignature) { Signature signature = worldSignature.GetSignature(); var correctElement = signature.Predicates.Find(elem => elem.Item1 == Name); if (string.IsNullOrEmpty(correctElement.Item1)) { return(ResultSentence <EValidationResult> .CreateResult(false, EValidationResult.UnknownSymbol, "Predicate " + Name + $" not found in the signature.")); } else if (correctElement.Item2 != Arguments.Count) { return(ResultSentence <EValidationResult> .CreateResult(false, EValidationResult.UnknownSymbol, "Predicate " + Name + $" has arity {correctElement.Item2}, but is applied to {Arguments.Count} arguments")); } } ResultSentence <List <string> > universeArguments = Argument.GetUniverseIdentifier(Arguments, pL1Structure, dictVariables); List <List <string> > predicateList = predDict.TryGetValue(Name); if (!universeArguments.IsValid) { result = ResultSentence <EValidationResult> .CreateResult(false, universeArguments.ValidationResult, universeArguments.ErrorMessage); } else { foreach (var predElem in predicateList) { if (predElem.SequenceEqual(universeArguments.Value)) { result = ResultSentence <EValidationResult> .CreateResult(true, EValidationResult.True); break; } } } return(result); }
internal void AddPredicate(string predicate, List <string> arguments) { PredicateDictionary predicates = _modelDataStructure.Predicates; List <string> universeIdentifier = CreateUniverseConsts(arguments.ToArray()); if (predicates.ContainsKey(predicate)) { //--Refactorn--// if (!(predicates[predicate].Any(p => CheckPredicateList(universeIdentifier, p)))) { predicates[predicate].Add(universeIdentifier); } } else { predicates.Add(predicate, new List <List <string> > { universeIdentifier }); } }