private JSGFGrammar.GrammarGraph processRuleSequence(JSGFRuleSequence jsgfruleSequence) { GrammarNode grammarNode = null; GrammarNode grammarNode2 = null; this.logger.fine(new StringBuilder().append("parseRuleSequence: ").append(jsgfruleSequence).toString()); List rules = jsgfruleSequence.getRules(); GrammarNode grammarNode3 = null; for (int i = 0; i < rules.size(); i++) { JSGFRule rule = (JSGFRule)rules.get(i); JSGFGrammar.GrammarGraph grammarGraph = this.processRule(rule); if (i == 0) { grammarNode = grammarGraph.getStartNode(); } if (i == rules.size() - 1) { grammarNode2 = grammarGraph.getEndNode(); } if (i > 0) { grammarNode3.add(grammarGraph.getStartNode(), 0f); } grammarNode3 = grammarGraph.getEndNode(); } return(new JSGFGrammar.GrammarGraph(this, grammarNode, grammarNode2)); }
private void addToCurrent(JSGFRule jsgfrule, JSGFRule rule) { if (jsgfrule == null) { return; } if (this.currentRule == null) { this.currentRule = jsgfrule; return; } if (this.currentRule is JSGFRuleSequence) { JSGFRuleSequence jsgfruleSequence = (JSGFRuleSequence)this.currentRule; jsgfruleSequence.append(rule); jsgfrule.parent = this.currentRule; this.currentRule = jsgfrule; } else if (this.currentRule is JSGFRuleAlternatives) { JSGFRuleAlternatives jsgfruleAlternatives = (JSGFRuleAlternatives)this.currentRule; jsgfruleAlternatives.append(rule); jsgfrule.parent = this.currentRule; this.currentRule = jsgfrule; } }
private void AddToCurrent(JSGFRule newRule, JSGFRule topRule) { if (newRule == null) { return; } if (_currentRule == null) { _currentRule = newRule; return; } if (_currentRule is JSGFRuleSequence) { JSGFRuleSequence ruleSequence = (JSGFRuleSequence)_currentRule; ruleSequence.Append(topRule); newRule.Parent = _currentRule; _currentRule = newRule; } else if (_currentRule is JSGFRuleAlternatives) { JSGFRuleAlternatives ruleAlternatives = (JSGFRuleAlternatives)_currentRule; ruleAlternatives.Append(topRule); newRule.Parent = _currentRule; _currentRule = newRule; } }
/** * Parses the given RuleSequence into a network of GrammarNodes. * * @param ruleSequence * the RuleSequence to parse * @return the first and last GrammarNodes of the network */ private GrammarGraph ProcessRuleSequence(JSGFRuleSequence ruleSequence) { GrammarNode startNode = null; GrammarNode endNode = null; this.LogInfo("parseRuleSequence: " + ruleSequence); List <JSGFRule> rules = ruleSequence.Rules; GrammarNode lastGrammarNode = null; // expand and connect each rule in the sequence serially for (int i = 0; i < rules.Count; i++) { JSGFRule rule = rules[i]; GrammarGraph newNodes = ProcessRule(rule); // first node if (i == 0) { startNode = newNodes.StartNode; } // last node if (i == (rules.Count - 1)) { endNode = newNodes.EndNode; } if (i > 0) { lastGrammarNode.Add(newNodes.StartNode, 0.0f); } lastGrammarNode = newNodes.EndNode; } return(new GrammarGraph(startNode, endNode, this)); }
public override void startElement(string uri, string localName, string qName, Attributes attributes) { JSGFRule jsgfrule = null; JSGFRule jsgfrule2 = null; this.logger.fine(new StringBuilder().append("Starting element ").append(qName).toString()); if (String.instancehelper_equals(qName, "rule")) { string value = attributes.getValue("id"); if (value != null) { jsgfrule = new JSGFRuleSequence(new ArrayList()); this.__topRuleMap.put(value, (JSGFRuleSequence)jsgfrule); jsgfrule2 = (JSGFRuleSequence)jsgfrule; } } if (String.instancehelper_equals(qName, "item")) { string value = attributes.getValue("repeat"); if (value != null) { jsgfrule = new JSGFRuleSequence(new ArrayList()); JSGFRuleCount jsgfruleCount = new JSGFRuleCount((JSGFRuleSequence)jsgfrule, 3); jsgfrule2 = jsgfruleCount; } else { jsgfrule = new JSGFRuleSequence(new ArrayList()); jsgfrule2 = (JSGFRuleSequence)jsgfrule; } } if (String.instancehelper_equals(qName, "one-of")) { jsgfrule = new JSGFRuleAlternatives(new ArrayList()); jsgfrule2 = (JSGFRuleAlternatives)jsgfrule; } this.addToCurrent(jsgfrule, jsgfrule2); }
public override void StartElement(URL uri, string localName, string qName, Attributes attributes) { JSGFRule newRule = null; JSGFRule topRule = null; this.LogInfo("Starting element " + qName); if (qName.Equals("rule")) { String id = attributes.getValue("id"); if (id != null) { newRule = new JSGFRuleSequence(new List <JSGFRule>()); TopRuleMap.Put(id, newRule); topRule = newRule; } } if (qName.Equals("item")) { String repeat = attributes.getValue("repeat"); if (repeat != null) { newRule = new JSGFRuleSequence(new List <JSGFRule>()); JSGFRuleCount ruleCount = new JSGFRuleCount(newRule, JSGFRuleCount.OnceOrMore); topRule = ruleCount; } else { newRule = new JSGFRuleSequence(new List <JSGFRule>()); topRule = newRule; } } if (qName.Equals("one-of")) { newRule = new JSGFRuleAlternatives(new List <JSGFRule>()); topRule = newRule; } AddToCurrent(newRule, topRule); }