Ejemplo n.º 1
0
        private IPatternRecognizer GetPatternRecognizerForSentence4()
        {
            // initial state
            string S = "S";

            // final state
            string[] Z = new string[] { "Z" };

            // productions
            List <Tuple <string, string, string> > prod = new List <Tuple <string, string, string> >();

            prod.Add(new Tuple <string, string, string>("S", "how", "A"));
            prod.Add(new Tuple <string, string, string>("A", "much", "B"));
            prod.Add(new Tuple <string, string, string>("B", "is", "C"));

            foreach (var sym in _symbolPairs)
            {
                prod.Add(new Tuple <string, string, string>("C", sym.Key, "D"));
                prod.Add(new Tuple <string, string, string>("D", sym.Key, "D"));
            }

            prod.Add(new Tuple <string, string, string>("D", "?", "Z"));

            PatternRecognizer pr = new PatternRecognizer(S, Z, prod);

            return(pr);
        }
Ejemplo n.º 2
0
        private IPatternRecognizer GetPatternRecognizerForSentence1()
        {
            // initial state
            string S = "S";

            // final state
            string[] Z = new string[] { "Z" };

            // productions
            List <Tuple <string, string, string> > prod = new List <Tuple <string, string, string> >();

            prod.Add(new Tuple <string, string, string>("S", PatternRecognizer.ANY, "A"));
            prod.Add(new Tuple <string, string, string>("A", "means", "B"));

            var romanSymbols = _converter.GetSymbols();

            foreach (var s in romanSymbols)
            {
                prod.Add(new Tuple <string, string, string>("B", s.Key, "Z"));
            }

            PatternRecognizer pr = new PatternRecognizer(S, Z, prod);

            return(pr);
        }
Ejemplo n.º 3
0
        private IPatternRecognizer GetPatternRecognizerForSentence2()
        {
            // initial state
            string S = "S";

            // final state
            string[] Z = new string[] { "Z" };

            // productions
            List <Tuple <string, string, string> > prod = new List <Tuple <string, string, string> >();

            foreach (var sym in _symbolPairs)
            {
                prod.Add(new Tuple <string, string, string>("S", sym.Key, "A"));
                prod.Add(new Tuple <string, string, string>("A", sym.Key, "A"));
            }


            prod.Add(new Tuple <string, string, string>("A", "units", "B"));
            prod.Add(new Tuple <string, string, string>("B", "of", "C"));

            foreach (var m in _metals)
            {
                prod.Add(new Tuple <string, string, string>("C", m.Key, "D"));
            }

            prod.Add(new Tuple <string, string, string>("D", "are", "E"));
            prod.Add(new Tuple <string, string, string>("E", "worth", "F"));
            prod.Add(new Tuple <string, string, string>("F", PatternRecognizer.NUMBER, "G"));
            prod.Add(new Tuple <string, string, string>("G", "Credits", "Z"));

            PatternRecognizer pr = new PatternRecognizer(S, Z, prod);

            return(pr);
        }
Ejemplo n.º 4
0
        public void PatternRecognizerSerializesCorrectly()
        {
            var recogniser = new PatternRecognizer
            {
                Anchor    = PatternRecognizerAnchor.End,
                Fuzzy     = true,
                GadgetIds = new List <string> {
                    "gadgetId1", "gadgetId2", "gadgetId3"
                },
                Actions = new List <string> {
                    "down", "up"
                },
                Patterns = new List <Pattern>
                {
                    new Pattern
                    {
                        Action    = "down",
                        GadgetIds = new List <string> {
                            "gadgetId1", "gadgetId2"
                        },
                        Colors = new List <string> {
                            "0000FF"
                        }
                    }
                }
            };

            Assert.True(Utility.CompareJson(recogniser, "PatternRecognizer.json"));
        }
Ejemplo n.º 5
0
        public void InitializeTests()
        {
            this.Board         = new Game.Data.Contract.Board();
            this.RowController = new RowController();
            this.Recognizer    = new PatternRecognizer(this.Board, this.RowController);
            this.Analyzer      = new BoardAnalyzer(this.Board);
            this.Controller    = new BoardController(this.Board, this.Analyzer, this.Recognizer);
            this.Controller.Initialize();
            this.Player = new Player("Nerzal")
            {
                Color = Colors.White
            };
            this.Player2 = new Player("Wr4thon")
            {
                Color = Colors.Black
            };

            IMovementRules movementRules = new MovementRules(this.Analyzer, this.Board);
            IGameOverRules gameOverRules = new GameOverRules(this.Analyzer);
            IRuleSet       ruleSet       = new RuleSet(movementRules, gameOverRules);
            IHistory       history       = new History();

            this.MillRuleEvaluator = new Evaluator(ruleSet, this.Analyzer);
            IRowController     rowController     = new RowController();
            IPatternRecognizer patternRecognizer = new PatternRecognizer(this.Board, rowController);

            this.GameController = new GameController(this.MillRuleEvaluator, this.Board, history, this.Controller, patternRecognizer, rowController);
        }
        private static void AddButtonDownTrigger(StartInputHandlerDirective directive, string triggerEventName, string[] possibleGadgetIds)
        {
            var recogniser = new PatternRecognizer
            {
                GadgetIds = possibleGadgetIds.ToList(),
                Fuzzy     = true
            };

            recogniser.Patterns.Add(new Pattern {
                Action = ButtonAction.Down
            });

            directive.Recognizers.Add(triggerEventName, recogniser);
        }
        private static void AddRollCallRecognisers(StartInputHandlerDirective directive, string[] names)
        {
            var recogniser = new PatternRecognizer
            {
                Fuzzy  = true,
                Anchor = PatternRecognizerAnchor.Start
            };

            directive.Recognizers.Add(RollCallCompleteName, recogniser);

            foreach (var name in names)
            {
                var pattern = CreateRollCallPattern(name);
                recogniser.Patterns.Add(pattern);
            }
        }
Ejemplo n.º 8
0
        public void CompareRecognizers()
        {
            LegacyDataLibrary library;
            using (var stream = typeof(LegacyRecognitionTest).Assembly.GetManifestResourceStream(typeof(LegacyRecognitionTest), "LegacyTrainingData.dat"))
                library = LegacyDataLibrary.FromStream(stream);

            var rand = new Random();
            var input = new int[library.ReferenceSet.HeuristicCount];
            for (int i = 0; i < input.Length; i++)
                input[i] = rand.Next();			//There is no reason to use secure random numbers here.

            var newResult = new PatternRecognizer().Recognize(library.ReferenceSet, input);
            var oldResult = new LegacyRecognizer().Recognize(library, input);

            if (oldResult == null)
                Assert.IsNull(newResult);
            else {
                Assert.AreEqual(oldResult.Item2, newResult.Certainty);
                Assert.AreEqual(oldResult.Item1, newResult.Label);
            }
        }