private void GenerateRuleList(string semantic, string[] alternates, SrgsRuleRef subjectRef = null, DirectObject directObject = null) { SrgsOneOf commandAlternates = new SrgsOneOf(alternates); SrgsItem command = new SrgsItem(); if (subjectRef != null) { command.Add(new SrgsItem(subjectRef)); command.Add(new SrgsSemanticInterpretationTag("out.subject=rules.subject;")); } command.Add(commandAlternates); command.Add(new SrgsSemanticInterpretationTag("out.command=\"" + semantic + "\";")); if (directObject != null) { command.Add(directObject.RuleRef); command.Add(new SrgsSemanticInterpretationTag("out.directObject=rules." + directObject.RuleName + ";")); } Item = command; RuleList = new List <SrgsRule>(); SrgsRule rule = new SrgsRule(semantic); rule.Add(command); RuleList.Add(rule); RootRule = rule; }
/// <summary> /// Parse a ruleref /// </summary> private IRuleRef ParseRuleRef(SrgsRuleRef srgsRuleRef, IElement parent) { IRuleRef ruleRef = null; bool fSpecialRuleRef = true; if (srgsRuleRef == SrgsRuleRef.Null) { ruleRef = _parser.Null; } else if (srgsRuleRef == SrgsRuleRef.Void) { ruleRef = _parser.Void; } else if (srgsRuleRef == SrgsRuleRef.Garbage) { ruleRef = _parser.Garbage; } else { ruleRef = _parser.CreateRuleRef(parent, srgsRuleRef.Uri, srgsRuleRef.SemanticKey, srgsRuleRef.Params); fSpecialRuleRef = false; } if (fSpecialRuleRef) { _parser.InitSpecialRuleRef(parent, ruleRef); } ruleRef.PostParse(parent); return(ruleRef); }
private void GenerateRuleList(string semantic, string[] alternates, SrgsRuleRef subjectRef = null, DirectObject directObject = null) { SrgsOneOf commandAlternates = new SrgsOneOf(alternates); SrgsItem command = new SrgsItem(); if (subjectRef != null) { command.Add(new SrgsItem(subjectRef)); command.Add(new SrgsSemanticInterpretationTag("out.subject=rules.subject;")); } command.Add(commandAlternates); command.Add(new SrgsSemanticInterpretationTag("out.command=\"" + semantic + "\";")); if (directObject != null) { command.Add(directObject.RuleRef); command.Add(new SrgsSemanticInterpretationTag("out.directObject=rules." + directObject.RuleName + ";")); } Item = command; RuleList = new List<SrgsRule>(); SrgsRule rule = new SrgsRule(semantic); rule.Add(command); RuleList.Add(rule); RootRule = rule; }
public void Add(SrgsRuleRef rootRuleRef, IList<SrgsRule> rules) { if (rootRuleRef != null) this.rootRuleRefs.Add(new SrgsItem(rootRuleRef)); if (rules != null) { foreach (var r in rules) this.rules.Add(r); } }
public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs) { var numbers = new SrgsOneOf( new SrgsItem( new SrgsItem("zero"), new SrgsSemanticInterpretationTag("out = 0") ), new SrgsItem( new SrgsItem("one"), new SrgsSemanticInterpretationTag("out = 1") ), new SrgsItem( new SrgsItem("two"), new SrgsSemanticInterpretationTag("out = 2") ), new SrgsItem( new SrgsItem("three"), new SrgsSemanticInterpretationTag("out = 3") ), new SrgsItem( new SrgsItem("four"), new SrgsSemanticInterpretationTag("out = 4") ), new SrgsItem( new SrgsItem("five"), new SrgsSemanticInterpretationTag("out = 5") ), new SrgsItem( new SrgsItem("six"), new SrgsSemanticInterpretationTag("out = 6") ), new SrgsItem( new SrgsItem("seven"), new SrgsSemanticInterpretationTag("out = 7") ), new SrgsItem( new SrgsItem("eight"), new SrgsSemanticInterpretationTag("out = 8") ), new SrgsItem( new SrgsItem("nine"), new SrgsSemanticInterpretationTag("out = 9") ) ); var numberRule = new SrgsRule("Number", numbers); refs["Number"] = new SrgsRuleRef(numberRule); return new Tuple<SrgsRuleRef, IList<SrgsRule>>( null, new List<SrgsRule> { numberRule } ); }
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 } ); }
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; }
public override Tuple<SrgsRuleRef, IList<SrgsRule>> GetGrammar(IDictionary<string, SrgsRuleRef> refs) { var rule = new SrgsRule("YesOrNo", new SrgsOneOf( new SrgsItem( new SrgsItem("yes"), new SrgsSemanticInterpretationTag("out = 'yes'") ), new SrgsItem( new SrgsItem("no"), new SrgsSemanticInterpretationTag("out = 'no'") ) ) ); refs["YesOrNo"] = new SrgsRuleRef(rule); return new Tuple<SrgsRuleRef, IList<SrgsRule>>( null, new List<SrgsRule> { rule } ); }
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; }
public Command(string semantic, string[] alternates, IEnumerable<OutputBase> keyList, SrgsRuleRef subjectRef, DirectObject directObject) { GenerateRuleList(semantic, alternates, subjectRef, directObject); GenerateKeyLookup(semantic, keyList, directObject); }
/// <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); }
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; }
public Command(string semantic, string[] alternates, IEnumerable <OutputBase> keyList, SrgsRuleRef subjectRef, DirectObject directObject) { GenerateRuleList(semantic, alternates, subjectRef, directObject); GenerateKeyLookup(semantic, keyList, directObject); }
/// <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); }
public Command(string semantic, string[] alternates, ushort[] keyList, SrgsRuleRef subjectRef, DirectObject directObject) { GenerateRuleList(semantic, alternates, subjectRef, directObject); GenerateKeyLookup(semantic, keyList, directObject); }
public Command(string semantic, string[] alternates, uint[] keyList, SrgsRuleRef subjectRef, DirectObject directObject) { GenerateRuleList(semantic, alternates, subjectRef, directObject); GenerateKeyLookup(semantic, keyList, directObject); }
private void LoadGrammarForEngineAndPlugins() { var memoryStream = new MemoryStream(Resources.mainDocument); var xmlReader = new XmlTextReader(memoryStream); var mainDocument = new SrgsDocument(xmlReader); //Rule for plugins var pluginRules = new SrgsRule("plugin"); var choices = new SrgsOneOf(); pluginRules.Add(choices); //Main rule (entry point for speech) var mainRule = new SrgsRule("main"); var systemName = new SrgsItem(_config.SpeechRecognitionElement.Name); var speakAnything = SrgsRuleRef.Garbage; var refPluginRules = new SrgsRuleRef(pluginRules); SrgsItem executeCommandRule = null; if (!String.IsNullOrWhiteSpace(_config.SpeechRecognitionElement.ExecuteCommandPhrase)) executeCommandRule = new SrgsItem(_config.SpeechRecognitionElement.ExecuteCommandPhrase); //Genere main Rule mainRule.Add(systemName); mainRule.Add(speakAnything); mainRule.Add(refPluginRules); mainRule.Add(new SrgsSemanticInterpretationTag("out=rules.plugin;")); mainRule.Add(speakAnything); if (!String.IsNullOrWhiteSpace(_config.SpeechRecognitionElement.ExecuteCommandPhrase)) mainRule.Add(executeCommandRule); mainRule.Scope = SrgsRuleScope.Private; //Here you should add choices to the document per Plugin foreach (var plugin in _plugins) { plugin.AddGrammarRules(mainDocument.Rules, choices); } mainDocument.Rules.Add(mainRule); mainDocument.Rules.Add(pluginRules); mainDocument.Root = mainRule; mainDocument.Culture = _speechRecognitionEngine.RecognizerInfo.Culture; mainDocument.Mode = SrgsGrammarMode.Voice; mainDocument.PhoneticAlphabet = SrgsPhoneticAlphabet.Sapi; using (var textWriter = new StringWriter()) { using (var xmlWriter = new XmlTextWriter(textWriter)) { mainDocument.WriteSrgs(xmlWriter); _log.Info(String.Format("Grammar for the recognition engine in the culture {0}, is {1}", _speechRecognitionEngine.RecognizerInfo.Culture.TwoLetterISOLanguageName, textWriter)); } } _speechRecognitionEngine.LoadGrammar(new Grammar(mainDocument)); }
public Command(string semantic, string[] alternates, string instruction, SrgsRuleRef subjectRef) { GenerateRuleList(semantic, alternates, subjectRef); GenerateInstruction(semantic, instruction); }
private void Form2_Load(object sender, EventArgs e) { recEngine = new SpeechRecognitionEngine(); /*Reglas para Select*/ SrgsRule selectRule = new SrgsRule("selectRule"); SrgsOneOf selectList = new SrgsOneOf(new string[] { "selecciona", "traeme", "busca", "obten", "muestrame", "muestra", "imprime", "imprimir" }); selectRule.Add(selectList); /*Reglas para numero de registros * todos, los = all * */ SrgsRule allRule = new SrgsRule("allRule"); SrgsOneOf allList = new SrgsOneOf(new string[] { "los", "todos los" }); allRule.Add(allList); /*nombre de la tabla*/ SrgsRule tablaRule = new SrgsRule("tablaRule"); SrgsOneOf tablaList = new SrgsOneOf(new string[] { "empleados" }); tablaRule.Add(tablaList); SrgsRule whereRule = new SrgsRule("whereRule"); SrgsOneOf whereList = new SrgsOneOf(new string[] { "igual" }); allRule.Add(allList); /*La referencia con una root ruke hace que que las reglas se unana y tengan que tener un * orden especifico, quitar o comentar la regla principal y quirar del la creacion del documenteo */ /*Regla principal*/ SrgsRule mainRule = new SrgsRule("mainRule"); mainRule.Scope = SrgsRuleScope.Public; /*Unir los select con los all*/ // Create the "Subject" and "Verb" rule references and add them to the SrgsDocument. SrgsRuleRef selectRef = new SrgsRuleRef(selectRule, "theSelect"); mainRule.Add(selectRef); SrgsRuleRef allRef = new SrgsRuleRef(allRule, "theAll"); mainRule.Add(allRef); SrgsRuleRef tablaRef = new SrgsRuleRef(tablaRule, "theTabla"); mainRule.Add(tablaRef); //Creando el documento con las reglas SrgsDocument newDocumento = new SrgsDocument(); newDocumento.Rules.Add(new SrgsRule[] { mainRule, selectRule, allRule, tablaRule }); newDocumento.Root = mainRule; //Agragar gramatica al engine Grammar grammar = new Grammar(newDocumento, "mainRule"); recEngine.LoadGrammar(grammar); //Crear XML System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("C:\\Users\\Misael\\Documents\\ejemplo.xml"); newDocumento.WriteSrgs(writer); writer.Close(); // Attach a handler for the SpeechRecognized event. recEngine.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(recEngine_SpeechRecognized); // Configure the input to the SpeechRecognitionEngine object. recEngine.SetInputToDefaultAudioDevice(); // Start asynchronous recognition. recEngine.RecognizeAsync(); }
static void Main(string[] args) { // Create the "Subject" rule. SrgsRule subjRule = new SrgsRule("id_Subject"); SrgsOneOf subjList = new SrgsOneOf(new string[] { "I", "you", "he", "she", "Tom", "Mary" }); subjRule.Add(subjList); // Create the "Verb" rule. SrgsRule verbRule = new SrgsRule("id_Verb"); SrgsOneOf verbList = new SrgsOneOf(new string[] { "ate", "bought", "saw", "sold", "wanted" }); verbRule.Add(verbList); // Create the "Object" rule. SrgsRule objRule = new SrgsRule("id_Object"); SrgsOneOf objList = new SrgsOneOf(new string[] { "apple", "banana", "pear", "peach", "melon" }); objRule.Add(objList); // Create the root rule. // In this grammar, the root rule contains references to the other three rules. SrgsRule rootRule = new SrgsRule("Subj_Verb_Obj"); rootRule.Scope = SrgsRuleScope.Public; // Create the "Subject" and "Verb" rule references and add them to the SrgsDocument. SrgsRuleRef subjRef = new SrgsRuleRef(subjRule, "theSubject"); rootRule.Add(subjRef); SrgsRuleRef verbRef = new SrgsRuleRef(verbRule, "theVerb"); rootRule.Add(verbRef); // Add logic to handle articles: "the", "a", "and", occurring zero or one time. SrgsOneOf articles = new SrgsOneOf( new SrgsItem[] { new SrgsItem(0, 1, "the"), new SrgsItem(0, 1, "a"), new SrgsItem(0, 1, "an") } ); rootRule.Add(articles); // Create the "Object" rule reference and add it to the SrgsDocument. SrgsRuleRef objRef = new SrgsRuleRef(objRule, "theObject"); rootRule.Add(objRef); // Create an SrgsDocument object that contains all four rules. SrgsDocument document = new SrgsDocument(); document.Rules.Add(rootRule, subjRule, verbRule, objRule); // Set "rootRule" as the root rule of the grammar. document.Root = rootRule; // Create a Grammar object, initializing it with the root rule. Grammar g = new Grammar(document, rootRule.Id); // Create a new SpeechRecognizer instance. SpeechRecognizer sr = new SpeechRecognizer(); // Load the Grammar object into the recognizer. sr.LoadGrammar(g); // Produce an XML file that contains the grammar. System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("srgsDocument.xml"); document.WriteSrgs(writer); writer.Close(); sr.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(sr_SpeechRecognized); while (true) { Console.Read(); } }
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); }
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); }
public Command(string semantic, string[] alternates, uint[] keyList, SrgsRuleRef subjectRef) { GenerateRuleList(semantic, alternates, subjectRef); GenerateKeyLookup(semantic, keyList); }