Ejemplo n.º 1
0
        internal void RemoveConst(string key)
        {
            ConstDictionary consts = _modelDataStructure.Consts;

            consts.Remove(key);
            _genericIndex--;
        }
Ejemplo n.º 2
0
        public override ResultSentence <string> GetPL1UniverseIdentifier(IWorldPL1Structure pL1WorldStructure, Dictionary <string, string> dictVariables)
        {
            PL1Structure       pl1Structure = pL1WorldStructure.GetPl1Structure();
            ConstDictionary    constDict    = pl1Structure.GetConsts();
            FunctionDictionary funcDict     = pl1Structure.GetFunctions();
            ResultSentence <List <string> > universeIdentifier = GetUniverseIdentifier(Arguments, pL1WorldStructure, dictVariables);
            ListDictionary listDict = funcDict.TryGetValue(Name);

            if (pL1WorldStructure is IWorldSignature worldSignature)
            {
                Signature signature = worldSignature.GetSignature();
                if (!signature.Functions.Any(elem => elem.Item1 == Name && elem.Item2 == Arguments.Count))
                {
                    return(ResultSentence <string> .CreateResult(EValidationResult.UnknownSymbol, false, "", "Function " + Name + " not found in signature."));
                }
            }

            if (!universeIdentifier.IsValid)
            {
                return(ResultSentence <string> .CreateResult(universeIdentifier.ValidationResult, false, universeIdentifier.Value.FirstOrDefault(), universeIdentifier.ErrorMessage));
            }

            string result = listDict.TryGetValue(universeIdentifier.Value);

            return(ResultSentence <string> .CreateResult(true, result));
        }
Ejemplo n.º 3
0
        internal string AddConst()
        {
            ConstDictionary consts = _modelDataStructure.Consts;
            string          key    = GENERIC_IDENTIFIER + _genericIndex;

            _genericIndex++;
            string uni = _universeIdentifier + consts.CurrIndex++;

            consts.Add(key, uni);
            _universe.Add(uni);

            return(key);
        }
Ejemplo n.º 4
0
        internal void AddConst(string key, string keySameUniverseIdentifier = null)
        {
            ConstDictionary consts = _modelDataStructure.Consts;

            if (!consts.ContainsKey(key))
            {
                if (keySameUniverseIdentifier == null)
                {
                    string uni = _universeIdentifier + consts.CurrIndex;
                    consts.Add(key, uni);
                    consts.CurrIndex++;
                    _universe.Add(uni);
                }
                else
                {
                    consts.Add(key, consts[keySameUniverseIdentifier]);
                }
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public string GetWorldConstant(IWorldPL1Structure pL1WorldStructure, Dictionary <string, string> dictVariables)
        {
            PL1Structure            pl1Structure       = pL1WorldStructure.GetPl1Structure();
            ConstDictionary         constDict          = pl1Structure.GetConsts();
            FunctionDictionary      funcDict           = pl1Structure.GetFunctions();
            Result <List <string> > universeIdentifier = GetUniverseIdentifier(Arguments, pL1WorldStructure, dictVariables);
            ListDictionary          listDict           = funcDict.TryGetValue(Name);

            string result = listDict.TryGetValue(universeIdentifier.Value);

            foreach (KeyValuePair <string, string> valuePair in constDict)
            {
                if (result == valuePair.Value)
                {
                    return(valuePair.Key);
                }
            }

            return("WorldConstant not found");
        }
Ejemplo n.º 7
0
        public static ResultSentence <List <string> > GetUniverseIdentifier(List <Argument> arguments, IWorldPL1Structure pL1WorldStructure, Dictionary <string, string> dictVariables)
        {
            ResultSentence <List <string> > universeArguments = ResultSentence <List <string> > .CreateResult(true, new List <string>());

            ConstDictionary constDict = pL1WorldStructure.GetPl1Structure().GetConsts();

            foreach (var item in arguments)
            {
                ResultSentence <string> universeIdentifier = item.GetPL1UniverseIdentifier(pL1WorldStructure, dictVariables);
                if (universeIdentifier.IsValid)
                {
                    universeArguments.Value.Add(constDict.TryGetValue(universeIdentifier.Value));
                }
                else
                {
                    universeArguments = ResultSentence <List <string> > .CreateResult(universeIdentifier.ValidationResult, false, new List <string>() { universeIdentifier.Value }, universeIdentifier.ErrorMessage);

                    break;
                };
            }
            return(universeArguments);
        }