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 void AddMoviesSpeechGrammarRules(SrgsRulesCollection srgsRules)
        {
            Movie[] movies = null;

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

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

                {
                    SrgsOneOf movieSrgsOneOf = new SrgsOneOf();

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

                        movieSrgsOneOf.Add(srgsItem);
                    }

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

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

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

                srgsRules.Add(movieSrgsRule);

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

                    SrgsRule  rootSrgsRule = srgsRules.Where(rule => rule.Id == "root").First();
                    SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                    srgsOneOf.Add(srgsItem);
                }
            }
        }
Beispiel #3
0
        private void AddRowSeatSpeechGrammarRules(SrgsRulesCollection rules)
        {
            SrgsRule rowSeatSrgsRule;

            {
                SrgsOneOf rowSeatSrgsOneOf = new SrgsOneOf();

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

                    rowSeatSrgsOneOf.Add(srgsItem);
                }

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

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

            rules.Add(rowSeatSrgsRule);

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

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Create Grammars for the contact names of customer's contact list
        /// </summary>
        private void Code_PrepareGrammar(object sender, EventArgs e)
        {
            SrgsOneOf oneOf = new SrgsOneOf();

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

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

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

                oneOf.Add(nameItem);
            }

            SrgsRule nameRule = new SrgsRule("name");

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

            SrgsDocument grammarDoc = new SrgsDocument();

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

            speechGrammar.Add(new Grammar(grammarDoc));
        }
Beispiel #5
0
        //Method to add item dynamically in the grammar
        private void addItemInABalise(SrgsDocument xmlGrammar, string nameOfRule, int idOfBalise, string itemToAdd)
        {
            #region Add item dynamically in the grammar

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

            #endregion
        }
Beispiel #6
0
        /// <summary>
        /// Creates a grammar for main menu options.
        /// </summary>
        /// <returns></returns>
        private Grammar SetupGrammar()
        {
            var options = this.MainMenuConfiguration.Options;

            SrgsOneOf oneOf = new SrgsOneOf();

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

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

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

                oneOf.Add(digitItem);
            }

            SrgsRule digitRule = new SrgsRule("digit");

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

            SrgsDocument grammarDoc = new SrgsDocument();

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

            return(new Grammar(grammarDoc));
        }
Beispiel #7
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 #8
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 #9
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 #10
0
        /// <summary>
        /// Generate a list of grammars with the annotations attach to the
        /// grammars' semantic tag.
        /// </summary>
        /// <param name="list"></param>
        /// <param name="annotations"></param>
        /// <returns></returns>
        public static List <SrgsDocument> GenerateGrammars(string[] list, string[] annotations)
        {
            String timeStamp = GetTimestamp();

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

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

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

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

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

            SrgsRule rule = new SrgsRule(ruleName, oneOfElements);

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

            {
                SrgsOneOf srgsOneOf = new SrgsOneOf();

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

                    srgsOneOf.Add(srgsItem);
                }

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

            rules.Add(movieSrgsRule);

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

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
Beispiel #13
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 #14
0
        public void AddGrammarRules(SrgsRulesCollection rules, SrgsOneOf choices)
        {
            var grammarRules = GetGrammarRules();

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

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

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

                choices.Add(pluginRuleItem);
            }
        }
        public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs)
        {
            var letters = new SrgsOneOf();
            foreach (var dataPair in this.letters)
            {
                letters.Add(new SrgsItem(
                    new SrgsSemanticInterpretationTag(string.Format("out = '{0}'", dataPair.Value)),
                    new SrgsToken(dataPair.Key)
                ));
            }

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

            return new Tuple<SrgsRuleRef, IList<SrgsRule>>(
                null,
                new List<SrgsRule> { letterRule }
            );
        }
Beispiel #16
0
        private void AddRowSpeechGrammarRules(SrgsRulesCollection rules)
        {
            SrgsRule rowSrgsRule;

            {
                SrgsOneOf rowSrgsOneOf = new SrgsOneOf();

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

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

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

                    rowSrgsOneOf.Add(srgsItem);
                }

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

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

            rules.Add(rowSrgsRule);

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

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
Beispiel #17
0
        private void AddSeatSpeechGrammarRules(SrgsRulesCollection rules)
        {
            SrgsRule seatSrgsRule;

            {
                SrgsOneOf seatSrgsOneOf = new SrgsOneOf();

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

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

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

                    seatSrgsOneOf.Add(srgsItem);
                }

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

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

            rules.Add(seatSrgsRule);

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

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
Beispiel #18
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 #19
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 #20
0
 public override void Invoke()
 {
     if (grammars.ContainsKey(name))
     {
         var other = grammars[name];
         Program.se.UnloadAllGrammars();
         grammars2.Remove(other.grammar);
         grammars.Remove(other.name);
     }
     var doc = new SrgsDocument(new XmlTextReader(new MemoryStream(Properties.Resources.numbers)));
     var alt = new SrgsOneOf();
     foreach (var rule in rules)
         alt.Add(new SrgsItem(new SrgsElement[] { rule.Value.Build(doc), new SrgsNameValueTag(rule.Key) }));
     var root = new SrgsRule(Program.InternalMarker + "root", alt);
     doc.Rules.Add(root);
     doc.Root = root;
     doc.Debug = true;
     grammar = new Grammar(doc);
     grammars.Add(name, this);
     grammars2.Add(grammar, this);
     Console.WriteLine("Created grammar " + name);
 }
Beispiel #21
0
        protected override void AddCustomSpeechGrammarRules(SrgsRulesCollection rules)
        {
            SrgsRule movieSrgsRule;

            {
                SrgsOneOf movieSrgsOneOf = new SrgsOneOf();

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

                    movieSrgsOneOf.Add(srgsItem);
                }

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

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

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

            rules.Add(movieSrgsRule);

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

                SrgsRule  rootSrgsRule = rules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
        private void AddGenresSpeechGrammarRulers(SrgsRulesCollection srgsRules)
        {
            SrgsRule genreSrgsRule;

            {
                SrgsOneOf genreSrgsOneOf = new SrgsOneOf();

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

                    genreSrgsOneOf.Add(srgsItem);
                }

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

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

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

            srgsRules.Add(genreSrgsRule);

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

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

            {
                SrgsOneOf ticketSrgsOneOf = new SrgsOneOf();

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

                    ticketSrgsOneOf.Add(srgsItem);
                }

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

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

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

            srgsRules.Add(ticketSrgsRule);

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

                SrgsRule  rootSrgsRule = srgsRules.Where(rule => rule.Id == "root").First();
                SrgsOneOf srgsOneOf    = (SrgsOneOf)rootSrgsRule.Elements.Where(element => element is SrgsOneOf).First();
                srgsOneOf.Add(srgsItem);
            }
        }
Beispiel #24
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 #25
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 #26
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 #27
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];
        }
        private SrgsRule GetRuleFromList(List<String> list, String ruleName)
        {
            SrgsOneOf oneOfElements = new SrgsOneOf();
            foreach (String listEntry in list)
            {
                oneOfElements.Add(new SrgsItem(listEntry));
            }

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

            return rule;
        }
Beispiel #29
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);
        }
Beispiel #30
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 #31
0
 SrgsRuleRef SrgsActionsFromCapabilities(DeviceCapabilities caps, SrgsDocument doc)
 {
     SrgsRule r;
     if (caps_rules.Keys.Contains(caps.Caps))
     {
         r = caps_rules[caps.Caps];
     }
     else
     {
         List<string> capsAsString = caps.Actions;
         if (capsAsString == null || capsAsString.Count == 0) return null;
         SrgsOneOf actions = new SrgsOneOf();
         foreach (string s in capsAsString)
         {
             SrgsItem si = new SrgsItem(s);
             //si.Add(new SrgsSemanticInterpretationTag(" out = \"" + s + "\";"));
             si.Add(new SrgsNameValueTag("action", s));
             actions.Add(si);
         }
         r = new SrgsRule(AudioRecog_SAPI.SrgsCleanupID("caps_" + caps.CapsAsIntString), actions);
         doc.Rules.Add(r);
         caps_rules.Add(caps.Caps, r);
     }
     //return new SrgsRuleRef(r, "action");
     return new SrgsRuleRef(r);
 }
Beispiel #32
0
 public void initialize_page(string name, string url)
 {
     choices.Add(new SrgsItem(name));
     pages.Add(name, url);
 }
Beispiel #33
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 #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 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 #35
0
        /// <summary>
        /// throughout the algorithm's passes the grammar is updated with the received prefix phonemes
        /// </summary>
        /// <param name="prefixes">phonemes to be added to the front</param>
        /// <param name="doc">the previous grammar</param>
        /// <param name="passNum">the current pass number</param>
        /// <param name="preReadPath">location of an additional grammar file which is smaller to improve computation time</param>
        /// <returns>
        /// an updated grammar
        /// </returns>
        public static SrgsDocument updateGrammar(List <String> prefixes, SrgsDocument doc, int passNum)
        {
            Console.WriteLine("Prefixing grammar with phonemes from pass {0}...", passNum - 1);
            Debug.WriteLine(String.Format("Grammar language is {0}", doc.Culture));

            // read prefix wildcard from text file
            //(this is a smaller wildcard with just 1 and 2 phonemes which, with the prefix, makes up the first word of superwildcard grammar)

            //string prefixWildcardFile = lex4all.Properties.Resources.en_US_prefixwildcard;
            //string[] words = prefixWildcardFile.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            string[] words = prefixWildcardFile.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
            Debug.WriteLine(String.Format("After split, words has length {0}", words.Length));

            // set up basic wildcard oneof
            SrgsOneOf prefixOneOf = new SrgsOneOf();

            // make grammar item/token for prefix + each wildcard "word"
            foreach (string prefix in prefixes)
            {
                SrgsToken prefixToken = new SrgsToken(prefix.Replace(" ", "."));
                prefixToken.Pronunciation = prefix;
                SrgsItem prefixItem = new SrgsItem();
                prefixItem.Add(prefixToken);
                prefixOneOf.Add(prefixItem);
                foreach (string word in words)
                {
                    if (word.Contains("\n"))
                    {
                        Console.WriteLine("Found a newline in line {0}", word);
                        break;
                    }
                    string    pron      = prefix + " " + word;
                    string    text      = pron.Replace(" ", ".");
                    SrgsToken thisToken = new SrgsToken(text);
                    thisToken.Pronunciation = pron;
                    SrgsItem thisItem = new SrgsItem();
                    thisItem.Add(thisToken);
                    prefixOneOf.Add(thisItem);
                }
            }

            // create grammar rules
            SrgsRule prefixRule = new SrgsRule("Prefixes" + (passNum - 1).ToString());

            prefixRule.Scope = SrgsRuleScope.Public;
            SrgsItem prefItem = new SrgsItem(prefixOneOf);

            prefixRule.Elements.Add(prefItem);
            SrgsRuleRef prefRef = new SrgsRuleRef(prefixRule);

            SrgsRule    wildRule = doc.Rules["Wildcard"];
            SrgsRuleRef wildRef  = new SrgsRuleRef(wildRule);

            SrgsRule newSuperRule = new SrgsRule("SuperWildcard" + (passNum - 1).ToString());

            newSuperRule.Scope = SrgsRuleScope.Public;
            newSuperRule.Elements.Add(new SrgsItem(prefRef));
            SrgsItem newSuperItem = new SrgsItem(0, 9);

            newSuperItem.Add(wildRef);
            newSuperRule.Elements.Add(newSuperItem);

            // update document by adding prefixed rules
            doc.Rules.Clear();
            doc.Rules.Add(new SrgsRule[] { newSuperRule, prefixRule, wildRule });
            doc.Root = newSuperRule;

            // report
            Console.WriteLine("Done.");

            return(doc);
        }
Beispiel #36
0
        /// <summary>
        /// is used by the algorithm to build the super wildcard grammar
        /// </summary>
        /// <param name="readPath">
        /// location of the wildcard.txt file which contains all possible phoneme combinations
        /// </param>
        /// <returns>
        /// a document object representing the grammar
        /// </returns>
        public static SrgsDocument getInitialGrammar()
        {
            Console.WriteLine("Building initial grammar...");

            // set up basic wildcard rule
            SrgsOneOf wildOneOf = new SrgsOneOf();

            // read phoneme wildcard from text file. all combinations are then added to the basic rule
            // string[] sfdasf = System.IO.File.ReadAllLines(readPath);
            // StreamReader rd = new StreamReader(readPath);
            // string allWords = rd.ReadToEnd();
            //string wildcardFile = lex4all.Properties.Resources.en_US_wildcard;

            //string[] words = wildcardFile.Split(new string[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
            string[] words = wildcardFile.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
            Debug.WriteLine(String.Format("After split, words has length {0}", words.Length));
            foreach (string word in words)
            {
                if (word.Contains("\n"))
                {
                    Debug.WriteLine(String.Format("Found a newline in line {0}", word));
                    break;
                }
                else
                {
                    // make grammar item/token for each wildcard "word"
                    string    pron      = word;
                    string    text      = word.Replace(" ", ".");
                    SrgsToken thisToken = new SrgsToken(text);
                    thisToken.Pronunciation = pron;
                    SrgsItem thisItem = new SrgsItem();
                    thisItem.Add(thisToken);
                    wildOneOf.Add(thisItem);
                    Debug.WriteLine(String.Format("Wrote {0} to wildOneOf", word));
                }
            }

            // create grammar rules
            SrgsRule wildRule = new SrgsRule("Wildcard");

            wildRule.Scope = SrgsRuleScope.Public;
            wildRule.Elements.Add(wildOneOf);
            SrgsRule superRule = new SrgsRule("SuperWildcard");

            superRule.Scope = SrgsRuleScope.Public;
            SrgsRuleRef wildRef   = new SrgsRuleRef(wildRule);
            SrgsItem    superItem = new SrgsItem(0, 10);

            superItem.Add(wildRef);
            superRule.Elements.Add(superItem);

            // create document and add rules
            SrgsDocument gramDoc = new SrgsDocument();

            //Dynamically allocate the  correct phonetic alphabet depending on the language of choice
            if (EngineControl.Language.Equals("zh-CN") || EngineControl.Language.Equals("de-DE"))
            {
                gramDoc.PhoneticAlphabet = SrgsPhoneticAlphabet.Sapi;
                phoneticAlphabet         = "sapi";
            }
            else if (EngineControl.Language.Equals("ja-JP"))
            {
                gramDoc.PhoneticAlphabet = SrgsPhoneticAlphabet.Ipa;
                phoneticAlphabet         = "ipa";
            }
            else

            {
                gramDoc.PhoneticAlphabet = SrgsPhoneticAlphabet.Ups; // This is the default phonetic alphabet setting
                phoneticAlphabet         = "ups";
            }


            gramDoc.Culture = new System.Globalization.CultureInfo(EngineControl.Language);
            gramDoc.Rules.Add(new SrgsRule[] { superRule, wildRule });
            gramDoc.Root = superRule;

            // report
            Console.WriteLine(String.Format("Done. Grammar language is {0}", gramDoc.Culture));

            // output initial grammar
            Console.WriteLine("");
            return(gramDoc);
        }
        /// <summary>
        /// Create Grammar of a given skill from the config file.
        /// </summary>
        /// <param name="skill"></param>
        /// <returns></returns>
        private Grammar[] CreateSkillGrammar(Skill skill)
        {
            Grammar[] grammars = new Grammar[2];

            SrgsItem[] srgsSkillValues     = new SrgsItem[skill.Values.Count];
            SrgsItem[] srgsDtmfSkillValues = new SrgsItem[skill.Values.Count];

            //iterate over skill values.
            for (int i = 0; i < skill.Values.Count; i++)
            {
                //set the recognition result equal to the category name.
                SrgsSemanticInterpretationTag tag = new SrgsSemanticInterpretationTag(
                    "$._value = \"" + skill.Values[i] + "\";"
                    );

                //one-of element to allow the user to enter the category name, or a number
                //representing the one-based position in the list of the category.
                SrgsOneOf categoryOneOf = new SrgsOneOf();
                //match the category name.
                categoryOneOf.Add(new SrgsItem(skill.Values[i]));
                //match the one-based index of the category in the list.
                categoryOneOf.Add(new SrgsItem((i + 1).ToString()));

                //wrap it all up with an item tag
                srgsSkillValues[i] = new SrgsItem(categoryOneOf);
                srgsSkillValues[i].Add(tag);

                srgsDtmfSkillValues[i] = new SrgsItem(i + 1);
                srgsDtmfSkillValues[i].Add(tag);
            }

            //one-of that wraps the list of items containing the category one-of elements.
            SrgsOneOf oneOf = new SrgsOneOf(srgsSkillValues);
            //root rule element.
            SrgsRule categoryRule = new SrgsRule(skill.Name.Replace(" ", ""), oneOf);

            categoryRule.Scope = SrgsRuleScope.Public;

            SrgsOneOf dtmfOneOf = new SrgsOneOf(srgsDtmfSkillValues);

            SrgsDocument grammarDoc = new SrgsDocument();

            //add and set the root rule
            grammarDoc.Rules.Add(categoryRule);
            grammarDoc.Root = categoryRule;

            //create the grammar object.
            Grammar grammar = new Grammar(grammarDoc);

            grammars[0] = grammar;


            SrgsDocument dtmfGrammarDoc = new SrgsDocument();

            dtmfGrammarDoc.Mode = SrgsGrammarMode.Dtmf;

            dtmfGrammarDoc.Rules.Add(categoryRule);
            dtmfGrammarDoc.Root = categoryRule;

            Grammar dtmfGrammar = new Grammar(dtmfGrammarDoc);

            grammars[1] = dtmfGrammar;

            return(grammars);
        }