예제 #1
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));
        }
예제 #2
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);
     }
 }
예제 #3
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);
        }
예제 #4
0
        private JSGFGrammar.GrammarGraph processRuleCount(JSGFRuleCount jsgfruleCount)
        {
            this.logger.fine(new StringBuilder().append("parseRuleCount: ").append(jsgfruleCount).toString());
            JSGFGrammar.GrammarGraph grammarGraph = new JSGFGrammar.GrammarGraph(this);
            int count = jsgfruleCount.getCount();

            JSGFGrammar.GrammarGraph grammarGraph2 = this.processRule(jsgfruleCount.getRule());
            grammarGraph.getStartNode().add(grammarGraph2.getStartNode(), 0f);
            grammarGraph2.getEndNode().add(grammarGraph.getEndNode(), 0f);
            if (count == 4 || count == 2)
            {
                grammarGraph.getStartNode().add(grammarGraph.getEndNode(), 0f);
            }
            if (count == 3 || count == 4)
            {
                grammarGraph2.getEndNode().add(grammarGraph2.getStartNode(), 0f);
            }
            return(grammarGraph);
        }
예제 #5
0
 public override void commitChanges()
 {
     try
     {
         if (this.loadGrammar)
         {
             if (this.manager == null)
             {
                 this.getGrammarManager();
             }
             this.loadXML();
             this.loadGrammar = false;
         }
         this.__ruleStack = new JSGFGrammar.RuleStack(this);
         this.newGrammar();
         this.firstNode = this.createGrammarNode("<sil>");
         GrammarNode grammarNode = this.createGrammarNode("<sil>");
         grammarNode.setFinalNode(true);
         Iterator iterator = this.rules.entrySet().iterator();
         while (iterator.hasNext())
         {
             Map.Entry entry = (Map.Entry)iterator.next();
             JSGFGrammar.GrammarGraph grammarGraph = new JSGFGrammar.GrammarGraph(this);
             this.__ruleStack.push((string)entry.getKey(), grammarGraph);
             JSGFGrammar.GrammarGraph grammarGraph2 = this.processRule((JSGFRule)entry.getValue());
             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();
     }
     catch (MalformedURLException ex)
     {
         throw new IOException(new StringBuilder().append("bad base grammar URL ").append(this.baseURL).append(' ').append(ex).toString());
     }
 }
예제 #6
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);
        }