Beispiel #1
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);
        }
        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 #3
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;
        }
        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 #5
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 #6
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);
        }
        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 #8
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 #9
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 #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
Beispiel #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
0
        private static Grammar GenerateCommandGrammar(List <CommandConfig> commands)
        {
            var doc = new SrgsDocument();

            var numbers = new List <string>(CommandEngine.Numbers.Keys);

            numbers.AddRange(new [] { "left", "up", "right", "down" });

            var numbers04 = new SrgsRule("numbers04")
            {
                Scope = SrgsRuleScope.Private
            };

            numbers04.Add(new SrgsItem(0, 4, new SrgsOneOf(numbers.ToArray())));
            doc.Rules.Add(numbers04);

            var numbers14 = new SrgsRule("numbers14")
            {
                Scope = SrgsRuleScope.Private
            };

            numbers14.Add(new SrgsItem(1, 4, new SrgsOneOf(numbers.ToArray())));
            doc.Rules.Add(numbers14);

            // TODO Prevent duplicate commands from being registered
            var choices = new List <SrgsItem>();

            foreach (var command in commands)
            {
                var item = new SrgsItem();

                var parts = command.Pattern.Split(' ');
                for (int i = 0, j = 0; i <= parts.Length; ++i)
                {
                    if (i == parts.Length)
                    {
                        var segment = string.Join(" ", parts, j, i - j);
                        if (!string.IsNullOrWhiteSpace(segment))
                        {
                            item.Add(new SrgsText(segment));
                            //Console.Write("\"" + segment + "\" ");
                        }
                    }
                    else if (parts[i].IndexOf('{') != -1)
                    {
                        var segment = string.Join(" ", parts, j, i - j);
                        if (!string.IsNullOrWhiteSpace(segment))
                        {
                            item.Add(new SrgsText(segment));
                            //Console.Write("\"" + segment + "\" ");
                        }

                        var  type       = parts[i].Split(':').Skip(1).First();
                        bool zeroOrMore = type[type.Length - 1] == '?';
                        type = type.Substring(0, type.IndexOf('}'));
                        switch (type)
                        {
                        case "number":
                            item.Add(new SrgsRuleRef(zeroOrMore ? numbers04 : numbers14));
                            //Console.Write("*number* ");
                            break;

                        case "word":
                            item.Add(SrgsRuleRef.Dictation);
                            //Console.Write("*word* ");
                            break;

                        default:
                            throw new IndexOutOfRangeException(type);
                        }

                        j = i + 1;
                    }
                }

                choices.Add(item);
                //Console.WriteLine();
            }

            var root = new SrgsRule("root")
            {
                Scope = SrgsRuleScope.Private
            };

            root.Add(new SrgsItem(
                         1, int.MaxValue,
                         new SrgsOneOf(choices.ToArray())
                         ));
            doc.Rules.Add(root);
            doc.Root = root;

            //using(var sw = File.OpenWrite(@"C:\Temp\NewGrammar.srgs"))
            //using(var xw = XmlWriter.Create(sw))
            //    doc.WriteSrgs(xw);

            return(new Grammar(doc)
            {
                Name = "Commands",
                Weight = 1.0f
            });
        }
Beispiel #20
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");

            SrgsOneOf squadNumbersChoice       = new SrgsOneOf(one, two, three, four, five, six, seven, eight, nine, ten);
            SrgsItem  squadNumbersConcatChoice = new SrgsItem(squadNumbersChoice, new SrgsItem(0, 1, "and"));

            squadNumbersConcatChoice.SetRepeat(1, 10);
            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);
        }
        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 #22
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 #23
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 #24
0
        private void Form2_Load(object sender, EventArgs e)
        {
            recEngine = new SpeechRecognitionEngine();

            /*Reglas para Select*/
            SrgsRule  selectRule = new SrgsRule("selectRule");
            SrgsOneOf selectList = new SrgsOneOf(new string[] {
                "selecciona",
                "traeme",
                "busca",
                "obten",
                "muestrame",
                "muestra",
                "imprime",
                "imprimir"
            });

            selectRule.Add(selectList);

            /*Reglas para numero de registros
             * todos, los = all *
             */
            SrgsRule  allRule = new SrgsRule("allRule");
            SrgsOneOf allList = new SrgsOneOf(new string[] {
                "los",
                "todos los"
            });

            allRule.Add(allList);

            /*nombre de la tabla*/
            SrgsRule  tablaRule = new SrgsRule("tablaRule");
            SrgsOneOf tablaList = new SrgsOneOf(new string[] {
                "empleados"
            });

            tablaRule.Add(tablaList);
            SrgsRule  whereRule = new SrgsRule("whereRule");
            SrgsOneOf whereList = new SrgsOneOf(new string[] {
                "igual"
            });

            allRule.Add(allList);


            /*La referencia con una root ruke hace que que las reglas se unana y tengan que tener un
             * orden especifico, quitar o comentar la regla principal y quirar del la creacion del documenteo */
            /*Regla principal*/
            SrgsRule mainRule = new SrgsRule("mainRule");

            mainRule.Scope = SrgsRuleScope.Public;

            /*Unir los select con los all*/
            // Create the "Subject" and "Verb" rule references and add them to the SrgsDocument.
            SrgsRuleRef selectRef = new SrgsRuleRef(selectRule, "theSelect");

            mainRule.Add(selectRef);

            SrgsRuleRef allRef = new SrgsRuleRef(allRule, "theAll");

            mainRule.Add(allRef);

            SrgsRuleRef tablaRef = new SrgsRuleRef(tablaRule, "theTabla");

            mainRule.Add(tablaRef);

            //Creando el documento con las reglas
            SrgsDocument newDocumento = new SrgsDocument();

            newDocumento.Rules.Add(new SrgsRule[] {
                mainRule,
                selectRule,
                allRule,
                tablaRule
            });
            newDocumento.Root = mainRule;

            //Agragar gramatica al engine
            Grammar grammar = new Grammar(newDocumento, "mainRule");

            recEngine.LoadGrammar(grammar);

            //Crear XML
            System.Xml.XmlWriter writer =
                System.Xml.XmlWriter.Create("C:\\Users\\Misael\\Documents\\ejemplo.xml");
            newDocumento.WriteSrgs(writer);
            writer.Close();


            // Attach a handler for the SpeechRecognized event.
            recEngine.SpeechRecognized +=
                new EventHandler <SpeechRecognizedEventArgs>(recEngine_SpeechRecognized);

            // Configure the input to the SpeechRecognitionEngine object.
            recEngine.SetInputToDefaultAudioDevice();

            // Start asynchronous recognition.
            recEngine.RecognizeAsync();
        }
Beispiel #25
0
        public static SrgsDocument BuildSrgsGrammar(CultureInfo cultureInfo)
        {
            SrgsDocument document = new SrgsDocument();

            document.Culture = cultureInfo;

            // Collect all subject items and add them to the document
            subjectObject = new Subject();
            foreach (SrgsRule rule in subjectObject.RuleList)
            {
                document.Rules.Add(rule);
            }

            SrgsRuleRef subjectRef = new SrgsRuleRef(subjectObject.RootRule);

            commandObjects = new Dictionary <string, Command>();
            SrgsOneOf commandSet = new SrgsOneOf();

            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 regroup = new Command("REGROUP", new string[] { "regroup", "return to formation", "fall back", "on me" }, "regroup", subjectRef);
            commandObjects.Add("REGROUP", regroup);
            commandSet.Add(regroup.Item);

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

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

            // Move to (Space)
            Command move = new Command("MOVE", new string[] { "move", "get over there", "move up" }, "move", subjectRef);
            commandObjects.Add("MOVE", move);
            commandSet.Add(move.Item);
            #endregion

            #region Engage (3)

            // Open fire (1)
            Command openFire = new Command("OPENFIRE", new string[] { "open fire", "fire at will", "weapons free", "go loud" }, "open fire", subjectRef);
            commandObjects.Add("OPENFIRE", openFire);
            commandSet.Add(openFire.Item);

            // Hold fire (1)
            Command holdFire = new Command("HOLDFIRE", new string[] { "hold fire", "cease fire", "go quiet" }, "hold fire", subjectRef);
            commandObjects.Add("HOLDFIRE", holdFire);
            commandSet.Add(holdFire.Item);

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

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

            // Engage at will (5)
            Command engageAtWill = new Command("ENGAGEATWILL", new string[] { "engage at will" }, "engage at will", subjectRef);
            commandObjects.Add("ENGAGEATWILL", engageAtWill);
            commandSet.Add(engageAtWill.Item);

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

            // Suppressive fire (9)
            Command suppressiveFire = new Command("SUPRESS", new string[] { "supressive fire", "supress" }, "suppressive fire", subjectRef);
            commandObjects.Add("SUPRESS", suppressiveFire);
            commandSet.Add(suppressiveFire.Item);

            #endregion

            #region Combat Mode (7)

            // Stealth (1)
            Command stealth = new Command("STEALTH", new string[] { "stealth", "go quiet", "go silent" }, "stealth", subjectRef);
            commandObjects.Add("STEALTH", stealth);
            commandSet.Add(stealth.Item);

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

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

            // Relax (4)
            Command relax = new Command("RELAX", new string[] { "relax", "safe", "at ease" }, "relax", subjectRef);
            commandObjects.Add("RELAX", relax);
            commandSet.Add(relax.Item);

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

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

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

            // Copy my stance (9)
            Command copyStance = new Command("COPYSTANCE", new string[] { "copy my stance", "default stance" }, "copy stance", subjectRef);
            commandObjects.Add("COPYSTANCE", copyStance);
            commandSet.Add(copyStance.Item);

            #endregion

            #region Formation (8)

            // Column (1)
            Command column = new Command("COLUMN", new string[] { "formation column", "form column" }, "column", 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" }, "staggered column", subjectRef);
            commandObjects.Add("STAGGEREDCOLUMN", staggeredColumn);
            commandSet.Add(staggeredColumn.Item);

            // Wedge (3)
            Command wedge = new Command("WEDGE", new string[] { "formation wedge", "form wedge" }, "wedge", 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" }, "echelon left", subjectRef);
            commandObjects.Add("ECHELONLEFT", echelonLeft);
            commandSet.Add(echelonLeft.Item);

            // Echelon Right (5)
            Command echelonRight = new Command("ECHELONRIGHT", new string[] { "formation echelon right", "form echelon right" }, "echelon right", subjectRef);
            commandObjects.Add("ECHELONRIGHT", echelonRight);
            commandSet.Add(echelonRight.Item);

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

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

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

            // Diamond (9)
            Command diamond = new Command("DIAMOND", new string[] { "formation diamond", "form diamond" }, "diamond", subjectRef);
            commandObjects.Add("DIAMOND", diamond);
            commandSet.Add(diamond.Item);

            #endregion

            #endregion

            SrgsRule commands = new SrgsRule("commands");
            commands.Add(commandSet);

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

            return(document);
        }
Beispiel #26
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 #27
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 #28
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 #29
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;
        }
        private Grammar init()
        {
            SrgsRule  ruleCity = new SrgsRule("Miasto");
            SrgsOneOf city     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, "Warszawa"),
                new SrgsItem(1, 1, "Radom"),
                new SrgsItem(1, 1, "Gdańsk"),
                new SrgsItem(1, 1, "Kielce"),
                new SrgsItem(1, 1, "Poznań")
            });

            ruleCity.Add(city);

            SrgsRule  ruleStreet = new SrgsRule("Ulica");
            SrgsOneOf street     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, "ulica Biała"),
                new SrgsItem(1, 1, "ulica Jasna"),
                new SrgsItem(1, 1, "ulica Ciemna"),
                new SrgsItem(1, 1, "ulica Czarna"),
                new SrgsItem(1, 1, "ulica Szybka"),
                new SrgsItem(1, 1, "ulica Wolna")
            });

            ruleStreet.Add(street);

            SrgsRule  ruleLiczba = new SrgsRule("Liczebnik");
            SrgsOneOf liczebnik  = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem("1"),
                new SrgsItem("2"),
                new SrgsItem("3"),
                new SrgsItem("4"),
                new SrgsItem("5"),
                new SrgsItem("6"),
                new SrgsItem("7"),
                new SrgsItem("8"),
                new SrgsItem("9")
            });

            ruleLiczba.Add(liczebnik);

            SrgsRule rootRule = new SrgsRule("rootBiletomat");

            rootRule.Scope = SrgsRuleScope.Public;

            rootRule.Add(new SrgsRuleRef(ruleCity, "IMIE"));
            rootRule.Add(new SrgsRuleRef(ruleStreet, "NAZWISKO"));
            rootRule.Add(new SrgsRuleRef(ruleLiczba, "LICZBA"));


            SrgsDocument docBiletomat = new SrgsDocument();

            docBiletomat.Culture = pRecognitionLanguage;
            docBiletomat.Rules.Add(new SrgsRule[]
                                   { rootRule, ruleCity, ruleStreet, ruleLiczba }
                                   );
            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);
        }
        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 #32
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 #33
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));
        }
Beispiel #34
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);
        }
Beispiel #35
0
        static void Main(string[] args)
        {
            // Create the "Subject" rule.
            SrgsRule  subjRule = new SrgsRule("id_Subject");
            SrgsOneOf subjList = new SrgsOneOf(new string[] { "I", "you", "he", "she", "Tom", "Mary" });

            subjRule.Add(subjList);

            // Create the "Verb" rule.
            SrgsRule  verbRule = new SrgsRule("id_Verb");
            SrgsOneOf verbList = new SrgsOneOf(new string[] { "ate", "bought", "saw", "sold", "wanted" });

            verbRule.Add(verbList);

            // Create the "Object" rule.
            SrgsRule  objRule = new SrgsRule("id_Object");
            SrgsOneOf objList = new SrgsOneOf(new string[] { "apple", "banana", "pear", "peach", "melon" });

            objRule.Add(objList);

            // Create the root rule.
            // In this grammar, the root rule contains references to the other three rules.
            SrgsRule rootRule = new SrgsRule("Subj_Verb_Obj");

            rootRule.Scope = SrgsRuleScope.Public;

            // Create the "Subject" and "Verb" rule references and add them to the SrgsDocument.
            SrgsRuleRef subjRef = new SrgsRuleRef(subjRule, "theSubject");

            rootRule.Add(subjRef);

            SrgsRuleRef verbRef = new SrgsRuleRef(verbRule, "theVerb");

            rootRule.Add(verbRef);

            // Add logic to handle articles: "the", "a", "and", occurring zero or one time.
            SrgsOneOf articles = new SrgsOneOf(
                new SrgsItem[] { new SrgsItem(0, 1, "the"), new SrgsItem(0, 1, "a"), new SrgsItem(0, 1, "an") }
                );

            rootRule.Add(articles);

            // Create the "Object" rule reference and add it to the SrgsDocument.
            SrgsRuleRef objRef = new SrgsRuleRef(objRule, "theObject");

            rootRule.Add(objRef);

            // Create an SrgsDocument object that contains all four rules.
            SrgsDocument document = new SrgsDocument();

            document.Rules.Add(rootRule, subjRule, verbRule, objRule);

            // Set "rootRule" as the root rule of the grammar.
            document.Root = rootRule;

            // Create a Grammar object, initializing it with the root rule.
            Grammar g = new Grammar(document, rootRule.Id);

            // Create a new SpeechRecognizer instance.
            SpeechRecognizer sr = new SpeechRecognizer();

            // Load the Grammar object into the recognizer.
            sr.LoadGrammar(g);

            // Produce an XML file that contains the grammar.
            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("srgsDocument.xml");
            document.WriteSrgs(writer);
            writer.Close();

            sr.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(sr_SpeechRecognized);
            while (true)
            {
                Console.Read();
            }
        }
        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 #37
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];
        }