Beispiel #1
0
        private Grammar CreateGrammar2D()
        {
            SrgsDocument doc = new SrgsDocument();

            doc.PhoneticAlphabet = SrgsPhoneticAlphabet.Ups;
            SrgsRule  rule  = new SrgsRule("check");
            SrgsOneOf oneOf = new SrgsOneOf();
            int       count = phonems.Length;

            for (int i = 0; i < count; i++)
            {
                for (int i2 = 0; i2 < count; i2++)
                {
                    string text          = phonems[i] + phonems[i2];
                    string pronunciation = phonems[i] + " " + phonems[i2];

                    SrgsToken token = new SrgsToken(text);
                    token.Pronunciation = pronunciation;
                    SrgsItem item = new SrgsItem(token);
                    oneOf.Add(item);
                }
            }

            rule.Add(oneOf);
            doc.Rules.Add(rule);
            doc.Root    = rule;
            doc.Culture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
            Grammar grammar = new Grammar(doc);

            return(grammar);
        }
Beispiel #2
0
        //Method to add item dynamically in the grammar
        private void addItemInABalise(SrgsDocument xmlGrammar, string nameOfRule, int idOfBalise, string itemToAdd)
        {
            #region Add item dynamically in the grammar

            //if the balise target by idOfBalise is a "OneOf" balise
            try
            {
                SrgsOneOf oneOfBalise = (SrgsOneOf)xmlGrammar.Rules[nameOfRule].Elements[idOfBalise];
                oneOfBalise.Add(new SrgsItem(itemToAdd));//Add item in the "OneOf" balise
            }
            catch
            {
                //if the balise target by idOfBalise is a "Item" balise
                try
                {
                    SrgsItem itemBalise = (SrgsItem)xmlGrammar.Rules[nameOfRule].Elements[idOfBalise];
                    itemBalise.Add(new SrgsItem(itemToAdd));//Add item in the "Item" balise
                }
                //Otherwise, return a message box error to inform user
                catch
                {
                    // Configure the message box to be displayed
                    string            messageBoxText = "In the method addItemInABalise(), it is only possible to add item after a OneOf balise or a Item balise!";
                    string            caption        = "Error in method addItemInABalise";
                    MessageBoxButtons button         = MessageBoxButtons.OK;
                    MessageBoxIcon    icon           = MessageBoxIcon.Error;
                    MessageBox.Show(messageBoxText, caption, button, icon);// Display message box
                }
            }

            #endregion
        }
Beispiel #3
0
        public Grammar[] CreateGrammar_Basic2DX()
        {
            List <Grammar>        grammars = new List <Grammar>();
            List <List <string> > words    = new List <List <string> >();

            int count = phonems_basic.Length;

            for (int i = 0; i < count; i++)
            {
                SrgsDocument doc = new SrgsDocument();
                doc.PhoneticAlphabet = SrgsPhoneticAlphabet.Ups;
                SrgsRule  rule  = new SrgsRule("basic2D" + i);
                SrgsOneOf oneOf = new SrgsOneOf();

                for (int i2 = 0; i2 < count; i2++)
                {
                    string text          = phonems_basic[i] + phonems_basic[i2];
                    string pronunciation = phonems_basic[i] + " " + phonems_basic[i2];

                    SrgsToken token = new SrgsToken(text);
                    token.Pronunciation = pronunciation;
                    SrgsItem item = new SrgsItem(token);
                    oneOf.Add(item);
                }

                rule.Add(oneOf);
                doc.Rules.Add(rule);
                doc.Root    = rule;
                doc.Culture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
                Grammar grammar = new Grammar(doc);
                grammars.Add(grammar);
            }

            return(grammars.ToArray());
        }
Beispiel #4
0
        private void AddRowSeatSpeechGrammarRules(SrgsRulesCollection rules)
        {
            SrgsRule rowSeatSrgsRule;

            {
                SrgsOneOf rowSeatSrgsOneOf = new SrgsOneOf();

                int i = 0;
                foreach (Seat seat in GetSeats())
                {
                    SrgsItem srgsItem = new SrgsItem("Rząd " + seat.Row + " miejsce " + seat.No);
                    srgsItem.Add(new SrgsSemanticInterpretationTag("out=\"rowseat." + i++ + "\";"));

                    rowSeatSrgsOneOf.Add(srgsItem);
                }

                SrgsItem phraseSrgsItem = new SrgsItem();
                phraseSrgsItem.Add(new SrgsItem(0, 1, "Wybierz"));
                phraseSrgsItem.Add(rowSeatSrgsOneOf);

                rowSeatSrgsRule = new SrgsRule("rowseat", phraseSrgsItem);
            }

            rules.Add(rowSeatSrgsRule);

            {
                SrgsItem srgsItem = new SrgsItem();
                srgsItem.Add(new SrgsRuleRef(rowSeatSrgsRule));

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
        private Grammar GetGrammar()
        {
            SrgsDocument document = new SrgsDocument();

            SrgsRule rootRule = new SrgsRule("directionRule");

            rootRule.Scope = SrgsRuleScope.Public;

            List <SrgsRule> oneTickGrammarDocument                    = GetDirectionRule(firstNumberEntry, "Tick", directionEntries, "oneTickRule");
            List <SrgsRule> multipleTicksGrammarDocument              = GetDirectionRule(numberEntries, "Ticks", directionEntries, "multipleTicksRule");
            List <SrgsRule> oneTickNoBindingWordGrammarDocument       = GetDirectionRule(firstNumberEntry, null, directionEntries, "oneTickRuleNoBindingWord");
            List <SrgsRule> multipleTicksNoBindingWordGrammarDocument = GetDirectionRule(numberEntries, null, directionEntries, "multipleTicksRuleNoBindingWord");

            SrgsOneOf oneOfElements = new SrgsOneOf(
                new SrgsItem(new SrgsRuleRef(oneTickGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(multipleTicksGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(oneTickNoBindingWordGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(multipleTicksNoBindingWordGrammarDocument[0]))
                );

            rootRule.Add(oneOfElements);

            document.Rules.Add(rootRule);
            document.Rules.Add(oneTickGrammarDocument.ToArray());
            document.Rules.Add(multipleTicksGrammarDocument.ToArray());
            document.Rules.Add(oneTickNoBindingWordGrammarDocument.ToArray());
            document.Rules.Add(multipleTicksNoBindingWordGrammarDocument.ToArray());

            document.Root = rootRule;

            return(new Grammar(document));
        }
Beispiel #6
0
        /// <summary>
        /// Create Grammars for the contact names of customer's contact list
        /// </summary>
        private void Code_PrepareGrammar(object sender, EventArgs e)
        {
            SrgsOneOf oneOf = new SrgsOneOf();

            foreach (var contact in contacts)
            {
                SrgsItem item = new SrgsItem(contact.Value.DisplayName);

                SrgsSemanticInterpretationTag tag =
                    new SrgsSemanticInterpretationTag("$._value = \"" + contact.Key + "\";");

                SrgsItem nameItem = new SrgsItem();
                nameItem.Add(item);
                nameItem.Add(tag);

                oneOf.Add(nameItem);
            }

            SrgsRule nameRule = new SrgsRule("name");

            nameRule.Scope = SrgsRuleScope.Public;
            nameRule.Elements.Add(oneOf);

            SrgsDocument grammarDoc = new SrgsDocument();

            grammarDoc.Rules.Add(nameRule);
            grammarDoc.Root = nameRule;

            speechGrammar.Add(new Grammar(grammarDoc));
        }
        public SrgsDocumentBuilder()
        {
            this.rootRuleRefs = new SrgsOneOf();
            this.rules = new List<SrgsRule>();

            this.References = new Dictionary<string, SrgsRuleRef>();
        }
        public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs)
        {
            var commands = new SrgsOneOf(
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'Input'"),
                    new SrgsItem("memory"),
                    new SrgsSemanticInterpretationTag("out.Numbers = ''"),
                    new SrgsItem(5, 5,
                        refs["Number"],
                        new SrgsSemanticInterpretationTag("out.Numbers += rules.Number + ','")
                    )
                ),
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'Reset'"),
                    new SrgsItem("memory reset")
                )
            );

            var moduleRule = new SrgsRule("Memory",
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Module = 'Memory'"),
                    commands
                )
            );

            return new Tuple<SrgsRuleRef, IList<SrgsRule>>(
                new SrgsRuleRef(moduleRule),
                new List<SrgsRule> { moduleRule }
            );
        }
Beispiel #9
0
        private SrgsRule GetDirectionRules()
        {
            SrgsRule directionRule = new SrgsRule("directionRule");

            usedRules.Add("directionRule", directionRule);

            List <String> oneTickNumberValues       = mapping.GetNumberValues(1, 1);
            List <String> multipleTicksNumberValues = mapping.GetNumberValues(2, 9);
            List <String> directionValues           = mapping.GetDirectionMappingValues();

            SrgsRule oneTickGrammarRule       = GetDirectionRule(oneTickNumberValues, mapping.TickInputMapping, directionValues, "oneTickRule");
            SrgsRule multipleTicksGrammarRule = GetDirectionRule(multipleTicksNumberValues, mapping.TicksInputMapping, directionValues, "multipleTicksRule");

            SrgsRule oneTickNoBindingWordGrammarRule       = GetDirectionRule(oneTickNumberValues, null, directionValues, "oneTickRuleNoBindingWord");
            SrgsRule multipleTicksNoBindingWordGrammarRule = GetDirectionRule(multipleTicksNumberValues, null, directionValues, "multipleTicksRuleNoBindingWord");

            SrgsOneOf oneOfElements = new SrgsOneOf(
                new SrgsItem(new SrgsRuleRef(oneTickGrammarRule)),
                new SrgsItem(new SrgsRuleRef(multipleTicksGrammarRule)),
                new SrgsItem(new SrgsRuleRef(oneTickNoBindingWordGrammarRule)),
                new SrgsItem(new SrgsRuleRef(multipleTicksNoBindingWordGrammarRule))
                );

            directionRule.Add(oneOfElements);

            return(directionRule);
        }
        public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs)
        {
            var commands = new SrgsOneOf(
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'Input';"),
                    new SrgsItem("password"),
                    refs["Number"],
                    new SrgsSemanticInterpretationTag("out.Column = rules.Number; out.Letters = '';"),
                    new SrgsItem(1, 6,
                        refs["Letter"],
                        new SrgsSemanticInterpretationTag("out.Letters += rules.Letter")
                    )
                ),
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'Reset'"),
                    new SrgsItem("password reset")
                )
            );

            var moduleRule = new SrgsRule("Passwords",
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Module = 'Passwords'"),
                    commands
                )
            );

            return new Tuple<SrgsRuleRef, IList<SrgsRule>>(
                new SrgsRuleRef(moduleRule),
                new List<SrgsRule> { moduleRule }
            );
        }
        private Grammar GetGrammar()
        {
            SrgsDocument document = new SrgsDocument();

            SrgsRule rootRule = new SrgsRule("directionRule");
            rootRule.Scope = SrgsRuleScope.Public;

            List<SrgsRule> oneTickGrammarDocument = GetDirectionRule(firstNumberEntry, "Tick", directionEntries, "oneTickRule");
            List<SrgsRule> multipleTicksGrammarDocument = GetDirectionRule(numberEntries, "Ticks", directionEntries, "multipleTicksRule");
            List<SrgsRule> oneTickNoBindingWordGrammarDocument = GetDirectionRule(firstNumberEntry, null, directionEntries, "oneTickRuleNoBindingWord");
            List<SrgsRule> multipleTicksNoBindingWordGrammarDocument = GetDirectionRule(numberEntries, null, directionEntries, "multipleTicksRuleNoBindingWord");

            SrgsOneOf oneOfElements = new SrgsOneOf(
                new SrgsItem(new SrgsRuleRef(oneTickGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(multipleTicksGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(oneTickNoBindingWordGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(multipleTicksNoBindingWordGrammarDocument[0]))
            );

            rootRule.Add(oneOfElements);

            document.Rules.Add(rootRule);
            document.Rules.Add(oneTickGrammarDocument.ToArray());
            document.Rules.Add(multipleTicksGrammarDocument.ToArray());
            document.Rules.Add(oneTickNoBindingWordGrammarDocument.ToArray());
            document.Rules.Add(multipleTicksNoBindingWordGrammarDocument.ToArray());

            document.Root = rootRule;

            return new Grammar(document);
        }
Beispiel #12
0
        private void GenerateRuleList(string semantic, string[] alternates, SrgsRuleRef subjectRef = null, DirectObject directObject = null)
        {
            SrgsOneOf commandAlternates = new SrgsOneOf(alternates);
            SrgsItem  command           = new SrgsItem();

            if (subjectRef != null)
            {
                command.Add(new SrgsItem(subjectRef));
                command.Add(new SrgsSemanticInterpretationTag("out.subject=rules.subject;"));
            }

            command.Add(commandAlternates);
            command.Add(new SrgsSemanticInterpretationTag("out.command=\"" + semantic + "\";"));

            if (directObject != null)
            {
                command.Add(directObject.RuleRef);
                command.Add(new SrgsSemanticInterpretationTag("out.directObject=rules." + directObject.RuleName + ";"));
            }

            Item = command;

            RuleList = new List <SrgsRule>();
            SrgsRule rule = new SrgsRule(semantic);

            rule.Add(command);

            RuleList.Add(rule);
            RootRule = rule;
        }
Beispiel #13
0
        private void GenerateRuleList(string semantic, string[] alternates, SrgsRuleRef subjectRef = null, DirectObject directObject = null)
        {
            SrgsOneOf commandAlternates = new SrgsOneOf(alternates);
            SrgsItem command = new SrgsItem();

            if (subjectRef != null)
            {
                command.Add(new SrgsItem(subjectRef));
                command.Add(new SrgsSemanticInterpretationTag("out.subject=rules.subject;"));
            }

            command.Add(commandAlternates);
            command.Add(new SrgsSemanticInterpretationTag("out.command=\"" + semantic + "\";"));

            if (directObject != null)
            {
                command.Add(directObject.RuleRef);
                command.Add(new SrgsSemanticInterpretationTag("out.directObject=rules." + directObject.RuleName + ";"));
            }

            Item = command;

            RuleList = new List<SrgsRule>();
            SrgsRule rule = new SrgsRule(semantic);
            rule.Add(command);

            RuleList.Add(rule);
            RootRule = rule;
        }
Beispiel #14
0
        public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs)
        {
            var commands = new SrgsOneOf(
                new SrgsItem(
                    new SrgsItem("wires"),
                    new SrgsSemanticInterpretationTag("out.Colors = '';"),
                    new SrgsItem(3, 6,
                        refs["Color"],
                        new SrgsSemanticInterpretationTag("out.Colors += rules.Color + ' ';")
                    )
                )
            );

            var moduleRule = new SrgsRule("Wires",
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Module = 'Wires'"),
                    commands
                )
            );

            return new Tuple<SrgsRuleRef, IList<SrgsRule>>(
                new SrgsRuleRef(moduleRule),
                new List<SrgsRule> { moduleRule }
            );
        }
Beispiel #15
0
        /// <summary>
        /// Creates a grammar for main menu options.
        /// </summary>
        /// <returns></returns>
        private Grammar SetupGrammar()
        {
            var options = this.MainMenuConfiguration.Options;

            SrgsOneOf oneOf = new SrgsOneOf();

            foreach (var option in options)
            {
                SrgsItem item = new SrgsItem(option.Index.ToString(CultureInfo.InvariantCulture));

                SrgsSemanticInterpretationTag tag =
                    new SrgsSemanticInterpretationTag("$._value = \"" + option.DtmfCode + "\";");

                SrgsItem digitItem = new SrgsItem();
                digitItem.Add(item);
                digitItem.Add(tag);

                oneOf.Add(digitItem);
            }

            SrgsRule digitRule = new SrgsRule("digit");

            digitRule.Scope = SrgsRuleScope.Public;
            digitRule.Elements.Add(oneOf);

            SrgsDocument grammarDoc = new SrgsDocument();

            grammarDoc.Mode = SrgsGrammarMode.Dtmf;
            grammarDoc.Rules.Add(digitRule);
            grammarDoc.Root = digitRule;

            return(new Grammar(grammarDoc));
        }
Beispiel #16
0
        private void GenerateSubjectList()
        {
            RuleList = new List <SrgsRule>();

            // INDIVIDUAL
            List <SrgsItem> numbersList = new List <SrgsItem>();

            for (int num = 1; num < 25; num++)
            {
                numbersList.Add(GetNewNode(new string[] { num.ToString() }, num.ToString().ToUpper()));
            }

            SrgsOneOf squadNumbersChoice       = new SrgsOneOf(numbersList.ToArray());
            SrgsItem  squadNumbersConcatChoice = new SrgsItem(squadNumbersChoice, new SrgsItem(0, 1, "and"));

            squadNumbersConcatChoice.SetRepeat(1, 12);

            SrgsRule squadNumbers = new SrgsRule("squadNumbers");

            squadNumbers.Add(squadNumbersConcatChoice);
            RuleList.Add(squadNumbers);

            SrgsRule squadMembers = new SrgsRule("squadSelections");

            squadMembers.Add(new SrgsRuleRef(squadNumbers));
            squadMembers.Add(new SrgsSemanticInterpretationTag("out=rules.squadNumbers;"));
            RuleList.Add(squadMembers);

            // ALL
            SrgsItem allItems = GetNewNode(new string[] { "all", "everyone", "team", "squad", "group" }, "ALL");
            SrgsRule all      = new SrgsRule("all");

            all.Add(allItems);
            RuleList.Add(all);

            // DESELECT ALL (DISREGARD)
            SrgsItem disregardItems = GetNewNode(new string[] { "disregard" }, "DISREGARD");
            SrgsRule disregard      = new SrgsRule("disregard");

            disregard.Add(disregardItems);
            RuleList.Add(disregard);

            // COLLECTING ALL COMMANDS
            SrgsOneOf subjectChoice = new SrgsOneOf();

            subjectChoice.Add(new SrgsItem(new SrgsRuleRef(squadMembers)));
            subjectChoice.Add(new SrgsItem(new SrgsRuleRef(all)));
            subjectChoice.Add(new SrgsItem(new SrgsRuleRef(disregard)));

            SrgsRule subject = new SrgsRule("subject");

            subject.Add(subjectChoice);

            RootRule = subject;
            RuleList.Add(subject);
        }
Beispiel #17
0
        private static void LoadSRGSGrammar()
        {
            //builder = new GrammarBuilder(Choices);
            //document = new SrgsDocument(builder);
            //grammar = new Grammar(document);

            // Create an SrgsDocument, create a new rule and set its scope to public.
            document = new SrgsDocument
            {
                PhoneticAlphabet = SrgsPhoneticAlphabet.Ups
            };
            //document.PhoneticAlphabet = SrgsPhoneticAlphabet.Sapi;

            //SrgsRule wordRule = (new SrgsRule("word", new SrgsElement[] { oneOfWord }));
            SrgsRule wordRule = new SrgsRule("word")
            {
                Scope = SrgsRuleScope.Public
            };

            SrgsOneOf oneOfWord = new SrgsOneOf(new SrgsItem[] { new SrgsItem("aardvark"),
                                                                 new SrgsItem("beaver"), new SrgsItem("cheetah") });

            SrgsItem  wordItem = new SrgsItem();
            SrgsToken token    = new SrgsToken("whatchamacallit")
            {
                Pronunciation = "W AE T CH AE M AE K AA L IH T"
            };

            wordItem.Add(token);
            //oneOfWord = new SrgsOneOf();
            oneOfWord.Add(wordItem);

            wordRule.Add(oneOfWord);

            //// Create the rule from the SrgsOneOf objects.
            //SrgsRule slangRule = new SrgsRule("slang", wordItem);
            //// Build an SrgsDocument object from the rule and set the phonetic alphabet.
            //SrgsDocument tokenPron = new SrgsDocument(slangRule);

            //// Create a Grammar object from the SrgsDocument and load it to the recognizer.
            //Grammar slangGrammar = new Grammar(tokenPron);
            //slangGrammar.Name = ("Slang Pronunciation");
            //RecEngine.LoadGrammarAsync(slangGrammar);

            //// Add references to winnerRule for ruleEurope.
            //wordRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem (new SrgsRuleRef(ruleEurope)))}));

            // Add all the rules to the document and set the root rule of the document.
            document.Rules.Add(new SrgsRule[] { wordRule });
            document.Root = wordRule;

            Grammar grammar = new Grammar(document);

            RecEngine.LoadGrammar(grammar);
        }
        private IOneOf ParseOneOf(SrgsOneOf srgsOneOf, IElement parent, IRule rule)
        {
            IOneOf oneOf = _parser.CreateOneOf(parent, rule);

            foreach (SrgsItem item in srgsOneOf.Items)
            {
                ProcessChildNodes(item, oneOf, rule);
            }
            oneOf.PostParse(parent);
            return(oneOf);
        }
Beispiel #19
0
        public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs)
        {
            var numbers = new SrgsOneOf(
                new SrgsItem(
                    new SrgsItem("zero"),
                    new SrgsSemanticInterpretationTag("out = 0")
                ),
                new SrgsItem(
                    new SrgsItem("one"),
                    new SrgsSemanticInterpretationTag("out = 1")
                ),
                new SrgsItem(
                    new SrgsItem("two"),
                    new SrgsSemanticInterpretationTag("out = 2")
                ),
                new SrgsItem(
                    new SrgsItem("three"),
                    new SrgsSemanticInterpretationTag("out = 3")
                ),
                new SrgsItem(
                    new SrgsItem("four"),
                    new SrgsSemanticInterpretationTag("out = 4")
                ),
                new SrgsItem(
                    new SrgsItem("five"),
                    new SrgsSemanticInterpretationTag("out = 5")
                ),
                new SrgsItem(
                    new SrgsItem("six"),
                    new SrgsSemanticInterpretationTag("out = 6")
                ),
                new SrgsItem(
                    new SrgsItem("seven"),
                    new SrgsSemanticInterpretationTag("out = 7")
                ),
                new SrgsItem(
                    new SrgsItem("eight"),
                    new SrgsSemanticInterpretationTag("out = 8")
                ),
                new SrgsItem(
                    new SrgsItem("nine"),
                    new SrgsSemanticInterpretationTag("out = 9")
                )
            );

            var numberRule = new SrgsRule("Number", numbers);
            refs["Number"] = new SrgsRuleRef(numberRule);

            return new Tuple<SrgsRuleRef, IList<SrgsRule>>(
                null,
                new List<SrgsRule> { numberRule }
            );
        }
        private void AddMoviesSpeechGrammarRules(SrgsRulesCollection srgsRules)
        {
            Movie[] movies = null;

            DispatchSync(() =>
            {
                movies = GetMovies();
            });

            if ((movies != null) && (movies.Length > 0))
            {
                SrgsRule movieSrgsRule;

                {
                    SrgsOneOf movieSrgsOneOf = new SrgsOneOf();

                    int i = 0;
                    foreach (Movie movie in movies)
                    {
                        SrgsItem srgsItem = new SrgsItem(movie.Title);
                        srgsItem.Add(new SrgsSemanticInterpretationTag("out=\"movies." + i++ + "\";"));

                        movieSrgsOneOf.Add(srgsItem);
                    }

                    SrgsItem  movieSrgsItem = new SrgsItem();
                    SrgsOneOf srgsOneOf     = new SrgsOneOf();
                    srgsOneOf.Add(new SrgsItem("Wyświetl"));
                    srgsOneOf.Add(new SrgsItem("Pokaż"));
                    srgsOneOf.Add(new SrgsItem("Wybierz"));
                    movieSrgsItem.Add(srgsOneOf);
                    movieSrgsItem.Add(new SrgsItem(0, 1, "film"));

                    SrgsItem phraseSrgsItem = new SrgsItem();
                    phraseSrgsItem.Add(movieSrgsItem);
                    phraseSrgsItem.Add(movieSrgsOneOf);

                    movieSrgsRule = new SrgsRule("movie", phraseSrgsItem);
                }

                srgsRules.Add(movieSrgsRule);

                {
                    SrgsItem srgsItem = new SrgsItem();
                    srgsItem.Add(new SrgsRuleRef(movieSrgsRule));

                    SrgsRule  rootSrgsRule = srgsRules.Where(rule => rule.Id == "root").First();
                    SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                    srgsOneOf.Add(srgsItem);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Generate a list of grammars with the annotations attach to the
        /// grammars' semantic tag.
        /// </summary>
        /// <param name="list"></param>
        /// <param name="annotations"></param>
        /// <returns></returns>
        public static List <SrgsDocument> GenerateGrammars(string[] list, string[] annotations)
        {
            String timeStamp = GetTimestamp();

            Debug.WriteLine("Before generate grammar time:" + timeStamp);

            List <SrgsDocument> srgsDocs = new List <SrgsDocument>();

            for (int i = 0; i < list.Length; i++)
            {
                SrgsRule  rule = new SrgsRule("index_" + i);
                SrgsOneOf so   = new SrgsOneOf();
                for (int j = i; j < list.Length && j < i + EBookInteractiveSystem.MAX_WORDS_IN_SPEECH; j++)
                {
                    string        ea   = "";
                    List <string> anno = new List <string>();
                    for (int k = i; k <= j; k++)
                    {
                        ea += list[k] + " ";
                        if (!anno.Contains(annotations[k]))
                        {
                            anno.Add(annotations[k]);
                        }
                    }
                    string annotate = "";
                    foreach (string ann in anno)
                    {
                        if (ann.Trim().Length > 0)
                        {
                            annotate += ann;
                        }
                    }
                    ea = ea.TrimEnd();
                    SrgsItem si = new SrgsItem(ea);
                    if (annotate.Length > 0)
                    {
                        annotate = "out.annotation=\"" + annotate + "\";";
                    }
                    si.Add(new SrgsSemanticInterpretationTag(annotate + "out.startIndex=\"" + i + "\";"));
                    so.Add(si);
                }
                rule.Add(so);
                SrgsDocument srgsDoc = new SrgsDocument();
                srgsDoc.Rules.Add(rule);
                srgsDoc.Root = rule;
                srgsDocs.Add(srgsDoc);
            }
            String after = GetTimestamp();

            Debug.WriteLine("after generate grammar time:" + after);
            return(srgsDocs);
        }
        private SrgsRule CreateRuleFromList(List <String> list, String ruleName)
        {
            SrgsOneOf oneOfElements = new SrgsOneOf();

            foreach (String listEntry in list)
            {
                oneOfElements.Add(new SrgsItem(listEntry));
            }

            SrgsRule rule = new SrgsRule(ruleName, oneOfElements);

            return(rule);
        }
        protected override void AddCustomSpeechGrammarRules(SrgsRulesCollection rules)
        {
            SrgsRule movieSrgsRule;

            {
                SrgsOneOf srgsOneOf = new SrgsOneOf();

                int i = 0;
                foreach (Screening screening in GetScreenings())
                {
                    SrgsItem srgsItem = new SrgsItem();
                    srgsItem.Add(new SrgsItem(0, 1, "Sala " + screening.Auditorium));
                    srgsItem.Add(new SrgsItem(0, 1, new SrgsOneOf(
                                                  new SrgsItem(
                                                      new SrgsItem("na"),
                                                      new SrgsItem(0, 1, "godzinę")
                                                      ),
                                                  new SrgsItem(
                                                      new SrgsItem("o"),
                                                      new SrgsItem(0, 1, "godzinie")
                                                      ),
                                                  new SrgsItem("godzina")
                                                  )));
                    srgsItem.Add(new SrgsItem(screening.GetHour()));
                    if (screening.GetMinutes() == "00")
                    {
                        srgsItem.Add(new SrgsItem(0, 1, screening.GetMinutes()));
                    }
                    else
                    {
                        srgsItem.Add(new SrgsItem(screening.GetMinutes()));
                    }
                    srgsItem.Add(new SrgsSemanticInterpretationTag("out=\"time." + i++ + "\";"));

                    srgsOneOf.Add(srgsItem);
                }

                movieSrgsRule = new SrgsRule("time", srgsOneOf);
            }

            rules.Add(movieSrgsRule);

            {
                SrgsItem srgsItem = new SrgsItem();
                srgsItem.Add(new SrgsRuleRef(movieSrgsRule));

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
Beispiel #24
0
        public void RenderButtons(IList <string> buttons, bool twoColumn)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                ClearAll();
                SrgsRule root      = new SrgsRule("command");
                SrgsOneOf commands = new SrgsOneOf();
                root.Add(new SrgsItem(commands));

                int numCols              = twoColumn ? 2 : 1;
                int numRows              = ((buttons.Count - 1) / numCols) + 1;
                ButtonsContainer.Rows    = numRows;
                ButtonsContainer.Columns = numCols;

                for (int i = 0; i < numRows * numCols; ++i)
                {
                    int index = (i % numCols) * numRows + i / numCols;
                    UIElement b;
                    if (index < buttons.Count)
                    {
                        string s = buttons[index];
                        b        = new Button()
                        {
                            Content = new TextBlock()
                            {
                                TextWrapping = TextWrapping.Wrap,
                                Text         = s,
                            },
                        };

                        commands.Add(new SrgsItem(s));
                    }
                    else
                    {
                        b = new TextBlock();
                    }

                    ButtonsContainer.Children.Add(b);
                }

                if (commands.Items.Count > 0 && EnableSpeechRecognition && _micAvailable)
                {
                    SrgsDocument doc = new SrgsDocument();
                    doc.Rules.Add(root);
                    doc.Root = root;
                    speechEngine.LoadGrammar(new Grammar(doc));
                    speechEngine.RecognizeAsync(RecognizeMode.Multiple);
                }
            }), null);
        }
        private Grammar init()
        {
            SrgsRule  ruleImie = new SrgsRule("Imię");
            SrgsOneOf imie     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, "Damian"),
                new SrgsItem(1, 1, "Jan"),
                new SrgsItem(1, 1, "Katarzyna"),
                new SrgsItem(1, 1, "Paweł"),
                new SrgsItem(1, 1, "Adam"),
                new SrgsItem(1, 1, "Maciej"),
                new SrgsItem(1, 1, "Maja"),
                new SrgsItem(1, 1, "Grzegorz")
            });

            ruleImie.Add(imie);

            SrgsRule  ruleNazwisko = new SrgsRule("Nazwisko");
            SrgsOneOf nazwisko     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, "Redkiewicz"),
                new SrgsItem(1, 1, "Piechota"),
                new SrgsItem(1, 1, "Klatka"),
                new SrgsItem(1, 1, "Kowalski"),
                new SrgsItem(1, 1, "Nowak"),
                new SrgsItem(1, 1, "Brzęczyszczykiewicz")
            });

            ruleNazwisko.Add(nazwisko);

            SrgsRule rootRule = new SrgsRule("rootBiletomat");

            rootRule.Scope = SrgsRuleScope.Public;
            rootRule.Add(new SrgsRuleRef(ruleImie, "IMIE"));
            rootRule.Add(new SrgsRuleRef(ruleNazwisko, "NAZWISKO"));

            SrgsDocument docBiletomat = new SrgsDocument();

            docBiletomat.Culture = pRecognitionLanguage;
            docBiletomat.Rules.Add(new SrgsRule[]
                                   { rootRule, ruleImie, ruleNazwisko }
                                   );
            docBiletomat.Root = rootRule;
            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("srgsDocument.xml");
            docBiletomat.WriteSrgs(writer);
            writer.Close();
            Grammar gramatyka = new Grammar(docBiletomat, "rootBiletomat");

            return(gramatyka);
        }
Beispiel #26
0
        private SrgsDocument CreateSrgsDocument()
        {
            SrgsDocument srgsDoc = new SrgsDocument();
            SrgsRule     rule    = new SrgsRule("someRule");
            SrgsItem     item    = new SrgsItem("someItem");

            item.Add(new SrgsSemanticInterpretationTag("out = \"foo\";"));
            SrgsOneOf oneOf = new SrgsOneOf(item);

            rule.Add(oneOf);

            srgsDoc.Rules.Add(rule);
            srgsDoc.Root = rule;
            return(srgsDoc);
        }
Beispiel #27
0
        public Example()
        {
            doc = new SrgsDocument();

            SrgsRule whatis = new SrgsRule("whatis");

            SrgsItem question = new SrgsItem("what is");
            SrgsOneOf closers = new SrgsOneOf("life", "the time", "love", "happiness", "two plus two");

            whatis.Add(question);
            whatis.Add(closers);
            whatis.Scope = SrgsRuleScope.Public;

            doc.Rules.Add(whatis);
            doc.Root = whatis;
        }
Beispiel #28
0
        public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs)
        {
            var commands = new SrgsOneOf(
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'Button'"),
                    new SrgsItem("button"),
                    refs["Color"],
                    new SrgsSemanticInterpretationTag("out.Color = rules.Color;"),
                    new SrgsOneOf(
                        new SrgsItem(
                            new SrgsItem("abort"),
                            new SrgsSemanticInterpretationTag("out.Label = 'abort'")
                        ),
                        new SrgsItem(
                            new SrgsItem("detonate"),
                            new SrgsSemanticInterpretationTag("out.Label = 'detonate'")
                        ),
                        new SrgsItem(
                            new SrgsItem("hold"),
                            new SrgsSemanticInterpretationTag("out.Label = 'hold'")
                        ),
                        new SrgsItem(
                            new SrgsItem("press"),
                            new SrgsSemanticInterpretationTag("out.Label = 'press'")
                        )
                    )
                ),
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'Strip'"),
                    new SrgsItem("button strip"),
                    refs["Color"],
                    new SrgsSemanticInterpretationTag("out.Color = rules.Color;")
                )
            );

            var moduleRule = new SrgsRule("Button",
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Module = 'Button'"),
                    commands
                )
            );

            return new Tuple<SrgsRuleRef, IList<SrgsRule>>(
                new SrgsRuleRef(moduleRule),
                new List<SrgsRule> { moduleRule }
            );
        }
Beispiel #29
0
        private SrgsRule GetRootRule()
        {
            SrgsRule rootRule = new SrgsRule("rootRule");

            usedRules.Add("rootRule", rootRule);

            SrgsRule directionRules     = GetDirectionRules();
            SrgsRule simpleCommandsRule = GetSimpleCommandsRule();

            SrgsOneOf oneOfElements = new SrgsOneOf(
                new SrgsItem(new SrgsRuleRef(directionRules)),
                new SrgsItem(new SrgsRuleRef(simpleCommandsRule))
                );

            rootRule.Add(oneOfElements);
            return(rootRule);
        }
Beispiel #30
0
        public void AddGrammarRules(SrgsRulesCollection rules, SrgsOneOf choices)
        {
            var grammarRules = GetGrammarRules();

            if (grammarRules.Length > 0)
            {
                rules.Add(GetGrammarRules());

                var pluginRuleItem = new SrgsItem();
                var refCurrentPluginRule = new SrgsRuleRef(rules.Single(x => x.Id == Id));
                var outPluginRuleItemSemantic = String.Format("out.type=\"{0}\"; out.params=rules.{0};", Id);

                pluginRuleItem.Add(refCurrentPluginRule);
                pluginRuleItem.Add(new SrgsSemanticInterpretationTag(outPluginRuleItemSemantic));

                choices.Add(pluginRuleItem);
            }
        }
Beispiel #31
0
        private void AddSeatSpeechGrammarRules(SrgsRulesCollection rules)
        {
            SrgsRule seatSrgsRule;

            {
                SrgsOneOf seatSrgsOneOf = new SrgsOneOf();

                List <int> seats = new List <int>();

                foreach (Seat seat in GetSeats())
                {
                    if (!seats.Contains(seat.No))
                    {
                        seats.Add(seat.No);
                    }
                }

                foreach (int seat in seats)
                {
                    SrgsItem srgsItem = new SrgsItem("Miejsce " + seat);
                    srgsItem.Add(new SrgsSemanticInterpretationTag("out=\"seat." + seat + "\";"));

                    seatSrgsOneOf.Add(srgsItem);
                }

                SrgsItem phraseSrgsItem = new SrgsItem();
                phraseSrgsItem.Add(new SrgsItem(0, 1, "Wybierz"));
                phraseSrgsItem.Add(seatSrgsOneOf);

                seatSrgsRule = new SrgsRule("seat", phraseSrgsItem);
            }

            rules.Add(seatSrgsRule);

            {
                SrgsItem srgsItem = new SrgsItem();
                srgsItem.Add(new SrgsRuleRef(seatSrgsRule));

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
Beispiel #32
0
        public void initialize(Action_Library2 new_grammar)
        {
            try
            {
                grammar = new_grammar;
                SrgsRule rule = grammar.Get_Rule("pages");
                foreach (SrgsElement element in rule.Elements)
                {
                    if (element.GetType() == typeof(SrgsOneOf))
                    {
                        choices = (SrgsOneOf)element;
                        break;
                    }
                }

                if (choices == null)
                {
                    choices = new SrgsOneOf();
                    rule.Add(choices);
                }

                pages.Clear();
                choices.Items.Clear();
                if (!File.Exists("web_pages.txt"))
                {
                    initialize_page("google", "http://www.google.com");
                }
                else
                {
                    string[] lines = File.ReadAllLines("web_pages.txt");
                    foreach (string line in lines)
                    {
                        string[] info = System.Text.RegularExpressions.Regex.Split(line, @"\s*,\s*");
                        initialize_page(info[0], info[1]);
                    }
                }

                grammar.Update();
            }
            catch
            {
            }
        }
Beispiel #33
0
        private void AddRowSpeechGrammarRules(SrgsRulesCollection rules)
        {
            SrgsRule rowSrgsRule;

            {
                SrgsOneOf rowSrgsOneOf = new SrgsOneOf();

                List <int> rows = new List <int>();

                foreach (Seat seat in GetSeats())
                {
                    if (!rows.Contains(seat.Row))
                    {
                        rows.Add(seat.Row);
                    }
                }

                foreach (int row in rows)
                {
                    SrgsItem srgsItem = new SrgsItem("Rząd " + row);
                    srgsItem.Add(new SrgsSemanticInterpretationTag("out=\"row." + row + "\";"));

                    rowSrgsOneOf.Add(srgsItem);
                }

                SrgsItem phraseSrgsItem = new SrgsItem();
                phraseSrgsItem.Add(new SrgsItem(0, 1, "Wybierz"));
                phraseSrgsItem.Add(rowSrgsOneOf);

                rowSrgsRule = new SrgsRule("row", phraseSrgsItem);
            }

            rules.Add(rowSrgsRule);

            {
                SrgsItem srgsItem = new SrgsItem();
                srgsItem.Add(new SrgsRuleRef(rowSrgsRule));

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
        public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs)
        {
            var letters = new SrgsOneOf();
            foreach (var dataPair in this.letters)
            {
                letters.Add(new SrgsItem(
                    new SrgsSemanticInterpretationTag(string.Format("out = '{0}'", dataPair.Value)),
                    new SrgsToken(dataPair.Key)
                ));
            }

            var letterRule = new SrgsRule("Letter", letters);
            refs["Letter"] = new SrgsRuleRef(letterRule);

            return new Tuple<SrgsRuleRef, IList<SrgsRule>>(
                null,
                new List<SrgsRule> { letterRule }
            );
        }
Beispiel #35
0
        private void GenerateRuleList()
        {
            RuleList = new List<SrgsRule>();

            SrgsOneOf directObject = new SrgsOneOf();

            foreach(directObjectEntry entry in entries)
            {
                SrgsItem item = GetNewNode(entry.alternates, entry.semantic);
                directObject.Add(item);
            }

            RuleList = new List<SrgsRule>();
            SrgsRule rule = new SrgsRule(RuleName);
            rule.Add(directObject);

            RuleRef = new SrgsRuleRef(rule);

            RuleList.Add(rule);
            RootRule = rule;
        }
Beispiel #36
0
 public override void Invoke()
 {
     if (grammars.ContainsKey(name))
     {
         var other = grammars[name];
         Program.se.UnloadAllGrammars();
         grammars2.Remove(other.grammar);
         grammars.Remove(other.name);
     }
     var doc = new SrgsDocument(new XmlTextReader(new MemoryStream(Properties.Resources.numbers)));
     var alt = new SrgsOneOf();
     foreach (var rule in rules)
         alt.Add(new SrgsItem(new SrgsElement[] { rule.Value.Build(doc), new SrgsNameValueTag(rule.Key) }));
     var root = new SrgsRule(Program.InternalMarker + "root", alt);
     doc.Rules.Add(root);
     doc.Root = root;
     doc.Debug = true;
     grammar = new Grammar(doc);
     grammars.Add(name, this);
     grammars2.Add(grammar, this);
     Console.WriteLine("Created grammar " + name);
 }
Beispiel #37
0
        private void GenerateRuleList()
        {
            RuleList = new List <SrgsRule>();

            SrgsOneOf directObject = new SrgsOneOf();

            foreach (directObjectEntry entry in entries)
            {
                SrgsItem item = GetNewNode(entry.alternates, entry.semantic);
                directObject.Add(item);
            }

            RuleList = new List <SrgsRule>();
            SrgsRule rule = new SrgsRule(RuleName);

            rule.Add(directObject);

            RuleRef = new SrgsRuleRef(rule);

            RuleList.Add(rule);
            RootRule = rule;
        }
        private void AddGenresSpeechGrammarRulers(SrgsRulesCollection srgsRules)
        {
            SrgsRule genreSrgsRule;

            {
                SrgsOneOf genreSrgsOneOf = new SrgsOneOf();

                int i = 0;
                foreach (Genre genre in GetGenres())
                {
                    SrgsItem srgsItem = new SrgsItem(genre.Name);
                    srgsItem.Add(new SrgsSemanticInterpretationTag("out=\"search.genres." + i++ + "\";"));

                    genreSrgsOneOf.Add(srgsItem);
                }

                SrgsItem genreSrgsItem = new SrgsItem("Wybierz");
                genreSrgsItem.Add(new SrgsItem(0, 1, "gatunek"));

                SrgsItem phraseSrgsItem = new SrgsItem();
                phraseSrgsItem.Add(genreSrgsItem);
                phraseSrgsItem.Add(genreSrgsOneOf);

                genreSrgsRule = new SrgsRule("genre", phraseSrgsItem);
            }

            srgsRules.Add(genreSrgsRule);

            {
                SrgsItem srgsItem = new SrgsItem();
                srgsItem.Add(new SrgsRuleRef(genreSrgsRule));

                SrgsRule  rootSrgsRule = srgsRules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
Beispiel #39
0
        protected override void AddCustomSpeechGrammarRules(SrgsRulesCollection rules)
        {
            SrgsRule movieSrgsRule;

            {
                SrgsOneOf movieSrgsOneOf = new SrgsOneOf();

                int i = 0;
                foreach (Movie movie in GetMovies())
                {
                    SrgsItem srgsItem = new SrgsItem(movie.Title);
                    srgsItem.Add(new SrgsSemanticInterpretationTag("out=\"movie." + i++ + "\";"));

                    movieSrgsOneOf.Add(srgsItem);
                }

                SrgsItem movieSrgsItem = new SrgsItem(0, 1, "Wybierz");
                movieSrgsItem.Add(new SrgsItem(0, 1, "film"));

                SrgsItem phraseSrgsItem = new SrgsItem();
                phraseSrgsItem.Add(movieSrgsItem);
                phraseSrgsItem.Add(movieSrgsOneOf);

                movieSrgsRule = new SrgsRule("movie", phraseSrgsItem);
            }

            rules.Add(movieSrgsRule);

            {
                SrgsItem srgsItem = new SrgsItem();
                srgsItem.Add(new SrgsRuleRef(movieSrgsRule));

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
        protected override void AddCustomSpeechGrammarRules(SrgsRulesCollection srgsRules)
        {
            SrgsRule ticketSrgsRule;

            {
                SrgsOneOf ticketSrgsOneOf = new SrgsOneOf();

                int i = 0;
                foreach (Price price in GetPrices())
                {
                    SrgsItem srgsItem = new SrgsItem(price.Description);
                    srgsItem.Add(new SrgsSemanticInterpretationTag("out=\"ticket." + i++ + "\";"));

                    ticketSrgsOneOf.Add(srgsItem);
                }

                SrgsItem ticketSrgsItem = new SrgsItem("Wybierz");
                ticketSrgsItem.Add(new SrgsItem(0, 1, "bilet"));

                SrgsItem phraseSrgsItem = new SrgsItem();
                phraseSrgsItem.Add(ticketSrgsItem);
                phraseSrgsItem.Add(ticketSrgsOneOf);

                ticketSrgsRule = new SrgsRule("ticket", phraseSrgsItem);
            }

            srgsRules.Add(ticketSrgsRule);

            {
                SrgsItem srgsItem = new SrgsItem();
                srgsItem.Add(new SrgsRuleRef(ticketSrgsRule));

                SrgsRule  rootSrgsRule = srgsRules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
Beispiel #41
0
        public override void Init()
        {
            grammar = Program.speech.vocabularies["web_browser"];
            SrgsRule rule = grammar.Get_Rule("pages");

            foreach (SrgsElement element in rule.Elements)
            {
                if (element.GetType() == typeof(SrgsOneOf))
                {
                    choices = (SrgsOneOf)element;
                    break;
                }
            }

            if (choices == null)
            {
                choices = new SrgsOneOf();
                rule.Add(choices);
            }

            if (!File.Exists("web_pages.txt"))
            {
                initialize_page("google", "http://www.google.com");
            }
            else
            {
                string[] lines = File.ReadAllLines("web_pages.txt");
                foreach (string line in lines)
                {
                    string[] info = System.Text.RegularExpressions.Regex.Split(line, @"\s*,\s*");
                    initialize_page(info[0], info[1]);
                }
            }

            grammar.Update();
        }
Beispiel #42
0
 SrgsRuleRef SrgsActionsFromCapabilities(DeviceCapabilities caps, SrgsDocument doc)
 {
     SrgsRule r;
     if (caps_rules.Keys.Contains(caps.Caps))
     {
         r = caps_rules[caps.Caps];
     }
     else
     {
         List<string> capsAsString = caps.Actions;
         if (capsAsString == null || capsAsString.Count == 0) return null;
         SrgsOneOf actions = new SrgsOneOf();
         foreach (string s in capsAsString)
         {
             SrgsItem si = new SrgsItem(s);
             //si.Add(new SrgsSemanticInterpretationTag(" out = \"" + s + "\";"));
             si.Add(new SrgsNameValueTag("action", s));
             actions.Add(si);
         }
         r = new SrgsRule(AudioRecog_SAPI.SrgsCleanupID("caps_" + caps.CapsAsIntString), actions);
         doc.Rules.Add(r);
         caps_rules.Add(caps.Caps, r);
     }
     //return new SrgsRuleRef(r, "action");
     return new SrgsRuleRef(r);
 }
Beispiel #43
0
        public SrgsDocument CreateGrammarDoc_SRGS()
        {
            //reset caches
            caps_rules = new Dictionary<EDeviceCapabilities, SrgsRule>();
            if (currentSrgsDoc == null)
            {

                currentSrgsDoc = new SrgsDocument();

                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
                //Grammar: Holly, [<courtesy>] <action> (<class>|<device>) [<location>] <courtesy>
                // Courtesy: Please, Thank You, Thanks, Cheers
                // Action: capabilities
                // Class: classes
                // Device: device friendly names
                // Location: rooms, here, this

                SrgsOneOf end_courtesy = new SrgsOneOf(new string[] { "please" });
                SrgsOneOf actionItemLocation_choices = new SrgsOneOf();
                foreach (Room rm in ListRooms())
                {
                    if (rm.Name == "") continue;
                    Dictionary<string, SrgsRuleRef> actionsPerDevice = new Dictionary<string, SrgsRuleRef>();
                    foreach (Device d in rm.ListDevices())
                    {
                        SrgsRuleRef caps_ruleref = SrgsActionsFromCapabilities(d.Capabilities, currentSrgsDoc);
                        if (caps_ruleref == null) continue;
                        string cl = SoundsLike.Get(d.Class, false);
                        if (cl != "" && !actionsPerDevice.ContainsKey(cl))
                        {
                            actionsPerDevice.Add(cl, caps_ruleref);
                        }
                        if (d.FriendlyName != "")
                        {
                            if (!actionsPerDevice.ContainsKey(d.FriendlyName))
                                actionsPerDevice.Add(d.FriendlyName, caps_ruleref);
                        }
                    }
                    //actionsperdevice.Value + actionsperdevice.Key+room
                    if (actionsPerDevice.Count == 0) continue; //nothing in the room
                    SrgsOneOf action_items = new SrgsOneOf();
                    bool action_items_valid = false;
                    foreach (string item in actionsPerDevice.Keys)
                    {
                        if (item == "") continue;
                        SrgsRule ai_gb = new SrgsRule(AudioRecog_SAPI.SrgsCleanupID(rm.Name + "_" + item));
                        ai_gb.Add(actionsPerDevice[item]);
                        ai_gb.Add(new SrgsItem(item));
                        currentSrgsDoc.Rules.Add(ai_gb);
                        //SrgsItem ai_gb_item = new SrgsItem(new SrgsRuleRef(ai_gb, "item"));
                        SrgsItem ai_gb_item = new SrgsItem(new SrgsRuleRef(ai_gb));
                        ai_gb_item.Add(new SrgsNameValueTag("item", item));
                        action_items.Add(ai_gb_item);
                        action_items_valid = true;
                    }
                    if (!action_items_valid) continue;
                    SrgsRule ail_gb = new SrgsRule(AudioRecog_SAPI.SrgsCleanupID(rm.Name + "__ail"), action_items);
                    if (rm != CurrentLocation)
                    {
                        //SrgsItem loc1 = new SrgsItem("in the " + rm.Name);
                        SrgsItem loc1 = new SrgsItem(0, 1, "in the " + rm.Name);
                        loc1.Add(new SrgsNameValueTag("room", rm.Name));
                        ail_gb.Add(loc1);
                    }
                    else
                    {
                        SrgsOneOf loc = new SrgsOneOf(new string[] { "in the " + rm.Name, "here" });
                        SrgsItem loc_item = new SrgsItem(0, 1, loc);
                        //SrgsItem loc_item = new SrgsItem(loc);
                        loc_item.Add(new SrgsNameValueTag("room", rm.Name));
                        ail_gb.Add(loc_item);
                    }
                    currentSrgsDoc.Rules.Add(ail_gb);
                    //SrgsItem ail_gb_item = new SrgsItem(new SrgsRuleRef(ail_gb, "room"));
                    SrgsItem ail_gb_item = new SrgsItem(new SrgsRuleRef(ail_gb));
                    //ail_gb_item.Add(new SrgsNameValueTag("room", rm.Name));
                    actionItemLocation_choices.Add(ail_gb_item);
                }
                SrgsRule root_rule = new SrgsRule("rootrule");
                root_rule.Add(new SrgsItem("Holly"));
                root_rule.Add(actionItemLocation_choices);
                root_rule.Add(end_courtesy);
                currentSrgsDoc.Rules.Add(root_rule);
                currentSrgsDoc.Root = root_rule;

                XmlWriter xmlout = XmlWriter.Create(@"C:\Users\ian\Desktop\grammar.xml");
                currentSrgsDoc.WriteSrgs(xmlout);
                xmlout.Close();
            }
            return currentSrgsDoc;
        }
Beispiel #44
0
        public System.Speech.Recognition.SrgsGrammar.SrgsDocument CreateGrammarDoc_SRGS()
        {
            if (currentSrgsDoc != null) return currentSrgsDoc;

            SrgsDocument doc = new SrgsDocument();
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
            SrgsOneOf ops = new SrgsOneOf();

            //TV Shows
            SrgsOneOf shows = new SrgsOneOf();
            if (mTVShows == null)
            {
                mTVShows = ListTVShows();
            }
            if (mTVShows == null) return null;
            foreach (XBMCProto.TVShow s in mTVShows)
            {
                string temps = CleanString(s.label);
                temps = temps.Trim();
                if (temps == "" || s.tvshowid < 1) continue;
                SrgsItem showitem = new SrgsItem(temps);
                showitem.Add(new SrgsNameValueTag("tvshowid", s.tvshowid));
                shows.Add(showitem);
            }

            SrgsItem cmd_play = new SrgsItem("play show");
            cmd_play.Add(new SrgsNameValueTag("command", "play show"));
            SrgsItem cmd_resume = new SrgsItem("resume show");
            cmd_resume.Add(new SrgsNameValueTag("command", "resume show"));
            SrgsOneOf cmd_tv = new SrgsOneOf(cmd_play, cmd_resume);

            SrgsRule rule_playshow_episode = new SrgsRule("playshow_episode");
            rule_playshow_episode.Add(cmd_tv);
            rule_playshow_episode.Add(shows);
            rule_playshow_episode.Add(new SrgsItem("season"));
            rule_playshow_episode.Add(CreateNumberSRGS("seasonval", doc));  //episode number
            rule_playshow_episode.Add(new SrgsItem("episode"));
            rule_playshow_episode.Add(CreateNumberSRGS("episodeval", doc));   //episode number
            doc.Rules.Add(rule_playshow_episode);
            ops.Add(new SrgsItem(new SrgsRuleRef(rule_playshow_episode)));

            //Movies
            SrgsOneOf films = new SrgsOneOf();
            if (mMovies == null)
            {
                mMovies = ListMovies();
            }
            if (mMovies == null) return null;
            foreach (XBMCProto.Movie m in mMovies)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.movieid < 1) continue;
                SrgsItem filmItem = new SrgsItem(temps);
                filmItem.Add(new SrgsNameValueTag("movieid", m.movieid));
                films.Add(filmItem);
            }

            SrgsItem cmd_play_movie = new SrgsItem("play movie");
            cmd_play_movie.Add(new SrgsNameValueTag("command", "play movie"));
            SrgsItem cmd_resume_movie = new SrgsItem("resume movie");
            cmd_resume_movie.Add(new SrgsNameValueTag("command", "resume movie"));
            SrgsOneOf cmd_movie = new SrgsOneOf(cmd_play_movie, cmd_resume_movie);

            SrgsRule rule_playmovie = new SrgsRule("playmovie");
            rule_playmovie.Add(cmd_movie);
            rule_playmovie.Add(films);
            doc.Rules.Add(rule_playmovie);
            ops.Add(new SrgsItem(new SrgsRuleRef(rule_playmovie)));

            //Music Genres
            SrgsOneOf audioGenres = new SrgsOneOf();
            if (mGenres == null)
            {
                mGenres = ListAudioGenres();
            }
            if (mGenres == null) return null;
            foreach (XBMCProto.Genre m in mGenres)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.genreid < 1) continue;
                SrgsItem agItem = new SrgsItem(temps+" music");
                agItem.Add(new SrgsNameValueTag("genreid", m.genreid));
                audioGenres.Add(agItem);
            }

            SrgsItem cmd_play_genre = new SrgsItem("play me some");
            cmd_play_genre.Add(new SrgsNameValueTag("command", "play me some"));
            SrgsOneOf cmd_genre = new SrgsOneOf(cmd_play_genre);

            SrgsRule rule_playgenre = new SrgsRule("playgenre");
            rule_playgenre.Add(cmd_genre);
            rule_playgenre.Add(audioGenres);
            doc.Rules.Add(rule_playgenre);
            ops.Add(new SrgsItem(new SrgsRuleRef(rule_playgenre)));

            //Other
            SrgsItem cmd_stop_media = new SrgsItem("stop media");
            cmd_stop_media.Add(new SrgsNameValueTag("command", "stop media"));
            SrgsItem cmd_pause_media = new SrgsItem("pause media");
            cmd_pause_media.Add(new SrgsNameValueTag("command", "pause media"));
            SrgsItem cmd_resume_media = new SrgsItem("resume media");
            cmd_resume_media.Add(new SrgsNameValueTag("command", "resume media"));
            ops.Add(new SrgsItem(cmd_stop_media));
            ops.Add(new SrgsItem(cmd_resume_media));
            ops.Add(new SrgsItem(cmd_pause_media));

            SrgsRule root_rule = new SrgsRule("rootrule");
            root_rule.Add(new SrgsItem("Holly"));
            root_rule.Add(ops);
            root_rule.Add(new SrgsItem("please"));
            doc.Rules.Add(root_rule);

            doc.Root = root_rule;

            XmlWriter xmlout = XmlWriter.Create(@"C:\Users\ian\Desktop\xbmc-grammar.xml");
            doc.WriteSrgs(xmlout);
            xmlout.Close();

            currentSrgsDoc = doc;
            return currentSrgsDoc;
        }
Beispiel #45
0
        public CMUSphinx_GrammarDict CreateGrammarDoc_FSG()
        {
            if (currentJSGFDoc != null) return currentJSGFDoc;
            CMUSphinx_GrammarDict ret = new CMUSphinx_GrammarDict();
            ret.GrammarName = GetName();

            CMUSphinx_FSGState root = ret.FSGCreate(ret.GrammarName);
            CMUSphinx_FSGState end = ret.FSGGetEndState();

            //numbers
            CMUSphinx_FSGState epNumsStart = ret.FSGCreateOrphanState();
            CMUSphinx_FSGState epNumsEnd = CreateNumberFSG(epNumsStart, ret);
            CMUSphinx_FSGState seasonNumsStart = ret.FSGCreateOrphanState();
            CMUSphinx_FSGState seasonNumsEnd = CreateNumberFSG(seasonNumsStart, ret);

            //TV Shows
            if (mTVShows == null)
            {
                mTVShows = ListTVShows();
            }
            if (mTVShows == null) return null;
            List<string> tvShowNames = new List<string>();
            foreach (XBMCProto.TVShow s in mTVShows)
            {
                string temps = CleanString(s.label);
                temps = temps.Trim();
                if (temps == "" || s.tvshowid < 1) continue;
                tvShowNames.Add(temps);
            }

            CMUSphinx_FSGState play = ret.FSGTransitionToNewState(root, "Holly play show");
            CMUSphinx_FSGState temp1 = ret.FSGTransitionToNewState(root, "Holly resume show");
            ret.FSGGroupStates(play, temp1);
            temp1 = ret.FSGCreateOrphanState();
            CMUSphinx_FSGState temp2;
            foreach (string s in tvShowNames)
            {
                temp2 = ret.FSGTransitionToNewState(play, s);
                ret.FSGGroupStates(temp1, temp2);
            }
            temp1 = ret.FSGTransitionToNewState(temp1, "season");
            temp1 = CreateNumberFSG(temp1, ret);
            temp1 = ret.FSGTransitionToNewState(temp1, "episode");
            temp1 = CreateNumberFSG(temp1, ret);
            temp1 = ret.FSGTransitionToNewState(temp1, "please");
            ret.FSGGroupStates(end, temp1);

            //Movies
            if (mMovies == null)
            {
                mMovies = ListMovies();
            }
            if (mMovies == null) return null;
            List<string> movieNames = new List<string>();
            foreach (XBMCProto.Movie m in mMovies)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.movieid < 1) continue;
                movieNames.Add(temps);
            }

            play = ret.FSGTransitionToNewState(root, "Holly play movie");
            temp1 = ret.FSGTransitionToNewState(root, "Holly resume movie");
            ret.FSGGroupStates(play, temp1);
            temp1 = ret.FSGCreateOrphanState();
            foreach (string s in movieNames)
            {
                temp2 = ret.FSGTransitionToNewState(play, s);
                ret.FSGGroupStates(temp1, temp2);
            }
            temp1 = ret.FSGTransitionToNewState(temp1, "please");
            ret.FSGGroupStates(end, temp1);

            //Music Genres
            SrgsOneOf audioGenres = new SrgsOneOf();
            if (mGenres == null)
            {
                mGenres = ListAudioGenres();
            }
            if (mGenres == null) return null;
            List<string> genreNames = new List<string>();
            foreach (XBMCProto.Genre m in mGenres)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.genreid < 1) continue;
                genreNames.Add(temps);
            }

            play = ret.FSGTransitionToNewState(root, "Holly play me some");
            temp1 = ret.FSGCreateOrphanState();
            foreach (string s in movieNames)
            {
                temp2 = ret.FSGTransitionToNewState(play, s);
                ret.FSGGroupStates(temp1, temp2);
            }
            temp1 = ret.FSGTransitionToNewState(temp1, "music please");
            ret.FSGGroupStates(end, temp1);

            //Other
            play = ret.FSGTransitionToNewState(root, "Holly stop media please");
            ret.FSGGroupStates(end, play);
            play = ret.FSGTransitionToNewState(root, "Holly pause media please");
            ret.FSGGroupStates(end, play);
            play = ret.FSGTransitionToNewState(root, "Holly resume media please");
            ret.FSGGroupStates(end, play);

            ret.BuildFSGGrammarAndDict();
            currentJSGFDoc = ret;
            return ret;
        }
        private SrgsRule GetDirectionRules()
        {
            SrgsRule directionRule = new SrgsRule("directionRule");
            usedRules.Add("directionRule", directionRule);

            List<String> oneTickNumberValues = mapping.GetNumberValues(1, 1);
            List<String> multipleTicksNumberValues = mapping.GetNumberValues(2, 9);
            List<String> directionValues = mapping.GetDirectionMappingValues();

            SrgsRule oneTickGrammarRule = GetDirectionRule(oneTickNumberValues, mapping.TickInputMapping, directionValues, "oneTickRule");
            SrgsRule multipleTicksGrammarRule = GetDirectionRule(multipleTicksNumberValues, mapping.TicksInputMapping, directionValues, "multipleTicksRule");

            SrgsRule oneTickNoBindingWordGrammarRule = GetDirectionRule(oneTickNumberValues, null, directionValues, "oneTickRuleNoBindingWord");
            SrgsRule multipleTicksNoBindingWordGrammarRule = GetDirectionRule(multipleTicksNumberValues, null, directionValues, "multipleTicksRuleNoBindingWord");

            SrgsOneOf oneOfElements = new SrgsOneOf(
                new SrgsItem(new SrgsRuleRef(oneTickGrammarRule)),
                new SrgsItem(new SrgsRuleRef(multipleTicksGrammarRule)),
                new SrgsItem(new SrgsRuleRef(oneTickNoBindingWordGrammarRule)),
                new SrgsItem(new SrgsRuleRef(multipleTicksNoBindingWordGrammarRule))
            );

            directionRule.Add(oneOfElements);

            return directionRule;
        }
Beispiel #47
0
        public static SrgsDocument BuildSrgsGrammar(CultureInfo cultureInfo)
        {
            SrgsDocument document = new SrgsDocument();

            document.Culture = cultureInfo;

            // make a new subject item and then add all of it's rules to the document
            subjectObject = new Subject();
            foreach (SrgsRule rule in subjectObject.RuleList)
            {
                document.Rules.Add(rule);
            }

            SrgsRuleRef subjectRef = new SrgsRuleRef(subjectObject.RootRule);

            // go through and add all of the commands
            commandObjects = new Dictionary <string, Command>();
            SrgsOneOf commandSet = new SrgsOneOf();

            // add just the subjects
            SrgsItem select = new SrgsItem();

            select.Add(new SrgsItem(subjectRef));
            select.Add(new SrgsSemanticInterpretationTag("out.subject=rules.subject;"));
            commandSet.Add(select);

            #region Commands
            #region Move (1)
            // return to formation (1)
            Command returnToFormation = new Command("FORMUP", new string[] { "return to formation", "form up", "fallback", "fall back", "regroup", "join up", "rally on me", "rally to me" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One), DirectInputEmulator.KeyPress(DirectInputKeys.One) }, subjectRef);
            commandObjects.Add("FORMUP", returnToFormation);
            commandSet.Add(returnToFormation.Item);

            // advance (2)
            Command advance = new Command("ADVANCE", new string[] { "advance", "move up" }, new[] { DirectInputEmulator.KeyPress(DirectInputKeys.One), DirectInputEmulator.KeyPress(DirectInputKeys.Two) }, subjectRef);
            commandObjects.Add("ADVANCE", advance);
            commandSet.Add(advance.Item);

            // stay back (3)
            Command stayBack = new Command("STAYBACK", new string[] { "stay back", "go back", "back up" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One), DirectInputEmulator.KeyPress(DirectInputKeys.Three) }, subjectRef);
            commandObjects.Add("STAYBACK", stayBack);
            commandSet.Add(stayBack.Item);

            // flank left (4)
            Command flankLeft = new Command("FLANKLEFT", new string[] { "flank left", "go left" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One), DirectInputEmulator.KeyPress(DirectInputKeys.Four) }, subjectRef);
            commandObjects.Add("FLANKLEFT", flankLeft);
            commandSet.Add(flankLeft.Item);

            // flank right (5)
            Command flankRight = new Command("FLANKRIGHT", new string[] { "flank right", "go right" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One), DirectInputEmulator.KeyPress(DirectInputKeys.Five) }, subjectRef);
            commandObjects.Add("FLANKRIGHT", flankRight);
            commandSet.Add(flankRight.Item);

            // stop (6)
            Command stop = new Command("STOP", new string[] { "stop", "hold position", "halt", "stay there", "stay here" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One), DirectInputEmulator.KeyPress(DirectInputKeys.Six) }, subjectRef);
            commandObjects.Add("STOP", stop);
            commandSet.Add(stop.Item);

            // Wait for me (7)
            Command waitForMe = new Command("WAIT", new string[] { "wait for me", "wait up", "wait" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One), DirectInputEmulator.KeyPress(DirectInputKeys.Seven) }, subjectRef);
            commandObjects.Add("WAIT", waitForMe);
            commandSet.Add(waitForMe.Item);

            // Find cover (8)
            Command cover = new Command("COVER", new string[] { "go for cover", "look for cover", "cover", "find cover", "get to cover", "hide" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One), DirectInputEmulator.KeyPress(DirectInputKeys.Eight) }, subjectRef);
            commandObjects.Add("COVER", cover);
            commandSet.Add(cover.Item);

            // Next waypoint (9)
            Command nextWaypoint = new Command("NEXTWAYPOINT", new string[] { "next waypoint", "go to the next waypoint" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One), DirectInputEmulator.KeyPress(DirectInputKeys.Nine) }, subjectRef);
            commandObjects.Add("NEXTWAYPOINT", nextWaypoint);
            commandSet.Add(nextWaypoint.Item);
            #endregion

            #region Target (2)
            // open menu
            Command openTargetMenu = new Command("OPENTARGET", new string[] { "show targets", "target menu", "open target menu", "targets" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Two) }, subjectRef);
            commandObjects.Add("OPENTARGET", openTargetMenu);
            commandSet.Add(openTargetMenu.Item);

            // cancel target (1)
            Command cancelTarget = new Command("CANCELTARGET", new string[] { "cancel target", "cancel targets", "no target" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Two), DirectInputEmulator.KeyPress(DirectInputKeys.One) }, subjectRef);
            commandObjects.Add("CANCELTARGET", cancelTarget);
            commandSet.Add(cancelTarget.Item);
            #endregion

            #region Engage (3)
            // open fire (1)
            Command openFire = new Command("OPENFIRE", new string[] { "open fire", "go loud", "fire at will" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three), DirectInputEmulator.KeyPress(DirectInputKeys.One) }, subjectRef);
            commandObjects.Add("OPENFIRE", openFire);
            commandSet.Add(openFire.Item);

            // hold fire (2)
            Command holdFire = new Command("HOLDFIRE", new string[] { "hold fire", "go quiet", "cease fire" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three), DirectInputEmulator.KeyPress(DirectInputKeys.Two) }, subjectRef);
            commandObjects.Add("HOLDFIRE", holdFire);
            commandSet.Add(holdFire.Item);

            // fire (3)
            Command fire = new Command("FIRE", new string[] { "fire", "take the shot" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three), DirectInputEmulator.KeyPress(DirectInputKeys.Three) }, subjectRef);
            commandObjects.Add("FIRE", fire);
            commandSet.Add(fire.Item);

            // engage (4)
            Command engage = new Command("ENGAGE", new string[] { "engage", "move to engage" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three), DirectInputEmulator.KeyPress(DirectInputKeys.Four) }, subjectRef);
            commandObjects.Add("ENGAGE", engage);
            commandSet.Add(engage.Item);

            // engage at will (5)
            Command enageAtWill = new Command("ENGAGEATWILL", new string[] { "engage at will" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three), DirectInputEmulator.KeyPress(DirectInputKeys.Five) }, subjectRef);
            commandObjects.Add("ENGAGEATWILL", enageAtWill);
            commandSet.Add(enageAtWill.Item);

            // disengage (6)
            Command disengage = new Command("DISENGAGE", new string[] { "disengage" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three), DirectInputEmulator.KeyPress(DirectInputKeys.Six) }, subjectRef);
            commandObjects.Add("DISENGAGE", disengage);
            commandSet.Add(disengage.Item);

            // scan horizon (7)
            Command scanHorizon = new Command("SCANHORIZON", new string[] { "scan horizon", "scan the horizon" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three), DirectInputEmulator.KeyPress(DirectInputKeys.Seven) }, subjectRef);
            commandObjects.Add("SCANHORIZON", scanHorizon);
            commandSet.Add(scanHorizon.Item);

            // watch direction (8)
            // team direct object
            DirectObject direction = new DirectObject("directionDO");
            direction.Add(new string[] { "north" }, "NORTH", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One) });
            direction.Add(new string[] { "north east" }, "NORTHEAST", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Two) });
            direction.Add(new string[] { "east" }, "EAST", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three) });
            direction.Add(new string[] { "south east" }, "SOUTHEAST", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Four) });
            direction.Add(new string[] { "south" }, "SOUTH", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Five) });
            direction.Add(new string[] { "south west" }, "SOUTHWEST", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Six) });
            direction.Add(new string[] { "west" }, "WEST", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Seven) });
            direction.Add(new string[] { "north west" }, "NORTHWEST", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight) });

            foreach (SrgsRule rule in direction.RuleList)
            {
                document.Rules.Add(rule);
            }

            Command watch = new Command("WATCH", new string[] { "watch", "watch the" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three), DirectInputEmulator.KeyPress(DirectInputKeys.Eight) }, subjectRef, direction);
            commandObjects.Add("WATCH", watch);
            commandSet.Add(watch.Item);

            // suppressive fire (9)
            Command suppresiveFire = new Command("SUPRESS", new string[] { "suppresive fire", "suppress" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three), DirectInputEmulator.KeyPress(DirectInputKeys.Nine) }, subjectRef);
            commandObjects.Add("SUPRESS", suppresiveFire);
            commandSet.Add(suppresiveFire.Item);
            #endregion

            #region Mount (4)
            // open mount menu
            Command openMountMenu = new Command("OPENMOUNT", new string[] { "show mount menu", "open mount menu", "show vehicles", "mount menu", "get in vehicle" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Four) }, subjectRef);
            commandObjects.Add("OPENMOUNT", openMountMenu);
            commandSet.Add(openMountMenu.Item);

            // dismount (1)
            Command dismount = new Command("DISMOUNT", new string[] { "dismount", "get out" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Four), DirectInputEmulator.KeyPress(DirectInputKeys.One) }, subjectRef);
            commandObjects.Add("DISMOUNT", dismount);
            commandSet.Add(dismount.Item);
            #endregion

            #region Action (6)
            // open menu
            Command openActionMenu = new Command("OPENACTION", new string[] { "show actions", "action menu", "perform action", "do action", "open action menu", "actions" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Six) }, subjectRef);
            commandObjects.Add("OPENACTION", openActionMenu);
            commandSet.Add(openActionMenu.Item);
            #endregion

            #region Combat Mode (7)
            // stealth (1)
            Command stealth = new Command("STEALTH", new string[] { "stealth", "stealthy", "stealth mode" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Seven), DirectInputEmulator.KeyPress(DirectInputKeys.One) }, subjectRef);
            commandObjects.Add("STEALTH", stealth);
            commandSet.Add(stealth.Item);

            // combat (2)
            Command combat = new Command("COMBAT", new string[] { "combat", "danger", "combat mode" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Seven), DirectInputEmulator.KeyPress(DirectInputKeys.Two) }, subjectRef);
            commandObjects.Add("COMBAT", combat);
            commandSet.Add(combat.Item);

            // aware (3)
            Command aware = new Command("AWARE", new string[] { "aware", "alert", "aware mode", "stay sharp", "stay frosty", "stay alert" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Seven), DirectInputEmulator.KeyPress(DirectInputKeys.Three) }, subjectRef);
            commandObjects.Add("AWARE", aware);
            commandSet.Add(aware.Item);

            // relax (4)
            Command relax = new Command("RELAX", new string[] { "relax", "relaxed mode", "safe" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Seven), DirectInputEmulator.KeyPress(DirectInputKeys.Four) }, subjectRef);
            commandObjects.Add("RELAX", relax);
            commandSet.Add(relax.Item);

            // stand up (6)
            Command standUp = new Command("STANDUP", new string[] { "stand up", "get up", "stand" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Seven), DirectInputEmulator.KeyPress(DirectInputKeys.Six) }, subjectRef);
            commandObjects.Add("STANDUP", standUp);
            commandSet.Add(standUp.Item);

            // stay crouched (7)
            Command stayCrouched = new Command("CROUCH", new string[] { "get low", "crouch", "stay crouched", "stay low" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Seven), DirectInputEmulator.KeyPress(DirectInputKeys.Seven) }, subjectRef);
            commandObjects.Add("CROUCH", stayCrouched);
            commandSet.Add(stayCrouched.Item);

            // go prone (8)
            Command goProne = new Command("PRONE", new string[] { "go prone", "get down", "prone", "hit the dirt", "down" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Seven), DirectInputEmulator.KeyPress(DirectInputKeys.Eight) }, subjectRef);
            commandObjects.Add("PRONE", goProne);
            commandSet.Add(goProne.Item);

            // copy my stance (9)
            Command copyMyStance = new Command("COPYMYSTANCE", new string[] { "copy my stance", "default stance" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Seven), DirectInputEmulator.KeyPress(DirectInputKeys.Nine) }, subjectRef);
            commandObjects.Add("COPYMYSTANCE", copyMyStance);
            commandSet.Add(copyMyStance.Item);
            #endregion

            #region Formation (8)
            // column (1)
            Command column = new Command("COLUMN", new string[] { "formation column", "form column" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight), DirectInputEmulator.KeyPress(DirectInputKeys.One) }, subjectRef);
            commandObjects.Add("COLUMN", column);
            commandSet.Add(column.Item);

            // staggered column (2)
            Command staggeredColumn = new Command("STAGGEREDCOLUMN", new string[] { "formation staggered column", "form staggered column" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight), DirectInputEmulator.KeyPress(DirectInputKeys.Two) }, subjectRef);
            commandObjects.Add("STAGGEREDCOLUMN", staggeredColumn);
            commandSet.Add(staggeredColumn.Item);

            // wedge (3)
            Command wedge = new Command("WEDGE", new string[] { "formation wedge", "form wedge" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight), DirectInputEmulator.KeyPress(DirectInputKeys.Three) }, subjectRef);
            commandObjects.Add("WEDGE", wedge);
            commandSet.Add(wedge.Item);

            // echelon left (4)
            Command echelonLeft = new Command("ECHELONLEFT", new string[] { "formation echelon left", "form echelon left" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight), DirectInputEmulator.KeyPress(DirectInputKeys.Four) }, subjectRef);
            commandObjects.Add("ECHELONLEFT", echelonLeft);
            commandSet.Add(echelonLeft.Item);

            // echelon right (5)
            Command echeloneRight = new Command("ECHELONRIGHT", new string[] { "formation echelon right", "form echelon right" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight), DirectInputEmulator.KeyPress(DirectInputKeys.Five) }, subjectRef);
            commandObjects.Add("ECHELONRIGHT", echeloneRight);
            commandSet.Add(echeloneRight.Item);

            // vee (6)
            Command vee = new Command("VEE", new string[] { "formation vee", "form vee" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight), DirectInputEmulator.KeyPress(DirectInputKeys.Six) }, subjectRef);
            commandObjects.Add("VEE", vee);
            commandSet.Add(vee.Item);

            // line (7)
            Command line = new Command("LINE", new string[] { "formation line", "form line" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight), DirectInputEmulator.KeyPress(DirectInputKeys.Seven) }, subjectRef);
            commandObjects.Add("LINE", line);
            commandSet.Add(line.Item);

            // file (8)
            Command file = new Command("FILE", new string[] { "formation file", "form file" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight), DirectInputEmulator.KeyPress(DirectInputKeys.Eight) }, subjectRef);
            commandObjects.Add("FILE", file);
            commandSet.Add(file.Item);

            // diamond (9)
            Command diamond = new Command("DIAMOND", new string[] { "formation diamond", "form diamond" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Eight), DirectInputEmulator.KeyPress(DirectInputKeys.Nine) }, subjectRef);
            commandObjects.Add("DIAMOND", diamond);
            commandSet.Add(diamond.Item);
            #endregion

            #region Assign Team (9)
            // team direct object
            DirectObject team = new DirectObject("teamDO");
            team.Add(new string[] { "team red", "red" }, "RED", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.One) });
            team.Add(new string[] { "team green", "green" }, "GREEN", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Two) });
            team.Add(new string[] { "team blue", "blue" }, "BLUE", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Three) });
            team.Add(new string[] { "team yellow", "yellow" }, "YELLOW", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Four) });
            team.Add(new string[] { "team white", "white" }, "WHITE", new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Five) });

            foreach (SrgsRule rule in team.RuleList)
            {
                document.Rules.Add(rule);
            }

            Command assignTeam = new Command("ASSIGN", new string[] { "assign", "assign to", "add to", "switch to" }, new [] { DirectInputEmulator.KeyPress(DirectInputKeys.Nine) }, subjectRef, team);
            commandObjects.Add("ASSIGN", assignTeam);
            commandSet.Add(assignTeam.Item);
            #endregion

            // not implemented
            #region WW_AiMenu
            #region Infantry Commands (1)
            // heal up (1)

            // rearm (2)

            // inventory (3)

            // fire on my lead (4)

            // garrison building (5)

            // clear building (6)

            // follow target (7)
            #endregion

            #region WayPoints (4)
            // set waypoints (1)

            // add waypoints (2)

            // move waypoints (3)

            // delete waypoints (4)

            // wait on waypoint (5)

            // cycle waypoint (6)
            #endregion
            #endregion
            #endregion

            // set the root rule to
            SrgsRule commands = new SrgsRule("commands");
            commands.Add(commandSet);

            document.Rules.Add(commands);
            document.Root = commands;

            return(document);
        }
        private Grammar init()
        {
            SrgsRule  ruleOrzeczenie = new SrgsRule("Orzeczenie");
            SrgsOneOf orzeczenie     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(0, 1, "chciałbym"),
                new SrgsItem(0, 1, "daj"),
                new SrgsItem(0, 1, "dawaj"),
                new SrgsItem(0, 1, "podaj"),
                new SrgsItem(0, 1, "poproszę"),
                new SrgsItem(0, 1, "proszę"),
                new SrgsItem(0, 1, "sprzedaj")
            });

            ruleOrzeczenie.Add(orzeczenie);

            SrgsRule  ruleBezokolicznik = new SrgsRule("Bezokolicznik");
            SrgsOneOf bezokolicznik     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(0, 1, "dostać"),
                new SrgsItem(0, 1, "kupić"),
                new SrgsItem(0, 1, "podać"),
                new SrgsItem(0, 1, "wziąć")
            });

            ruleBezokolicznik.Add(bezokolicznik);

            SrgsRule ruleDopelnienie = new SrgsRule("Dopelnienie");
            string   guitarItem      = "gitarę";
            string   drumsItem       = "perkusję";
            string   violinItem      = "skrzypce";
            string   bellsItem       = "dzwoneczki";
            string   bassItem        = "bas";

            productIdGrammarDictionary.Add(1, guitarItem);
            productIdGrammarDictionary.Add(2, drumsItem);
            productIdGrammarDictionary.Add(3, violinItem);
            productIdGrammarDictionary.Add(4, bellsItem);
            productIdGrammarDictionary.Add(5, bassItem);

            SrgsOneOf dopelnienie = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, guitarItem),
                new SrgsItem(1, 1, drumsItem),
                new SrgsItem(1, 1, violinItem),
                new SrgsItem(1, 1, bellsItem),
                new SrgsItem(1, 1, bassItem)
            });

            ruleDopelnienie.Add(dopelnienie);
            SrgsRule rootRule = new SrgsRule("rootBiletomat");

            rootRule.Scope = SrgsRuleScope.Public;
            rootRule.Add(new SrgsRuleRef(ruleOrzeczenie, "ORZECZENIE"));
            rootRule.Add(new SrgsRuleRef(ruleBezokolicznik, "BEZOKOLICZNIK"));
            rootRule.Add(new SrgsRuleRef(ruleDopelnienie, "DOPELNIENIE"));

            SrgsDocument docBiletomat = new SrgsDocument();

            docBiletomat.Culture = pRecognitionLanguage;

            docBiletomat.Rules.Add(new SrgsRule[]
                                   { rootRule, ruleOrzeczenie, ruleBezokolicznik, ruleDopelnienie }
                                   );

            docBiletomat.Root = rootRule;

            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("srgsDocument.xml");
            docBiletomat.WriteSrgs(writer);
            writer.Close();
            return(new Grammar(docBiletomat, "rootBiletomat"));
        }
Beispiel #49
0
        protected override SrgsRule[] GetGrammarRules()
        {
            var srgsRuleArtist = new SrgsRule("artist");
            var srgsItemArtist = new SrgsItem(0, 1);
            var srgsOneOfArtist = new SrgsOneOf();
            srgsItemArtist.Add(srgsOneOfArtist);
            srgsRuleArtist.Add(srgsItemArtist);

            var srgsRuleAlbum = new SrgsRule("album");
            var srgsItemAlbum = new SrgsItem(0, 1);
            var srgsOneOfAlbum = new SrgsOneOf();
            srgsItemAlbum.Add(srgsOneOfAlbum);
            srgsRuleAlbum.Add(srgsItemAlbum);

            var srgsRuleTitle = new SrgsRule("title");
            var srgsItemTitle = new SrgsItem(0, 1);
            var srgsOneOfTitle = new SrgsOneOf();
            srgsItemTitle.Add(srgsOneOfTitle);
            srgsRuleTitle.Add(srgsItemTitle);

            var srgsRuleMusic = new SrgsRule("musicPlay");
            srgsRuleMusic.Add(new SrgsItem("reproducí"));
            srgsRuleMusic.Add(SrgsRuleRef.Garbage);
            srgsRuleMusic.Add(new SrgsRuleRef(srgsRuleArtist));
            srgsRuleMusic.Add(SrgsRuleRef.Garbage);
            srgsRuleMusic.Add(new SrgsRuleRef(srgsRuleAlbum));
            srgsRuleMusic.Add(SrgsRuleRef.Garbage);
            srgsRuleMusic.Add(new SrgsRuleRef(srgsRuleTitle));
            srgsRuleMusic.Add(new SrgsSemanticInterpretationTag("out.artist = rules.artist; out.album = rules.album; out.title = rules.title"));

            var mediaList = Player.mediaCollection.getByAttribute("MediaType", "audio");
            for (var i = 0; i < mediaList.count; i++)
            {
                var item = mediaList.Item[i];

                var author = item.getItemInfo("author");
                var album = item.getItemInfo("album");
                var title = item.getItemInfo("title");

                if (!String.IsNullOrWhiteSpace(author))
                {
                    try
                    {
                        var srgsAuthorItem = new SrgsItem(author);
                        srgsOneOfArtist.Add(srgsAuthorItem);
                    }
                    catch (FormatException exception)
                    {
                        Log.Info(string.Format("the author can't be parsed: {0}", exception));
                    }
                }

                if (!String.IsNullOrWhiteSpace(album))
                {
                    try
                    {
                        var srgsAlbumItem = new SrgsItem(album);
                        srgsOneOfAlbum.Add(srgsAlbumItem);
                    }
                    catch (FormatException exception)
                    {
                        Log.Info(string.Format("the album can't be parsed: {0}", exception));
                    }
                }

                if (!String.IsNullOrWhiteSpace(title))
                {
                    try
                    {
                        var srgsTitleItem = new SrgsItem(title);
                        srgsOneOfTitle.Add(srgsTitleItem);
                    }
                    catch (FormatException exception)
                    {
                        Log.Info(string.Format("the title of the song can't be parsed: {0}", exception));
                    }
                }
            }

            if (srgsOneOfArtist.Items.Count > 0 || srgsOneOfAlbum.Items.Count > 0 || srgsOneOfTitle.Items.Count > 0)
            {
                return new[] { srgsRuleAlbum, srgsRuleArtist, srgsRuleMusic, srgsRuleTitle };
            }

            return new SrgsRule[0];
        }
Beispiel #50
0
        private void GenerateRuleList()
        {
            RuleList = new List<SrgsRule>();

            // SQUAD SELECTION
            SrgsItem one = GetNewNode(new string[] {"one"}, "ONE");
            SrgsItem two = GetNewNode(new string[] { "two" }, "TWO");
            SrgsItem three = GetNewNode(new string[] { "three" }, "THREE");
            SrgsItem four = GetNewNode(new string[] { "four" }, "FOUR");
            SrgsItem five = GetNewNode(new string[] { "five" }, "FIVE");
            SrgsItem six = GetNewNode(new string[] { "six" }, "SIX");
            SrgsItem seven = GetNewNode(new string[] { "seven" }, "SEVEN");
            SrgsItem eight = GetNewNode(new string[] { "eight" }, "EIGHT");
            SrgsItem nine = GetNewNode(new string[] { "nine" }, "NINE");
            SrgsItem ten = GetNewNode(new string[] { "ten" }, "TEN");
            SrgsItem eleven = GetNewNode(new string[] { "eleven" }, "ELEVEN");
            SrgsItem twelve = GetNewNode(new string[] { "twelve" }, "TWELVE");

            SrgsOneOf squadNumbersChoice = new SrgsOneOf(one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve);
            SrgsItem squadNumbersConcatChoice = new SrgsItem(squadNumbersChoice, new SrgsItem(0, 1, "and"));
            squadNumbersConcatChoice.SetRepeat(1, 12);
            SrgsRule squadNumbers = new SrgsRule("squadNumbers");
            squadNumbers.Add(squadNumbersConcatChoice);
            RuleList.Add(squadNumbers);
            SrgsRule squadMembers = new SrgsRule("squadSelections");
            squadMembers.Add(new SrgsRuleRef(squadNumbers));
            squadMembers.Add(new SrgsSemanticInterpretationTag("out=rules.squadNumbers;"));
            RuleList.Add(squadMembers);

            // TEAM
            SrgsItem red = GetNewNode(new string[] { "red" }, "RED");
            SrgsItem yellow = GetNewNode(new string[] { "yellow" }, "YELLOW");
            SrgsItem white = GetNewNode(new string[] { "white" }, "WHITE");
            SrgsItem blue = GetNewNode(new string[] { "blue" }, "BLUE");
            SrgsItem green = GetNewNode(new string[] { "green" }, "GREEN");

            SrgsOneOf teamColorsChoice = new SrgsOneOf(blue, green, white, yellow, red);
            SrgsRule teamColors = new SrgsRule("teamColors");
            teamColors.Add(teamColorsChoice);
            RuleList.Add(teamColors);

            SrgsRule teams = new SrgsRule("teams");
            teams.Add(new SrgsItem("team"));
            teams.Add(new SrgsRuleRef(teamColors));
            teams.Add(new SrgsSemanticInterpretationTag("out=rules.teamColors;"));
            RuleList.Add(teams);

            // ALL
            SrgsItem allItems = GetNewNode(new string[] { "all", "everyone", "team", "squad" }, "ALL");
            SrgsRule all = new SrgsRule("all");
            all.Add(allItems);
            RuleList.Add(all);

            // ALL TOGETHER NOW
            SrgsOneOf subjectChoice = new SrgsOneOf();
            subjectChoice.Add(new SrgsItem(new SrgsRuleRef(teams)));
            subjectChoice.Add(new SrgsItem(new SrgsRuleRef(squadMembers)));
            subjectChoice.Add(new SrgsItem(new SrgsRuleRef(all)));

            SrgsRule subject = new SrgsRule("subject");
            subject.Add(subjectChoice);

            RootRule = subject;
            RuleList.Add(subject);
        }
Beispiel #51
0
        public System.Speech.Recognition.SrgsGrammar.SrgsDocument CreateGrammarDoc_SRGS()
        {
            if (currentSrgsDoc != null) return currentSrgsDoc;

            SrgsDocument doc = new SrgsDocument();
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");

            SrgsOneOf is_awake = new SrgsOneOf(new string[] { "i'm awake", "turn off the alarm", "i am awake"});

            SrgsRule root_rule = new SrgsRule("rootrule");
            root_rule.Add(new SrgsItem("Holly"));
            SrgsItem cmd = new SrgsItem(is_awake);
            cmd.Add(new SrgsNameValueTag("command", "turn off alarm"));
            root_rule.Add(cmd);
            root_rule.Add(new SrgsItem("please"));
            doc.Rules.Add(root_rule);
            doc.Root = root_rule;

            currentSrgsDoc = doc;
            return currentSrgsDoc;
        }
Beispiel #52
0
        private void LoadGrammarForEngineAndPlugins()
        {
            var memoryStream = new MemoryStream(Resources.mainDocument);
            var xmlReader = new XmlTextReader(memoryStream);
            var mainDocument = new SrgsDocument(xmlReader);

            //Rule for plugins
            var pluginRules = new SrgsRule("plugin");
            var choices = new SrgsOneOf();
            pluginRules.Add(choices);

            //Main rule (entry point for speech)
            var mainRule = new SrgsRule("main");
            var systemName = new SrgsItem(_config.SpeechRecognitionElement.Name);
            var speakAnything = SrgsRuleRef.Garbage;
            var refPluginRules = new SrgsRuleRef(pluginRules);
            SrgsItem executeCommandRule = null;
            if (!String.IsNullOrWhiteSpace(_config.SpeechRecognitionElement.ExecuteCommandPhrase))
                executeCommandRule = new SrgsItem(_config.SpeechRecognitionElement.ExecuteCommandPhrase);

            //Genere main Rule
            mainRule.Add(systemName);
            mainRule.Add(speakAnything);
            mainRule.Add(refPluginRules);
            mainRule.Add(new SrgsSemanticInterpretationTag("out=rules.plugin;"));
            mainRule.Add(speakAnything);
            if (!String.IsNullOrWhiteSpace(_config.SpeechRecognitionElement.ExecuteCommandPhrase))
                mainRule.Add(executeCommandRule);
            mainRule.Scope = SrgsRuleScope.Private;

            //Here you should add choices to the document per Plugin
            foreach (var plugin in _plugins)
            {
                plugin.AddGrammarRules(mainDocument.Rules, choices);
            }

            mainDocument.Rules.Add(mainRule);
            mainDocument.Rules.Add(pluginRules);
            mainDocument.Root = mainRule;
            mainDocument.Culture = _speechRecognitionEngine.RecognizerInfo.Culture;
            mainDocument.Mode = SrgsGrammarMode.Voice;
            mainDocument.PhoneticAlphabet = SrgsPhoneticAlphabet.Sapi;

            using (var textWriter = new StringWriter())
            {
                using (var xmlWriter = new XmlTextWriter(textWriter))
                {
                    mainDocument.WriteSrgs(xmlWriter);
                    _log.Info(String.Format("Grammar for the recognition engine in the culture {0}, is {1}", _speechRecognitionEngine.RecognizerInfo.Culture.TwoLetterISOLanguageName, textWriter));
                }
            }

            _speechRecognitionEngine.LoadGrammar(new Grammar(mainDocument));
        }
        private SrgsRule GetRuleFromList(List<String> list, String ruleName)
        {
            SrgsOneOf oneOfElements = new SrgsOneOf();
            foreach (String listEntry in list)
            {
                oneOfElements.Add(new SrgsItem(listEntry));
            }

            SrgsRule rule = new SrgsRule(ruleName, oneOfElements);
            usedRules.Add(ruleName, rule);

            return rule;
        }
Beispiel #54
0
        public static SrgsDocument BuildSrgsGrammar(CultureInfo cultureInfo)
        {
            SrgsDocument document = new SrgsDocument();
            document.Culture = cultureInfo;

            // make a new subject item and then add all of it's rules to the document
            subjectObject = new Subject();
            foreach(SrgsRule rule in subjectObject.RuleList)
            {
                document.Rules.Add(rule);
            }

            SrgsRuleRef subjectRef = new SrgsRuleRef(subjectObject.RootRule);

            // go through and add all of the commands
            commandObjects = new Dictionary<string, Command>();
            SrgsOneOf commandSet = new SrgsOneOf();

            // add just the subjects
            SrgsItem select = new SrgsItem();
            select.Add(new SrgsItem(subjectRef));
            select.Add(new SrgsSemanticInterpretationTag("out.subject=rules.subject;"));
            commandSet.Add(select);

            #region Commands
            #region Move (1)
            // return to formation (1)
            Command returnToFormation = new Command("FORMUP", new string[] { "return to formation", "form up", "fallback", "fall back", "regroup", "join up", "rally on me", "rally to me" }, new uint[] { Keys.One, Keys.One }, subjectRef);
            commandObjects.Add("FORMUP", returnToFormation);
            commandSet.Add(returnToFormation.Item);

            // advance (2)
            Command advance = new Command("ADVANCE", new string[] { "advance", "move up" }, new uint[] { Keys.One, Keys.Two }, subjectRef);
            commandObjects.Add("ADVANCE", advance);
            commandSet.Add(advance.Item);

            // stay back (3)
            Command stayBack = new Command("STAYBACK", new string[] { "stay back", "go back", "back up" }, new uint[] { Keys.One, Keys.Three }, subjectRef);
            commandObjects.Add("STAYBACK", stayBack);
            commandSet.Add(stayBack.Item);

            // flank left (4)
            Command flankLeft = new Command("FLANKLEFT", new string[] { "flank left", "go left" }, new uint[] { Keys.One, Keys.Four }, subjectRef);
            commandObjects.Add("FLANKLEFT", flankLeft);
            commandSet.Add(flankLeft.Item);

            // flank right (5)
            Command flankRight = new Command("FLANKRIGHT", new string[] { "flank right", "go right" }, new uint[] { Keys.One, Keys.Five }, subjectRef);
            commandObjects.Add("FLANKRIGHT", flankRight);
            commandSet.Add(flankRight.Item);

            // stop (6)
            Command stop = new Command("STOP", new string[] { "stop", "hold position", "halt", "stay there", "stay here" }, new uint[] { Keys.One, Keys.Six }, subjectRef);
            commandObjects.Add("STOP", stop);
            commandSet.Add(stop.Item);

            // Wait for me (7)
            Command waitForMe = new Command("WAIT", new string[] { "wait for me", "wait up", "wait" }, new uint[] { Keys.One, Keys.Seven }, subjectRef);
            commandObjects.Add("WAIT", waitForMe);
            commandSet.Add(waitForMe.Item);

            // Find cover (8)
            Command cover = new Command("COVER", new string[] { "go for cover", "look for cover", "cover", "find cover", "get to cover", "hide" }, new uint[] { Keys.One, Keys.Eight }, subjectRef);
            commandObjects.Add("COVER", cover);
            commandSet.Add(cover.Item);

            // Next waypoint (9)
            Command nextWaypoint = new Command("NEXTWAYPOINT", new string[] { "next waypoint", "go to the next waypoint" }, new uint[] { Keys.One, Keys.Nine }, subjectRef);
            commandObjects.Add("NEXTWAYPOINT", nextWaypoint);
            commandSet.Add(nextWaypoint.Item);
            #endregion

            #region Target (2)
            // open menu
            Command openTargetMenu = new Command("OPENTARGET", new string[] { "show targets", "target menu", "open target menu", "targets" }, new uint[] { Keys.Two }, subjectRef);
            commandObjects.Add("OPENTARGET", openTargetMenu);
            commandSet.Add(openTargetMenu.Item);

            // cancel target (1)
            Command cancelTarget = new Command("CANCELTARGET", new string[] { "cancel target", "cancel targets", "no target" }, new uint[] { Keys.Two, Keys.One }, subjectRef);
            commandObjects.Add("CANCELTARGET", cancelTarget);
            commandSet.Add(cancelTarget.Item);
            #endregion

            #region Engage (3)
            // open fire (1)
            Command openFire = new Command("OPENFIRE", new string[] { "open fire", "go loud", "fire at will" }, new uint[] { Keys.Three, Keys.One }, subjectRef);
            commandObjects.Add("OPENFIRE", openFire);
            commandSet.Add(openFire.Item);

            // hold fire (2)
            Command holdFire = new Command("HOLDFIRE", new string[] { "hold fire", "go quiet", "cease fire" }, new uint[] { Keys.Three, Keys.Two }, subjectRef);
            commandObjects.Add("HOLDFIRE", holdFire);
            commandSet.Add(holdFire.Item);

            // fire (3)
            Command fire = new Command("FIRE", new string[] { "fire", "take the shot" }, new uint[] { Keys.Three, Keys.Three }, subjectRef);
            commandObjects.Add("FIRE", fire);
            commandSet.Add(fire.Item);

            // engage (4)
            Command engage = new Command("ENGAGE", new string[] { "engage", "move to engage" }, new uint[] { Keys.Three, Keys.Four }, subjectRef);
            commandObjects.Add("ENGAGE", engage);
            commandSet.Add(engage.Item);

            // engage at will (5)
            Command enageAtWill = new Command("ENGAGEATWILL", new string[] { "engage at will" }, new uint[] { Keys.Three, Keys.Five }, subjectRef);
            commandObjects.Add("ENGAGEATWILL", enageAtWill);
            commandSet.Add(enageAtWill.Item);

            // disengage (6)
            Command disengage = new Command("DISENGAGE", new string[] { "disengage" }, new uint[] { Keys.Three, Keys.Six }, subjectRef);
            commandObjects.Add("DISENGAGE", disengage);
            commandSet.Add(disengage.Item);

            // scan horizon (7)
            Command scanHorizon = new Command("SCANHORIZON", new string[] { "scan horizon", "scan the horizon" }, new uint[] { Keys.Three, Keys.Seven }, subjectRef);
            commandObjects.Add("SCANHORIZON", scanHorizon);
            commandSet.Add(scanHorizon.Item);

            // watch direction (8)
            // team direct object
            DirectObject direction = new DirectObject("directionDO");
            direction.Add(new string[] { "north" }, "NORTH", new uint[] { Keys.One });
            direction.Add(new string[] { "north east" }, "NORTHEAST", new uint[] { Keys.Two });
            direction.Add(new string[] { "east" }, "EAST", new uint[] { Keys.Three });
            direction.Add(new string[] { "south east" }, "SOUTHEAST", new uint[] { Keys.Four });
            direction.Add(new string[] { "south" }, "SOUTH", new uint[] { Keys.Five });
            direction.Add(new string[] { "south west" }, "SOUTHWEST", new uint[] { Keys.Six });
            direction.Add(new string[] { "west" }, "WEST", new uint[] { Keys.Seven });
            direction.Add(new string[] { "north west" }, "NORTHWEST", new uint[] { Keys.Eight });

            foreach (SrgsRule rule in direction.RuleList)
            {
                document.Rules.Add(rule);
            }

            Command watch = new Command("WATCH", new string[] { "watch", "watch the"}, new uint[] { Keys.Three, Keys.Eight }, subjectRef, direction);
            commandObjects.Add("WATCH", watch);
            commandSet.Add(watch.Item);

            // suppressive fire (9)
            Command suppresiveFire = new Command("SUPRESS", new string[] { "supppresive fire", "surpress" }, new uint[] { Keys.Three, Keys.Nine }, subjectRef);
            commandObjects.Add("SUPRESS", suppresiveFire);
            commandSet.Add(suppresiveFire.Item);
            #endregion

            #region Mount (4)
            // open mount menu
            Command openMountMenu = new Command("OPENMOUNT", new string[] { "show mount menu", "open mount menu", "show vehicles", "mount menu", "get in vehicle" }, new uint[] { Keys.Four }, subjectRef);
            commandObjects.Add("OPENMOUNT", openMountMenu);
            commandSet.Add(openMountMenu.Item);

            // dismount (1)
            Command dismount = new Command("DISMOUNT", new string[] { "dismount", "get out" }, new uint[] { Keys.Four, Keys.One }, subjectRef);
            commandObjects.Add("DISMOUNT", dismount);
            commandSet.Add(dismount.Item);
            #endregion

            #region Action (6)
            // open menu
            Command openActionMenu = new Command("OPENACTION", new string[] { "show actions", "action menu", "perform action", "do action", "open action menu", "actions" }, new uint[] { Keys.Six }, subjectRef);
            commandObjects.Add("OPENACTION", openActionMenu);
            commandSet.Add(openActionMenu.Item);
            #endregion

            #region Combat Mode (7)
            // stealth (1)
            Command stealth = new Command("STEALTH", new string[] { "stealth", "stealthy", "stealth mode" }, new uint[] { Keys.Seven, Keys.One }, subjectRef);
            commandObjects.Add("STEALTH", stealth);
            commandSet.Add(stealth.Item);

            // combat (2)
            Command combat = new Command("COMBAT", new string[] { "combat", "danger", "combat mode" }, new uint[] { Keys.Seven, Keys.Two }, subjectRef);
            commandObjects.Add("COMBAT", combat);
            commandSet.Add(combat.Item);

            // aware (3)
            Command aware = new Command("AWARE", new string[] { "aware", "alert", "aware mode", "stay sharp", "stay frosty", "stay alert" }, new uint[] { Keys.Seven, Keys.Three }, subjectRef);
            commandObjects.Add("AWARE", aware);
            commandSet.Add(aware.Item);

            // relax (4)
            Command relax = new Command("RELAX", new string[] { "relax", "relaxed mode", "safe" }, new uint[] { Keys.Seven, Keys.Four }, subjectRef);
            commandObjects.Add("RELAX", relax);
            commandSet.Add(relax.Item);

            // stand up (6)
            Command standUp = new Command("STANDUP", new string[] { "stand up", "get up", "stand" }, new uint[] { Keys.Seven, Keys.Six }, subjectRef);
            commandObjects.Add("STANDUP", standUp);
            commandSet.Add(standUp.Item);

            // stay crouched (7)
            Command stayCrouched = new Command("CROUCH", new string[] { "get low", "crouch", "stay crouched", "stay low" }, new uint[] { Keys.Seven, Keys.Seven }, subjectRef);
            commandObjects.Add("CROUCH", stayCrouched);
            commandSet.Add(stayCrouched.Item);

            // go prone (8)
            Command goProne = new Command("PRONE", new string[] { "go prone", "get down", "prone", "hit the dirt", "down" }, new uint[] { Keys.Seven, Keys.Eight }, subjectRef);
            commandObjects.Add("PRONE", goProne);
            commandSet.Add(goProne.Item);

            // copy my stance (9)
            Command copyMyStance = new Command("COPYMYSTANCE", new string[] { "copy my stance", "default stance" }, new uint[] { Keys.Seven, Keys.Nine }, subjectRef);
            commandObjects.Add("COPYMYSTANCE", copyMyStance);
            commandSet.Add(copyMyStance.Item);
            #endregion

            #region Formation (8)
            // column (1)
            Command column = new Command("COLUMN", new string[] { "formation column", "form column"}, new uint[] { Keys.Eight, Keys.One }, subjectRef);
            commandObjects.Add("COLUMN", column);
            commandSet.Add(column.Item);

            // staggered column (2)
            Command staggeredColumn = new Command("STAGGEREDCOLUMN", new string[] { "formation staggered column", "form staggered column" }, new uint[] { Keys.Eight, Keys.Two }, subjectRef);
            commandObjects.Add("STAGGEREDCOLUMN", staggeredColumn);
            commandSet.Add(staggeredColumn.Item);

            // wedge (3)
            Command wedge = new Command("WEDGE", new string[] { "formation wedge", "form wedge" }, new uint[] { Keys.Eight, Keys.Three }, subjectRef);
            commandObjects.Add("WEDGE", wedge);
            commandSet.Add(wedge.Item);

            // echelon left (4)
            Command echelonLeft = new Command("ECHELONLEFT", new string[] { "formation echelon left", "form echelon left" }, new uint[] { Keys.Eight, Keys.Four }, subjectRef);
            commandObjects.Add("ECHELONLEFT", echelonLeft);
            commandSet.Add(echelonLeft.Item);

            // echelon right (5)
            Command echeloneRight = new Command("ECHELONRIGHT", new string[] { "formation echelon right", "form echelon right" }, new uint[] { Keys.Eight, Keys.Five }, subjectRef);
            commandObjects.Add("ECHELONRIGHT", echeloneRight);
            commandSet.Add(echeloneRight.Item);

            // vee (6)
            Command vee = new Command("VEE", new string[] { "formation vee", "form vee" }, new uint[] { Keys.Eight, Keys.Six }, subjectRef);
            commandObjects.Add("VEE", vee);
            commandSet.Add(vee.Item);

            // line (7)
            Command line = new Command("LINE", new string[] { "formation line", "form line" }, new uint[] { Keys.Eight, Keys.Seven }, subjectRef);
            commandObjects.Add("LINE", line);
            commandSet.Add(line.Item);

            // file (8)
            Command file = new Command("FILE", new string[] { "formation file", "form file" }, new uint[] { Keys.Eight, Keys.Eight }, subjectRef);
            commandObjects.Add("FILE", file);
            commandSet.Add(file.Item);

            // diamond (9)
            Command diamond = new Command("DIAMOND", new string[] { "formation diamond", "form diamond" }, new uint[] { Keys.Eight, Keys.Nine }, subjectRef);
            commandObjects.Add("DIAMOND", diamond);
            commandSet.Add(diamond.Item);
            #endregion

            #region Assign Team (9)
            // team direct object
            DirectObject team = new DirectObject("teamDO");
            team.Add(new string[] { "team red", "red" }, "RED", new uint[] { Keys.One });
            team.Add(new string[] { "team green", "green" }, "GREEN", new uint[] { Keys.Two });
            team.Add(new string[] { "team blue", "blue" }, "BLUE", new uint[] { Keys.Three });
            team.Add(new string[] { "team yellow", "yellow" }, "YELLOW", new uint[] { Keys.Four });
            team.Add(new string[] { "team white", "white" }, "WHITE", new uint[] { Keys.Five });

            foreach (SrgsRule rule in team.RuleList)
            {
                document.Rules.Add(rule);
            }

            Command assignTeam = new Command("ASSIGN", new string[] { "assign", "assign to", "add to", "switch to" }, new uint[] { Keys.Nine }, subjectRef, team);
            commandObjects.Add("ASSIGN", assignTeam);
            commandSet.Add(assignTeam.Item);
            #endregion

            // not implemented
            #region WW_AiMenu
            #region Infantry Commands (1)
            // heal up (1)

            // rearm (2)

            // inventory (3)

            // fire on my lead (4)

            // garrison building (5)

            // clear building (6)

            // follow target (7)
            #endregion

            #region WayPoints (4)
            // set waypoints (1)

            // add waypoints (2)

            // move waypoints (3)

            // delete waypoints (4)

            // wait on waypoint (5)

            // cycle waypoint (6)
            #endregion
            #endregion
            #endregion

            // set the root rule to
            SrgsRule commands = new SrgsRule("commands");
            commands.Add(commandSet);

            document.Rules.Add(commands);
            document.Root = commands;

            return document;
        }
Beispiel #55
0
        public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs)
        {
            var commands = new SrgsOneOf(
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'Reset'"),
                    new SrgsItem("bomb reset")
                ),
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'SerialParity'"),
                    new SrgsItem("serial number"),
                    new SrgsOneOf(
                        new SrgsItem(
                            new SrgsItem("even"),
                            new SrgsSemanticInterpretationTag("out.Value = 'even'")
                        ),
                        new SrgsItem(
                            new SrgsItem("odd"),
                            new SrgsSemanticInterpretationTag("out.Value = 'odd'")
                        )
                    )
                ),
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'SerialVowel'"),
                    new SrgsItem("serial vowel"),
                     refs["YesOrNo"],
                    new SrgsSemanticInterpretationTag("out.Value = rules.YesOrNo")
                ),
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'BatteryCount'"),
                    new SrgsItem("batteries"),
                    refs["Number"],
                    new SrgsSemanticInterpretationTag("out.Count = rules.Number")
                ),
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'Indicator'"),
                    new SrgsItem("indicator"),
                    new SrgsOneOf(
                        new SrgsItem(
                            new SrgsItem("car"),
                            new SrgsSemanticInterpretationTag("out.Label = 'CAR'")
                        ),
                        new SrgsItem(
                            new SrgsItem("freak"),
                            new SrgsSemanticInterpretationTag("out.Label = 'FRK'")
                        )
                    ),
                    refs["YesOrNo"],
                    new SrgsSemanticInterpretationTag("out.Value = rules.YesOrNo")
                ),
                 new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'StrikeCount'"),
                    new SrgsItem("strikes"),
                    refs["Number"],
                    new SrgsSemanticInterpretationTag("out.Count = rules.Number")
                )
            );

            var moduleRule = new SrgsRule("Bomb",
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Module = 'Bomb'"),
                    commands
                )
            );

            return new Tuple<SrgsRuleRef, IList<SrgsRule>>(
                new SrgsRuleRef(moduleRule),
                new List<SrgsRule> { moduleRule }
            );
        }
Beispiel #56
0
        public CMUSphinx_GrammarDict CreateGrammarDoc_JSGF()
        {
            if (currentJSGFDoc != null) return currentJSGFDoc;
            CMUSphinx_GrammarDict ret = new CMUSphinx_GrammarDict();
            ret.GrammarName = GetName();
            StringBuilder bld = new StringBuilder();

            List<string> ops = new List<string>();

            //numbers
            CreateNumberJSGF("NUMS", ret);

            //TV Shows
            if (mTVShows == null)
            {
                mTVShows = ListTVShows();
            }
            if (mTVShows == null) return null;
            List<string> tvShowNames = new List<string>();
            foreach (XBMCProto.TVShow s in mTVShows)
            {
                string temps = CleanString(s.label);
                temps = temps.Trim();
                if (temps == "" || s.tvshowid < 1) continue;
                tvShowNames.Add(temps);
            }

            string tvshow_name = "<TVSHOW>";
            StringBuilder tvshow_bld = new StringBuilder();
            ret.JSGFRuleStart(tvshow_name, tvshow_bld);
            ret.JSGFRuleAddChoicesStart(tvshow_bld, new List<string>(new string[]{ "play show", "resume show"}));
            ret.JSGFRuleAddChoicesEnd(tvshow_bld);
            ret.JSGFRuleAddChoicesStart(tvshow_bld, tvShowNames);
            ret.JSGFRuleAddChoicesEnd(tvshow_bld);
            ret.JSGFRuleAddToken(tvshow_bld, "SEASON");
            ret.JSGFRuleAddToken(tvshow_bld, "<NUMS>");
            ret.JSGFRuleAddToken(tvshow_bld, "EPISODE");
            ret.JSGFRuleAddToken(tvshow_bld, "<NUMS>");
            ret.JSGFRuleEnd(tvshow_name, tvshow_bld);

            ops.Add(tvshow_name);

            //Movies
            if (mMovies == null)
            {
                mMovies = ListMovies();
            }
            if (mMovies == null) return null;
            List<string> movieNames = new List<string>();
            foreach (XBMCProto.Movie m in mMovies)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.movieid < 1) continue;
                movieNames.Add(temps);
            }

            string movie_name = "<MOVIE>";
            StringBuilder movie_bld = new StringBuilder();
            ret.JSGFRuleStart(movie_name, movie_bld);
            ret.JSGFRuleAddChoicesStart(movie_bld, new List<string>(new string[] { "play movie", "resume movie" }));
            ret.JSGFRuleAddChoicesEnd(movie_bld);
            ret.JSGFRuleAddChoicesStart(movie_bld, movieNames);
            ret.JSGFRuleAddChoicesEnd(movie_bld);
            ret.JSGFRuleEnd(movie_name, movie_bld);

            ops.Add(movie_name);

            //Music Genres
            SrgsOneOf audioGenres = new SrgsOneOf();
            if (mGenres == null)
            {
                mGenres = ListAudioGenres();
            }
            if (mGenres == null) return null;
            List<string> genreNames = new List<string>();
            foreach (XBMCProto.Genre m in mGenres)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.genreid < 1) continue;
                genreNames.Add(temps + " music");
            }

            string audiogenre_name = "<AUDIOGENRE>";
            StringBuilder audiogenre_bld = new StringBuilder();
            ret.JSGFRuleStart(audiogenre_name, audiogenre_bld);
            ret.JSGFRuleAddToken(audiogenre_bld, "play me some");
            ret.JSGFRuleAddChoicesStart(audiogenre_bld, genreNames);
            ret.JSGFRuleAddChoicesEnd(audiogenre_bld);
            ret.JSGFRuleEnd(audiogenre_name, audiogenre_bld);

            ops.Add(audiogenre_name);

            //Other
            ops.Add("stop media");
            ops.Add("pause media");
            ops.Add("resume media");

            StringBuilder bld_ops= new StringBuilder();
            ret.JSGFRuleStart("<OPS>", bld_ops);
            ret.JSGFRuleAddChoicesStart(bld_ops, ops);
            ret.JSGFRuleAddChoicesEnd(bld_ops);
            ret.JSGFRuleEnd("<OPS>", bld_ops);

            ret.JSGFRuleStart("<ROOT>", bld);
            ret.JSGFRuleAddToken(bld, "Holly");
            ret.JSGFRuleAddToken(bld, "<OPS>");
            ret.JSGFRuleAddToken(bld, "please");
            ret.JSGFRuleEnd("<ROOT>", bld);

            ret.JSGFSetRootRule("<ROOT>");

            ret.BuildJSGFGrammarAndDict();
            currentJSGFDoc = ret;
            return ret;
        }
Beispiel #57
0
        SrgsItem CreateNumberSRGS(string prepend, SrgsDocument doc)
        {
            SrgsItem digit_0 = new SrgsItem("zero");
            digit_0.Add(new SrgsNameValueTag(prepend+"0", 0));
            SrgsItem digit_1 = new SrgsItem("one");
            digit_1.Add(new SrgsNameValueTag(prepend + "1", 1));
            SrgsItem digit_2 = new SrgsItem("two");
            digit_2.Add(new SrgsNameValueTag(prepend + "2", 2));
            SrgsItem digit_3 = new SrgsItem("three");
            digit_3.Add(new SrgsNameValueTag(prepend + "3", 3));
            SrgsItem digit_4 = new SrgsItem("four");
            digit_4.Add(new SrgsNameValueTag(prepend + "4", 4));
            SrgsItem digit_5 = new SrgsItem("five");
            digit_5.Add(new SrgsNameValueTag(prepend + "5", 5));
            SrgsItem digit_6 = new SrgsItem("six");
            digit_6.Add(new SrgsNameValueTag(prepend + "6", 6));
            SrgsItem digit_7 = new SrgsItem("seven");
            digit_7.Add(new SrgsNameValueTag(prepend + "7", 7));
            SrgsItem digit_8 = new SrgsItem("eight");
            digit_8.Add(new SrgsNameValueTag(prepend + "8", 8));
            SrgsItem digit_9 = new SrgsItem("nine");
            digit_9.Add(new SrgsNameValueTag(prepend + "9", 9));
            SrgsItem digit_10 = new SrgsItem("ten");
            digit_10.Add(new SrgsNameValueTag(prepend + "10", 10));
            SrgsItem digit_11 = new SrgsItem("eleven");
            digit_11.Add(new SrgsNameValueTag(prepend + "11", 11));
            SrgsItem digit_12 = new SrgsItem("twelve");
            digit_12.Add(new SrgsNameValueTag(prepend + "12", 12));
            SrgsItem digit_13 = new SrgsItem("thirteen");
            digit_13.Add(new SrgsNameValueTag(prepend + "13", 13));
            SrgsItem digit_14 = new SrgsItem("fourteen");
            digit_14.Add(new SrgsNameValueTag(prepend + "14", 14));
            SrgsItem digit_15 = new SrgsItem("fifteen");
            digit_15.Add(new SrgsNameValueTag(prepend + "15", 15));
            SrgsItem digit_16 = new SrgsItem("sixteen");
            digit_16.Add(new SrgsNameValueTag(prepend + "16", 16));
            SrgsItem digit_17 = new SrgsItem("seventeen");
            digit_17.Add(new SrgsNameValueTag(prepend + "17", 17));
            SrgsItem digit_18 = new SrgsItem("eighteen");
            digit_18.Add(new SrgsNameValueTag(prepend + "18", 18));
            SrgsItem digit_19 = new SrgsItem("nineteen");
            digit_19.Add(new SrgsNameValueTag(prepend + "19", 19));

            SrgsItem digit_20 = new SrgsItem("twenty");
            digit_20.Add(new SrgsNameValueTag(prepend + "20", 20));
            SrgsItem digit_30 = new SrgsItem("thirty");
            digit_30.Add(new SrgsNameValueTag(prepend + "30", 30));
            SrgsItem digit_40 = new SrgsItem("fourty");
            digit_40.Add(new SrgsNameValueTag(prepend + "40", 40));
            SrgsItem digit_50 = new SrgsItem("fifty");
            digit_50.Add(new SrgsNameValueTag(prepend + "50", 50));
            SrgsItem digit_60 = new SrgsItem("sixty");
            digit_60.Add(new SrgsNameValueTag(prepend + "60", 60));

            SrgsOneOf digit_onepart = new SrgsOneOf(digit_0, digit_1, digit_2, digit_3,
                digit_4, digit_5, digit_6, digit_7, digit_8, digit_9, digit_10,
                digit_11, digit_12, digit_13, digit_14, digit_15, digit_16, digit_17, digit_18, digit_19,
                digit_20, digit_30, digit_40, digit_50, digit_60);
            SrgsOneOf digit_single = new SrgsOneOf(digit_1, digit_2, digit_3,
                digit_4, digit_5, digit_6, digit_7, digit_8, digit_9);
            SrgsOneOf digit_second = new SrgsOneOf(digit_20, digit_30, digit_40, digit_50, digit_60);
            SrgsRule digit_twopart = new SrgsRule(prepend+"_twodigit");
            digit_twopart.Add(digit_second);
            digit_twopart.Add(digit_single);
            doc.Rules.Add(digit_twopart);
            SrgsOneOf number = new SrgsOneOf(
                new SrgsItem(digit_onepart), new SrgsItem(new SrgsRuleRef(digit_twopart)));

            SrgsItem ret = new SrgsItem(number);
            ret.Add(new SrgsNameValueTag(prepend, "true"));
            return ret;
        }
Beispiel #58
0
        public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs)
        {
            var commands = new SrgsOneOf(
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Command = 'Simon'; out.Colors = ''"),
                    new SrgsItem("simon"),
                    new SrgsItem(1, 10,
                        refs["Color"],
                        new SrgsSemanticInterpretationTag("out.Colors += rules.Color + ','")
                    )
                )
            );

            var moduleRule = new SrgsRule("Simon",
                new SrgsItem(
                    new SrgsSemanticInterpretationTag("out.Module = 'Simon'"),
                    commands
                )
            );

            return new Tuple<SrgsRuleRef, IList<SrgsRule>>(
                new SrgsRuleRef(moduleRule),
                new List<SrgsRule> { moduleRule }
            );
        }
        private SrgsRule GetRootRule()
        {
            SrgsRule rootRule = new SrgsRule("rootRule");
            usedRules.Add("rootRule", rootRule);

            SrgsRule directionRules = GetDirectionRules();
            SrgsRule simpleCommandsRule = GetSimpleCommandsRule();

            SrgsOneOf oneOfElements = new SrgsOneOf(
                new SrgsItem(new SrgsRuleRef(directionRules)),
                new SrgsItem(new SrgsRuleRef(simpleCommandsRule))
            );

            rootRule.Add(oneOfElements);
            return rootRule;
        }