Exemple #1
0
        public static PredicateList execute(PropositionSyntacticElement element, PredicateList predicateState)
        {
            // when a proposition element is executed the proposition
            // must be set to true. This can only be done when:
            //  the proposition is found in the list
            //  the proposition must not be false
            // the element can then be set to true
            PredicateSyntacticElement pse = predicateState.GetPredicate(element.PredicateName);

            if (pse == null)
            {
                element.Value = false;
                throw new ArgumentNullException(element.PredicateName +
                                                "could not bo found in state for " + element.Text);
            }
            else
            {
                if (pse.Value == false)
                {
                    element.Value = false;
                }
                else
                {
                    pse.Value     = true;
                    element.Value = true;
                }
            }
            return(predicateState);
        }
Exemple #2
0
        public override object Clone()
        {
            var p = new AnalyseProject()
            {
                AnalyseEndTime      = AnalyseEndTime,
                AnalyseStartTime    = AnalyseStartTime,
                ProjectStartTime    = ProjectStartTime,
                CurrentDataSource   = CurrentDataSource.Clone() as IDataSource,
                DefaultFilterNumber = DefaultFilterNumber,
                Fine            = Fine,
                Grade           = Grade,
                Memo            = Memo,
                Name            = Name,
                TestStepDelayMS = TestStepDelayMS,
                Status          = Status
            };

            InstrumentList.ForEach(v => p.InstrumentList.Add(v.Clone() as IInstrument));
            ResultList.ForEach(v => p.ResultList.Add(v.Clone() as IInstrument));
            BlockList.ForEach(v => p.BlockList.Add(v.Clone() as IInstrument));
            ConditionList.ForEach(v => p.ConditionList.Add(v.Clone() as ICondition));
            PredicateList.ForEach(v => p.PredicateList.Add(v.Clone() as ICondition));

            return(p);
        }
Exemple #3
0
        private Sentence SingleSimpleSentence(string punct = null)
        {
            int howMany = 1;

            if (random.Next(0, 100) < 10)
            {
                howMany = 2;
            }
            else if (random.Next(0, 100) < 20)
            {
                howMany = 3;
            }
            PredicateList pl = new PredicateList();

            while (howMany > 0)
            {
                var p = GeneratePredicate();
                pl.Add(p);
                howMany--;
            }

            SentenceOptionalParts parts = OptionalParts(punct);

            if (parts != null)
            {
                if (punct == "NONE")
                {
                    parts.Punctuation = null;
                }
            }

            Sentence s = new Sentence(RandomEnPiChain(), pl, SentenceDiagnostics.NotFromParser, parts);

            return(s);
        }
Exemple #4
0
 public static bool?Evaluate(ExpressionSyntacticElement exp, PredicateList state)
 {
     if (exp.GetType() == typeof(NotExpression))
     {
         return(ExpressionExecutive.Evaluate((NotExpression)exp, state));
     }
     if (exp.GetType() == typeof(AndExpression))
     {
         return(ExpressionExecutive.Evaluate((AndExpression)exp, state));
     }
     if (exp.GetType() == typeof(OrExpression))
     {
         return(ExpressionExecutive.Evaluate((OrExpression)exp, state));
     }
     if (exp.GetType() == typeof(XorExpression))
     {
         return(ExpressionExecutive.Evaluate((XorExpression)exp, state));
     }
     if (exp.GetType() == typeof(PredicateExpression))
     {
         return(ExpressionExecutive.Evaluate((PredicateExpression)exp, state));
     }
     if (exp.GetType() == typeof(ImplicationSyntacticExpression))
     {
         return(ExpressionExecutive.Evaluate((ImplicationSyntacticExpression)exp, state));
     }
     if (exp.GetType() == typeof(IfAndOnlyIfSyntacticExpression))
     {
         return(ExpressionExecutive.Evaluate((IfAndOnlyIfSyntacticExpression)exp, state));
     }
     throw new UnknownExpressionException();
 }
Exemple #5
0
        /// <summary>
        /// Implies when run, evaluates left hand side and right hand side then sets itself
        /// this is the a result, True, the argument is valid and false it is not valid.
        /// Unknown will have to be taken as invalid. If all steps in the argument are valid
        /// then we should have a good argument
        /// implies testing
        /// p --> q
        /// 1  1  1
        /// 1  0  0
        /// 0  1  1
        /// 0  1  0
        /// X  1  1
        /// X  0  X
        /// 1  X  X
        /// 0  X  1
        /// X  X  X
        /// </summary>
        /// <param name="element"></param>
        /// <param name="predicateState"></param>
        /// <returns></returns>
        public static PredicateList execute(ImplicationSyntacticExpression element, PredicateList predicateState)
        {
            bool?lhs = ExpressionExecutive.Evaluate(element.lhs, predicateState);
            bool?rhs = ExpressionExecutive.Evaluate(element.rhs, predicateState);

            element.Value = ImpliesTruthTable(lhs, rhs);
            return(predicateState);
        }
 public void IdentifyWebApiControllers()
 {
     webApiControllers = Types.InAssembly(typeof(Startup).Assembly)
                         .That()
                         .AreClasses()
                         .And().ArePublic()
                         .And().Inherit(typeof(ControllerBase));
 }
Exemple #7
0
        public override void SerialObject()
        {
            ConditionSerialList.Clear();
            ConditionList.ForEach(v => ConditionSerialList.Add(SerialInfo.GetSerialInfo(v)));

            PredicateSerialList.Clear();
            PredicateList.ForEach(v => PredicateSerialList.Add(SerialInfo.GetSerialInfo(v)));
        }
        /// <summary>
        /// Fetches all controllers found in this application.
        /// </summary>
        private static PredicateList GetWebApiControllers()
        {
            PredicateList webApiControllers = Types.InAssembly(typeof(Startup).Assembly)
                                              .That()
                                              .AreClasses()
                                              .And().ArePublic()
                                              .And().Inherit(typeof(ControllerBase));

            return(webApiControllers);
        }
Exemple #9
0
 public override void LoadOriginalStatus()
 {
     if (Status != ProjectStatus.Stopped)
     {
         Stop();
     }
     CurrentDataSource.LoadOriginalStatus();
     ConditionList.ForEach(v => v.LoadOriginalStatus());
     PredicateList.ForEach(v => v.LoadOriginalStatus());
 }
Exemple #10
0
 public override void PrepareWork()
 {
     CurrentDataSource.PrepareWork();
     ProjectStartTime = DateTime.Now;
     ResultList.Clear();
     ConditionList.ForEach(v => v.PrepareWork());
     PredicateList.ForEach(v => v.PrepareWork());
     current = 0;
     CurrentDataSource.CacheSize = 5;
 }
Exemple #11
0
 public static bool?Evaluate(PredicateExpression exp, PredicateList state)
 {
     if (state.IsPredicate(exp.PredicateName))
     {
         PredicateSyntacticElement p = state.GetPredicate(exp.PredicateName);
         return(p.Value);
     }
     else
     {
         throw new ArgumentOutOfRangeException("predicate not found in state");
     }
 }
Exemple #12
0
        //Simple Sentences
        public Sentence(ComplexChain subjects, PredicateList predicates, SentenceDiagnostics diagnostics, SentenceOptionalParts parts = null)
        {
            LaFragment      = new List <Fragment>();
            this.subjects   = subjects;   //only (*), o, en
            this.predicates = predicates; //only li, pi, en
            if (parts != null)
            {
                punctuation    = parts.Punctuation;
                tagConjunction = parts.Conjunction;
                tagQuestion    = parts.TagQuestion;
                headVocatives  = parts.HeadVocatives;
                isHortative    = parts.IsHortative;
            }

            this.diagnostics = diagnostics;
        }
Exemple #13
0
        public override void InitContextMenu()
        {
            base.InitContextMenu();

            PredicateMenuList.Clear();
            MainViewModel.Resource.ConditionPrototypeList.ForEach(v =>
            {
                var command = new CommonCommand((obj) =>
                {
                    var o = v.CreateInstance() as ICondition;
                    o.GetInstrumentList = () => {
                        var l = new List <IInstrument>();
                        foreach (var inst in InstrumentList)
                        {
                            l.Add(inst);
                        }
                        return(l);
                    };
                    o.AnalyseDataSource = CurrentDataSource;
                    var vm = new ConditionViewModel()
                    {
                        TargetObject = o
                    };
                    PredicateList.Add(vm);
                    TargetProject.PredicateList.Add(o);
                });
                command.Name            = "New " + v.Name;
                command.Memo            = v.Memo;
                command.ForegroundBrush = new SolidColorBrush(Colors.Blue);
                PredicateMenuList.Add(command);
            });

            var pcommand = new CommonCommand((obj) =>
            {
                if (CurrentPredicate != null && PredicateList.Contains(CurrentPredicate))
                {
                    PredicateList.Remove(CurrentPredicate);
                }
            });

            pcommand.Name            = "Delete Predicate";
            pcommand.Memo            = "Delete Current Predicate";
            pcommand.ForegroundBrush = new SolidColorBrush(Colors.Orange);
            PredicateMenuList.Add(pcommand);
        }
Exemple #14
0
        public static bool?Evaluate(NotExpression exp, PredicateList state)
        {
            bool?val = ExpressionExecutive.Evaluate(exp.expression, state);

            if (val == true)
            {
                return(false);
            }
            if (val == false)
            {
                return(true);
            }
            if (val == null)
            {
                return(null);
            }
            throw new NotImplementedException();
        }
Exemple #15
0
        public static bool?Evaluate(IfAndOnlyIfSyntacticExpression exp, PredicateList state)
        {
            bool?lhs = ExpressionExecutive.Evaluate(exp.lhs, state);
            bool?rhs = ExpressionExecutive.Evaluate(exp.rhs, state);

            if (lhs == true && rhs == true)
            {
                return(true);
            }
            if (lhs == true && rhs == false)
            {
                return(false);
            }
            if (lhs == true && rhs == null)
            {
                return(null);
            }
            if (lhs == false && rhs == true)
            {
                return(false);
            }
            if (lhs == false && rhs == false)
            {
                return(true);
            }
            if (lhs == false && rhs == null)
            {
                return(null);
            }
            if (lhs == null && rhs == true)
            {
                return(null);
            }
            if (lhs == null && rhs == false)
            {
                return(null);
            }
            if (lhs == null && rhs == null)
            {
                return(null);
            }
            throw new NotImplementedException();
        }
Exemple #16
0
        public override void RecoverySerialObject()
        {
            ConditionList.Clear();
            ConditionSerialList.ForEach(v =>
            {
                var i = v.CreateInstance(BacktestingResource.CommonResource.ConditionPrototypeList.Cast <ISerialSupport>().ToList());
                if (i != null)
                {
                    ConditionList.Add(i as ICondition);
                }
            });

            PredicateList.Clear();
            PredicateSerialList.ForEach(v =>
            {
                var i = v.CreateInstance(BacktestingResource.CommonResource.ConditionPrototypeList.Cast <ISerialSupport>().ToList());
                if (i != null)
                {
                    PredicateList.Add(i as ICondition);
                }
            });
        }
        public async Task GivenTodoWebApiControllers_WhenBeingAnalyzed_ThenEnsureTheyDoNotDependOnServiceInterfaces()
        {
            // Arrange
            PredicateList webApiControllers = GetWebApiControllers();

            string[] serviceInterfaces = Types.InAssembly(typeof(ITodoItemService).Assembly)
                                         .That()
                                         .ArePublic()
                                         .And().AreInterfaces()
                                         .GetTypes()
                                         .Where(localType => !string.IsNullOrWhiteSpace(localType.FullName))
                                         .Select(localType => localType.FullName)
                                         .ToArray();

            // Act
            TestResult testResult = webApiControllers.Should().NotHaveDependencyOnAny(serviceInterfaces).GetResult();

            await DisplayFailingTypesIfAnyAsync(testResult);

            // Assert
            testResult.IsSuccessful.Should().Be(true, "Web API controllers must *not* depend on any service interface");
        }
        public async Task GivenTodoWebApiControllers_WhenBeingAnalyzed_ThenEnsureTheyDoNotDependOnPersistence()
        {
            // Arrange
            PredicateList webApiControllers = GetWebApiControllers();

            string[] persistenceNamespaces = Types.InAssembly(typeof(TodoDbContext).Assembly)
                                             .GetTypes()
                                             .Where(localType => !string.IsNullOrWhiteSpace(localType.Namespace))
                                             .Select(localType => localType.Namespace)
                                             .Distinct()
                                             .ToArray();

            // Act
            TestResult testResult =
                webApiControllers.Should().NotHaveDependencyOnAny(persistenceNamespaces).GetResult();

            await DisplayFailingTypesIfAnyAsync(testResult);

            // Assert
            testResult.IsSuccessful
            .Should().Be(true, "Web API controllers must *not* depend on persistence related namespaces");
        }
Exemple #19
0
        public override void LoadInfo()
        {
            if (TargetProject == null)
            {
                return;
            }
            ConditionList.Clear();
            TargetProject.ConditionList.ForEach(v => ConditionList.Add(new ConditionViewModel()
            {
                TargetObject = v
            }));
            PredicateList.Clear();
            TargetProject.PredicateList.ForEach(v => PredicateList.Add(new ConditionViewModel()
            {
                TargetObject = v
            }));

            InstrumentList.Clear();
            TargetProject.InstrumentList.ForEach(v => InstrumentList.Add(v));
            ResultList.Clear();
            TargetProject.ResultList.ForEach(v => ResultList.Add(new InstrumentViewModel()
            {
                TargetObject = v, GetCurrentDataSource = () => { return(CurrentDataSource); }
            }));
            TargetProject.BlockList.ForEach(v => BlockList.Add(new InstrumentViewModel()
            {
                TargetObject = v, GetCurrentDataSource = () => { return(CurrentDataSource); }
            }));
            CurrentDataSource = TargetProject.CurrentDataSource;

            IsChanged = false;
            if (TargetSummaryVM != null)
            {
                TargetSummaryVM.Refresh();
            }
        }
 public void Setup()
 {
     predicateList = new PredicateList();
 }
Exemple #21
0
        public Sentence ProcessSimpleSentence(string sentence, Punctuation punctuation, string original)
        {
            //Think this is causing a bug.
            ////HACK: Still need a better way to deal with quotes.
            //if (sentence.EndCheck("»") || sentence.EndCheck("«"))
            //{
            //    sentence = sentence.Substring(0, sentence.Length - 1);
            //}



            //Comment? Get out of here!
            if (sentence.StartCheck("///"))
            {
                Comment c = new Comment(sentence);
                return(new Sentence(c, diagnostics));
            }

            //Simple exclamation! Get out of here!
            if (Exclamation.IsExclamation(sentence))
            {
                return(new Sentence(new Exclamation(new HeadedPhrase(new Word(sentence))), punctuation, new SentenceDiagnostics(original, sentence)));
            }

            List <Vocative> headVocatives = null;

            //jan Mato o, ale li pona. Head vocative!
            //kin la o moku. //not a vocative (hopefully dealt with elsewhere)
            //jan Mato o moku! //Head vocative, & imperative, with 2nd o discarded
            //jan Mato o o moku! //Head vocative, & imperative, with 2nd o discarded


            if (sentence.ContainsCheck(" o o "))//Explicit vocative & imperative
            {
                //Okay, we know exactly when the head vocatives end.
                headVocatives = new List <Vocative>();
                string justHeadVocatives = sentence.Substring(0, sentence.IndexOf(" o o ", StringComparison.Ordinal));

                //Process head vocatives.
                ProcessHeadVocatives(Splitters.SplitOnO(justHeadVocatives), headVocatives, allAreVocatives: true);
                //BUG: Add the dummy! (And it still doesn't work!)
                sentence = "jan Sanwan o " + sentence.Substring(sentence.IndexOf(" o o ", StringComparison.Ordinal) + 5);
            }


            //Starts with o, then we have imperative & no head vocatives.
            bool endsOrStartsWithO = sentence.StartCheck("o ") && sentence.EndCheck(" o");

            if (!endsOrStartsWithO)
            {
                //jan So o! (We already deal with degenerate vocative sentences elsewhere)
                //jan So o sina li nasa.
                //jan So o nasa!
                //jan So o mi mute o nasa.  <-- This is the problem.

                //These could be vocatives or imperatives.
                if (sentence.ContainsCheck(" o ", " o,", ",o ") && sentence.ContainsCheck(" li "))
                {
                    headVocatives = new List <Vocative>();

                    ProcessHeadVocatives(Splitters.SplitOnO(sentence), headVocatives, allAreVocatives: false);

                    //int firstLi = sentence.IndexOf(" li ");
                    int lastO = sentence.LastIndexOf(" o ", StringComparison.Ordinal);
                    if (lastO < 0)
                    {
                        lastO = sentence.LastIndexOf(" o,", StringComparison.Ordinal);
                    }

                    sentence = sentence.Substring(lastO + 2);
                }
            }

            //Process tag conjunctions and tag questions
            Particle    conjunction = null;
            TagQuestion tagQuestion = null;

            if (sentence.StartCheck("taso "))
            {
                conjunction = Particles.taso;
                sentence    = sentence.Substring(5);
            }
            else if (sentence.StartCheck("anu "))
            {
                conjunction = Particles.anu;
                sentence    = sentence.Substring(4);
            }
            else if (sentence.StartCheck("en "))
            {
                //Well, either parse it or throw. Otherwise, this gets skipped.
                //is this legal?
                conjunction = Particles.en;
                sentence    = sentence.Substring(3);
            }
            else if (sentence.StartCheck("ante ")) //never seen it.
            {
                conjunction = Particles.ante;
                sentence    = sentence.Substring(5);
            }

            //Should already have ? stripped off
            if (sentence.EndsWith(" anu seme"))
            {
                tagQuestion = new TagQuestion();
                sentence    = sentence.Substring(0, sentence.LastIndexOf(" anu seme", StringComparison.Ordinal));
            }


            if (sentence.EndCheck(" li"))
            {
                throw new TpParseException("Something went wrong-- sentenc ends with li. " + sentence);
            }
            if (sentence.StartsOrContainsOrEnds("la"))
            {
                throw new TpParseException("If it contains a la, anywhere, it isn't a simple sentence. " + sentence);
            }

            bool isHortative  = false;
            bool isImperative = false;

            if (sentence.StartCheck("o ") && sentence.ContainsCheck(" li "))
            {
                //o mi mute li moku
                isHortative = true;
                sentence    = sentence.RemoveLeadingWholeWord("o");
            }
            if (sentence.StartCheck("o ") && !sentence.ContainsCheck(" li "))
            {
                //o pana e pan
                isImperative = true;
                //sentence = sentence.RemoveLeadingWholeWord("o");
            }
            // someting o ==> vocative

            string[] liParts = Splitters.SplitOnLiOrO(sentence);

            if (liParts.Length == 1 && Exclamation.IsExclamation(liParts[0]))
            {
                //HACK: Duplicate code. & it only deals with a single final puncution mark.
                string possiblePunctuation = sentence[sentence.Length - 1].ToString();
                if (Punctuation.TryParse(possiblePunctuation, out punctuation))
                {
                    sentence = sentence.Substring(0, sentence.Length - 1);
                }

                //The whole thing is o! (or pakala! or the like)
                //pona a! a a a! ike a!
                TokenParserUtils tpu = new TokenParserUtils();

                Word[]       tokes         = tpu.ValidWords(sentence);
                HeadedPhrase parts         = new HeadedPhrase(tokes[0], new WordSet(ArrayExtensions.Tail(tokes)));
                bool         modifiersAreA = true;

                foreach (Word w in parts.Modifiers)
                {
                    if (w == "a")
                    {
                        continue;           //peculiar to exclamations & repeats.
                    }
                    if (w == "kin")
                    {
                        continue;             //modifies just about anything
                    }
                    modifiersAreA = false;
                }

                if (modifiersAreA)
                {
                    Exclamation exclamation = new Exclamation(parts);
                    Sentence    s           = new Sentence(exclamation, punctuation, diagnostics);
                    return(s);
                }
            }


            //Degenerate sentences.
            if (liParts[liParts.Length - 1].Trim(new char[] { ',', '«', '»', '!', ' ' }) == "o")
            {
                //We have a vocative sentence...
                Vocative vocative = new Vocative(ProcessEnPiChain(liParts[0]));
                Sentence s        = new Sentence(vocative, punctuation, diagnostics);
                return(s);
            }

            string subjects = liParts[0].Trim();

            ComplexChain subjectChain = null;
            int          startAt      = 1; //slot 0 is normally a subject

            if (subjects.Contains("«"))
            {
                int foo = 3;
            }
            if (subjects.StartCheck("o ") ||
                subjects.StartCheck("«o "))
            {
                //This is a verb phrase with implicit subjects!
                startAt = 0;
            }
            else
            {
                subjectChain = ProcessEnPiChain(subjects);
            }

            PredicateList verbPhrases = new PredicateList();

            for (int i = startAt; i < liParts.Length; i++)
            {
                string predicate = liParts[i].Trim();

                verbPhrases.Add(ProcessPredicates(predicate));
            }

            //Head or complete sentence.

            Sentence parsedSentence = new Sentence(subjectChain, verbPhrases, diagnostics, new SentenceOptionalParts
            {
                Conjunction = conjunction,
                //Etc
                Punctuation   = punctuation,
                IsHortative   = isHortative,
                TagQuestion   = tagQuestion,
                HeadVocatives = headVocatives != null ? headVocatives.ToArray() : null
            });

            return(parsedSentence);
        }
Exemple #22
0
 public override void SaveOriginalStatus()
 {
     CurrentDataSource.SaveOriginalStatus();
     ConditionList.ForEach(v => v.SaveOriginalStatus());
     PredicateList.ForEach(v => v.SaveOriginalStatus());
 }
Exemple #23
0
 public override void FinishWork()
 {
     CurrentDataSource.FinishWork();
     ConditionList.ForEach(v => v.FinishWork());
     PredicateList.ForEach(v => v.FinishWork());
 }
Exemple #24
0
 /// <summary>
 /// each of the following expressions all rely on expressions either unary or binary
 /// these are defined in the evaluate function, these can only really be worked out when all predicate suppositions
 /// are made. For propositions like p and not p must be run
 /// </summary>
 /// <param name="element"></param>
 /// <param name="predicateState"></param>
 /// <returns></returns>
 public static PredicateList execute(ThereforeSyntacticElement element, PredicateList predicateState)
 {
     // for of a therefore are
     element.Value = ExpressionExecutive.Evaluate(element.expression, predicateState);
     return(predicateState);
 }