Ejemplo n.º 1
0
 public JSGFRuleState(JSGFRule rule, bool isEnabled, bool isPublic)
 {
     this.rule       = rule;
     this.IsPublic   = isPublic;
     this._isEnabled = isEnabled;
     Samples         = new List <String>();
 }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        /**
         * Parses the given RuleAlternatives into a network of GrammarNodes.
         *
         * @param ruleAlternatives
         *            the RuleAlternatives to parse
         * @return a grammar graph
         */
        private GrammarGraph ProcessRuleAlternatives(JSGFRuleAlternatives ruleAlternatives)
        {
            this.LogInfo("parseRuleAlternatives: " + ruleAlternatives);
            GrammarGraph result = new GrammarGraph(this);

            List <JSGFRule> rules   = ruleAlternatives.GetRules();
            List <Float>    weights = GetNormalizedWeights(ruleAlternatives.GetWeights());

            // expand each alternative, and connect them in parallel
            for (int i = 0; i < rules.Count; i++)
            {
                JSGFRule rule   = rules[i];
                float    weight = 0.0f;
                if (weights != null)
                {
                    weight = weights[i];
                }
                this.LogInfo("Alternative: " + rule);
                GrammarGraph newNodes = ProcessRule(rule);
                result.StartNode.Add(newNodes.StartNode, weight);
                newNodes.EndNode.Add(result.EndNode, 0.0f);
            }

            return(result);
        }
Ejemplo n.º 4
0
        private JSGFGrammar.GrammarGraph processRuleTag(JSGFRuleTag jsgfruleTag)
        {
            this.logger.fine(new StringBuilder().append("parseRuleTag: ").append(jsgfruleTag).toString());
            JSGFRule rule = jsgfruleTag.getRule();

            return(this.processRule(rule));
        }
Ejemplo n.º 5
0
        /**
         * ruleForJSGF
         */
        public static JSGFRule RuleForJSGF(String text)
        {
            JSGFRule r = null;

            try
            {
                StringReader sread = new StringReader(text);
                if (_parser == null)
                {
                    _parser = new JSGFParser(sread);
                }
                else
                {
                    _parser.ReInit(sread);
                }
                r = _parser.Alternatives();
                // Console.WriteLine("JSGF Parser Version " + version
                //                    + ":  JSGF RHS parsed successfully.");
            }
            catch (ParseException e)
            {
                Console.WriteLine("JSGF Parser Version " + Version + ":  Encountered errors during parse.");
            }
            return(r);
        }
Ejemplo n.º 6
0
        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;
            }
        }
Ejemplo n.º 7
0
        /**
         * Parses the given RuleTag into a network GrammarNodes.
         *
         * @param ruleTag
         *            the RuleTag to parse
         * @return the first and last GrammarNodes of the network
         */
        private GrammarGraph ProcessRuleTag(JSGFRuleTag ruleTag)
        {
            this.LogInfo("parseRuleTag: " + ruleTag);
            JSGFRule rule = ruleTag.Rule;

            return(ProcessRule(rule));
        }
Ejemplo n.º 8
0
 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;
     }
 }
Ejemplo n.º 9
0
 public JSGFRuleState(JSGFRuleGrammar jsgfruleGrammar, JSGFRule jsgfrule, bool flag, bool flag2)
 {
     this.this_0    = jsgfruleGrammar;
     this.rule      = jsgfrule;
     this.isPublic  = flag2;
     this.isEnabled = flag;
     this.samples   = new ArrayList();
 }
Ejemplo n.º 10
0
        public override void EndElement(URL uri, string localName, string qName)
        {
            this.LogInfo("Ending element " + qName);

            if (qName.Equals("item") || qName.Equals("one-of") || qName.Equals("rule"))
            {
                _currentRule = _currentRule.Parent;
            }
        }
Ejemplo n.º 11
0
        /**
         * Parses the given RuleName into a network of GrammarNodes.
         *
         * @param initialRuleName
         *            the RuleName rule to parse
         * @return a grammar graph
         */
        private GrammarGraph ProcessRuleName(JSGFRuleName initialRuleName)
        {
            this.LogInfo("parseRuleName: " + initialRuleName);
            GrammarGraph result = RuleStack.Contains(initialRuleName.GetRuleName());

            if (result != null)
            { // its a recursive call
                return(result);
            }
            else
            {
                result = new GrammarGraph(this);
                RuleStack.Push(initialRuleName.GetRuleName(), result);
            }
            JSGFRuleName ruleName = _ruleGrammar.Resolve(initialRuleName);

            if (ruleName == JSGFRuleName.Null)
            {
                result.StartNode.Add(result.EndNode, 0.0f);
            }
            else if (ruleName == JSGFRuleName.Void)
            {
                // no connection for void
            }
            else
            {
                if (ruleName == null)
                {
                    throw new JSGFGrammarException("Can't resolve "
                                                   + initialRuleName + " g "
                                                   + initialRuleName.GetFullGrammarName());
                }
                JSGFRuleGrammar rg = Manager.RetrieveGrammar(ruleName
                                                             .GetFullGrammarName());
                if (rg == null)
                {
                    throw new JSGFGrammarException("Can't resolve grammar name "
                                                   + ruleName.GetFullGrammarName());
                }

                JSGFRule rule = rg.GetRule(ruleName.GetSimpleRuleName());
                if (rule == null)
                {
                    throw new JSGFGrammarException("Can't resolve rule: "
                                                   + ruleName.GetRuleName());
                }
                GrammarGraph ruleResult = ProcessRule(rule);
                if (result != ruleResult)
                {
                    result.StartNode.Add(ruleResult.StartNode, 0.0f);
                    ruleResult.EndNode.Add(result.EndNode, 0.0f);
                }
            }
            RuleStack.Pop();
            return(result);
        }
Ejemplo n.º 12
0
        /**
         * Commit changes to all loaded grammars and all changes of grammar since
         * the last commitChange
         *
         * @throws JSGFGrammarParseException
         * @throws JSGFGrammarException
         */
        public virtual void CommitChanges()
        {
            try
            {
                if (LoadGrammar)
                {
                    if (Manager == null)
                    {
                        GetGrammarManager();
                    }
                    _ruleGrammar = LoadNamedGrammar(GrammarName);
                    LoadImports(_ruleGrammar);
                    LoadGrammar = false;
                }

                Manager.LinkGrammars();
                RuleStack = new RuleStack();
                NewGrammar();

                FirstNode = CreateGrammarNode("<sil>");
                GrammarNode finalNode = CreateGrammarNode("<sil>");
                finalNode.SetFinalNode(true);

                // go through each rule and create a network of GrammarNodes
                // for each of them

                foreach (String ruleName in _ruleGrammar.GetRuleNames())
                {
                    if (_ruleGrammar.IsRulePublic(ruleName))
                    {
                        String       fullName        = GetFullRuleName(ruleName);
                        GrammarGraph publicRuleGraph = new GrammarGraph(this);
                        RuleStack.Push(fullName, publicRuleGraph);
                        JSGFRule     rule  = _ruleGrammar.GetRule(ruleName);
                        GrammarGraph graph = ProcessRule(rule);
                        RuleStack.Pop();

                        FirstNode.Add(publicRuleGraph.StartNode, 0.0f);
                        publicRuleGraph.EndNode.Add(finalNode, 0.0f);
                        publicRuleGraph.StartNode.Add(graph.StartNode,
                                                      0.0f);
                        graph.EndNode.Add(publicRuleGraph.EndNode, 0.0f);
                    }
                }
                PostProcessGrammar();
                if (Logger.Level == LogLevel.All)
                {
                    DumpGrammar();
                }
            }
            catch (UriFormatException mue)
            {
                throw new IOException("bad base grammar URL " + BaseUrl + ' ' + mue);
            }
        }
Ejemplo n.º 13
0
 public virtual void commitChanges()
 {
     try
     {
         if (this.loadGrammar)
         {
             if (this.manager == null)
             {
                 this.getGrammarManager();
             }
             this.ruleGrammar = this.loadNamedGrammar(this.grammarName);
             this.loadImports(this.ruleGrammar);
             this.loadGrammar = false;
         }
         this.manager.linkGrammars();
         this.__ruleStack = new JSGFGrammar.RuleStack(this);
         this.newGrammar();
         this.firstNode = this.createGrammarNode("<sil>");
         GrammarNode grammarNode = this.createGrammarNode("<sil>");
         grammarNode.setFinalNode(true);
         Iterator iterator = this.ruleGrammar.getRuleNames().iterator();
         while (iterator.hasNext())
         {
             string text = (string)iterator.next();
             if (this.ruleGrammar.isRulePublic(text))
             {
                 string fullRuleName = this.getFullRuleName(text);
                 JSGFGrammar.GrammarGraph grammarGraph = new JSGFGrammar.GrammarGraph(this);
                 this.__ruleStack.push(fullRuleName, grammarGraph);
                 JSGFRule rule = this.ruleGrammar.getRule(text);
                 JSGFGrammar.GrammarGraph grammarGraph2 = this.processRule(rule);
                 this.__ruleStack.pop();
                 this.firstNode.add(grammarGraph.getStartNode(), 0f);
                 grammarGraph.getEndNode().add(grammarNode, 0f);
                 grammarGraph.getStartNode().add(grammarGraph2.getStartNode(), 0f);
                 grammarGraph2.getEndNode().add(grammarGraph.getEndNode(), 0f);
             }
         }
         this.postProcessGrammar();
         if (this.logger.isLoggable(Level.FINEST))
         {
             this.dumpGrammar();
         }
     }
     catch (MalformedURLException ex)
     {
         throw new IOException(new StringBuilder().append("bad base grammar URL ").append(this.baseURL).append(' ').append(ex).toString(), ex);
     }
 }
Ejemplo n.º 14
0
        private JSGFGrammar.GrammarGraph processRuleName(JSGFRuleName jsgfruleName)
        {
            this.logger.fine(new StringBuilder().append("parseRuleName: ").append(jsgfruleName).toString());
            JSGFGrammar.GrammarGraph grammarGraph = this.__ruleStack.contains(jsgfruleName.getRuleName());
            if (grammarGraph != null)
            {
                return(grammarGraph);
            }
            grammarGraph = new JSGFGrammar.GrammarGraph(this);
            this.__ruleStack.push(jsgfruleName.getRuleName(), grammarGraph);
            JSGFRuleName jsgfruleName2 = this.ruleGrammar.resolve(jsgfruleName);

            if (jsgfruleName2 == JSGFRuleName.__NULL)
            {
                grammarGraph.getStartNode().add(grammarGraph.getEndNode(), 0f);
            }
            else if (jsgfruleName2 != JSGFRuleName.__VOID)
            {
                if (jsgfruleName2 == null)
                {
                    string message = new StringBuilder().append("Can't resolve ").append(jsgfruleName).append(" g ").append(jsgfruleName.getFullGrammarName()).toString();

                    throw new JSGFGrammarException(message);
                }
                JSGFRuleGrammar jsgfruleGrammar = this.manager.retrieveGrammar(jsgfruleName2.getFullGrammarName());
                if (jsgfruleGrammar == null)
                {
                    string message2 = new StringBuilder().append("Can't resolve grammar name ").append(jsgfruleName2.getFullGrammarName()).toString();

                    throw new JSGFGrammarException(message2);
                }
                JSGFRule rule = jsgfruleGrammar.getRule(jsgfruleName2.getSimpleRuleName());
                if (rule == null)
                {
                    string message3 = new StringBuilder().append("Can't resolve rule: ").append(jsgfruleName2.getRuleName()).toString();

                    throw new JSGFGrammarException(message3);
                }
                JSGFGrammar.GrammarGraph grammarGraph2 = this.processRule(rule);
                if (grammarGraph != grammarGraph2)
                {
                    grammarGraph.getStartNode().add(grammarGraph2.getStartNode(), 0f);
                    grammarGraph2.getEndNode().add(grammarGraph.getEndNode(), 0f);
                }
            }
            this.__ruleStack.pop();
            return(grammarGraph);
        }
Ejemplo n.º 15
0
        public override void Characters(char[] buf, int offset, int len)
        {
            String item = new String(buf, offset, len).Trim();

            if (item.Length == 0)
            {
                return;
            }

            this.LogInfo("Processing text " + item);

            JSGFRuleToken newRule = new JSGFRuleToken(item);

            AddToCurrent(newRule, newRule);
            // Don't shift current
            _currentRule = newRule.Parent;
        }
Ejemplo n.º 16
0
        /**
         * Parses the given Rule into a network of GrammarNodes.
         *
         * @param rule
         *            the Rule to parse
         * @return a grammar graph
         */
        protected GrammarGraph ProcessRule(JSGFRule rule)
        {
            GrammarGraph result;

            if (rule != null)
            {
                this.LogInfo("parseRule: " + rule);
            }

            if (rule is JSGFRuleAlternatives)
            {
                result = ProcessRuleAlternatives((JSGFRuleAlternatives)rule);
            }
            else if (rule is JSGFRuleCount)
            {
                result = ProcessRuleCount((JSGFRuleCount)rule);
            }
            else if (rule is JSGFRuleName)
            {
                result = ProcessRuleName((JSGFRuleName)rule);
            }
            else if (rule is JSGFRuleSequence)
            {
                result = ProcessRuleSequence((JSGFRuleSequence)rule);
            }
            else if (rule is JSGFRuleTag)
            {
                result = ProcessRuleTag((JSGFRuleTag)rule);
            }
            else if (rule is JSGFRuleToken)
            {
                result = ProcessRuleToken((JSGFRuleToken)rule);
            }
            else
            {
                throw new ArgumentException("Unsupported Rule type: " + rule);
            }
            return(result);
        }
Ejemplo n.º 17
0
        private JSGFGrammar.GrammarGraph processRuleAlternatives(JSGFRuleAlternatives jsgfruleAlternatives)
        {
            this.logger.fine(new StringBuilder().append("parseRuleAlternatives: ").append(jsgfruleAlternatives).toString());
            JSGFGrammar.GrammarGraph grammarGraph = new JSGFGrammar.GrammarGraph(this);
            List rules             = jsgfruleAlternatives.getRules();
            List normalizedWeights = this.getNormalizedWeights(jsgfruleAlternatives.getWeights());

            for (int i = 0; i < rules.size(); i++)
            {
                JSGFRule jsgfrule       = (JSGFRule)rules.get(i);
                float    logProbability = 0f;
                if (normalizedWeights != null)
                {
                    logProbability = ((Float)normalizedWeights.get(i)).floatValue();
                }
                this.logger.fine(new StringBuilder().append("Alternative: ").append(jsgfrule).toString());
                JSGFGrammar.GrammarGraph grammarGraph2 = this.processRule(jsgfrule);
                grammarGraph.getStartNode().add(grammarGraph2.getStartNode(), logProbability);
                grammarGraph2.getEndNode().add(grammarGraph.getEndNode(), 0f);
            }
            return(grammarGraph);
        }
Ejemplo n.º 18
0
        protected internal virtual JSGFGrammar.GrammarGraph processRule(JSGFRule rule)
        {
            if (rule != null)
            {
                this.logger.fine(new StringBuilder().append("parseRule: ").append(rule).toString());
            }
            JSGFGrammar.GrammarGraph result;
            if (rule is JSGFRuleAlternatives)
            {
                result = this.processRuleAlternatives((JSGFRuleAlternatives)rule);
            }
            else if (rule is JSGFRuleCount)
            {
                result = this.processRuleCount((JSGFRuleCount)rule);
            }
            else if (rule is JSGFRuleName)
            {
                result = this.processRuleName((JSGFRuleName)rule);
            }
            else if (rule is JSGFRuleSequence)
            {
                result = this.processRuleSequence((JSGFRuleSequence)rule);
            }
            else if (rule is JSGFRuleTag)
            {
                result = this.processRuleTag((JSGFRuleTag)rule);
            }
            else
            {
                if (!(rule is JSGFRuleToken))
                {
                    string text = new StringBuilder().append("Unsupported Rule type: ").append(rule).toString();

                    throw new IllegalArgumentException(text);
                }
                result = this.processRuleToken((JSGFRuleToken)rule);
            }
            return(result);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        /**
         * 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));
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        protected internal virtual void resolveRule(JSGFRule r)
        {
            if (r is JSGFRuleToken)
            {
                return;
            }
            if (r is JSGFRuleAlternatives)
            {
                Iterator iterator = ((JSGFRuleAlternatives)r).getRules().iterator();
                while (iterator.hasNext())
                {
                    JSGFRule jsgfrule = (JSGFRule)iterator.next();
                    this.resolveRule(jsgfrule);
                }
                return;
            }
            if (r is JSGFRuleSequence)
            {
                Iterator iterator = ((JSGFRuleSequence)r).getRules().iterator();
                while (iterator.hasNext())
                {
                    JSGFRule jsgfrule = (JSGFRule)iterator.next();
                    this.resolveRule(jsgfrule);
                }
                return;
            }
            if (r is JSGFRuleCount)
            {
                this.resolveRule(((JSGFRuleCount)r).getRule());
                return;
            }
            if (r is JSGFRuleTag)
            {
                JSGFRuleTag jsgfruleTag = (JSGFRuleTag)r;
                JSGFRule    jsgfrule    = jsgfruleTag.getRule();
                string      text        = jsgfrule.toString();
                object      obj         = (Collection)this.__ruleTags.get(text);
                if ((Collection)obj == null)
                {
                    obj = new HashSet();
                    this.__ruleTags.put(text, (HashSet)obj);
                }
                object     obj2 = obj;
                object     tag  = jsgfruleTag.getTag();
                Collection collection;
                if (obj2 != null)
                {
                    if ((collection = (obj2 as Collection)) == null)
                    {
                        throw new IncompatibleClassChangeError();
                    }
                }
                else
                {
                    collection = null;
                }
                collection.add(tag);
                this.resolveRule(jsgfrule);
                return;
            }
            if (!(r is JSGFRuleName))
            {
                string message = "Unknown rule type";

                throw new JSGFGrammarException(message);
            }
            JSGFRuleName jsgfruleName  = (JSGFRuleName)r;
            JSGFRuleName jsgfruleName2 = this.resolve(jsgfruleName);

            if (jsgfruleName2 == null)
            {
                string message2 = new StringBuilder().append("Unresolvable rulename in grammar ").append(this.name).append(": ").append(jsgfruleName).toString();

                throw new JSGFGrammarException(message2);
            }
            jsgfruleName.resolvedRuleName = jsgfruleName2.getRuleName();
            jsgfruleName.setRuleName(jsgfruleName2.getRuleName());
        }
Ejemplo n.º 23
0
 public virtual void setRule(string ruleName, JSGFRule rule, bool isPublic)
 {
     JSGFRuleGrammar.JSGFRuleState jsgfruleState = new JSGFRuleGrammar.JSGFRuleState(this, rule, true, isPublic);
     this.__rules.put(ruleName, jsgfruleState);
 }
Ejemplo n.º 24
0
        /** Resolve the given rule. */
        protected void ResolveRule(JSGFRule r)
        {
            if (r is JSGFRuleToken)
            {
                return;
            }

            if (r is JSGFRuleAlternatives)
            {
                foreach (JSGFRule rule in ((JSGFRuleAlternatives)r).GetRules())
                {
                    ResolveRule(rule);
                }
                return;
            }

            if (r is JSGFRuleSequence)
            {
                foreach (JSGFRule rule in ((JSGFRuleSequence)r).Rules)
                {
                    ResolveRule(rule);
                }
                return;
            }

            if (r is JSGFRuleCount)
            {
                ResolveRule(((JSGFRuleCount)r).Rule);
                return;
            }

            if (r is JSGFRuleTag)
            {
                JSGFRuleTag rt = (JSGFRuleTag)r;

                JSGFRule rule    = rt.Rule;
                String   ruleStr = rule.ToString();

                // add the tag the tag-table
                var tags = RuleTags.Get(ruleStr);
                if (tags == null)
                {
                    tags = new HashSet <String>();
                    RuleTags.Put(ruleStr, tags);
                }
                tags.Add(rt.Tag);

                ResolveRule(rule);
                return;
            }

            if (r is JSGFRuleName)
            {
                JSGFRuleName rn       = (JSGFRuleName)r;
                JSGFRuleName resolved = Resolve(rn);

                if (resolved == null)
                {
                    throw new JSGFGrammarException("Unresolvable rulename in grammar " + _name + ": " + rn);
                }
                else
                {
                    // TODO: This forces all rule names to be fully resolved.
                    // This should be changed.
                    rn.ResolvedRuleName = resolved.GetRuleName();
                    rn.SetRuleName(resolved.GetRuleName());
                    return;
                }
            }

            throw new JSGFGrammarException("Unknown rule type");
        }
Ejemplo n.º 25
0
        /**
         * Set a rule in the grammar either by creating a new rule or updating an
         * existing rule.
         *
         * @param ruleName
         *            the name of the rule.
         * @param rule
         *            the definition of the rule.
         * @param isPublic
         *            whether this rule is public or not.
         */
        public void SetRule(String ruleName, JSGFRule rule, bool isPublic)
        {
            JSGFRuleState state = new JSGFRuleState(rule, true, isPublic);

            Rules.Put(ruleName, state);
        }