Exemplo n.º 1
0
        /**
         * Parses the given RuleCount into a network of GrammarNodes.
         *
         * @param ruleCount
         *            the RuleCount object to parse
         * @return a grammar graph
         */
        private GrammarGraph ProcessRuleCount(JSGFRuleCount ruleCount)
        {
            this.LogInfo("parseRuleCount: " + ruleCount);
            GrammarGraph result   = new GrammarGraph(this);
            int          count    = ruleCount.Count;
            GrammarGraph newNodes = ProcessRule(ruleCount.Rule);

            result.StartNode.Add(newNodes.StartNode, 0.0f);
            newNodes.EndNode.Add(result.EndNode, 0.0f);

            // if this is optional, add a bypass arc

            if (count == JSGFRuleCount.ZeroOrMore ||
                count == JSGFRuleCount.Optional)
            {
                result.StartNode.Add(result.EndNode, 0.0f);
            }

            // if this can possibly occur more than once, add a loopback

            if (count == JSGFRuleCount.OnceOrMore ||
                count == JSGFRuleCount.ZeroOrMore)
            {
                newNodes.EndNode.Add(newNodes.StartNode, 0.0f);
            }
            return(result);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public JSGFRule Item()
        {
            JSGFRule      r;
            List <String> _tags = null;
            int           count = -1;

            switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk)
            {
            case Grammar:
            case Import:
            case Public:
            case IntegerLiteral:
            case FloatingPointLiteral:
            case StringLiteral:
            case Identifier:
            case 28:
                switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk)
                {
                case Grammar:
                case Import:
                case Public:
                case IntegerLiteral:
                case FloatingPointLiteral:
                case StringLiteral:
                case Identifier:
                    r = Terminal();
                    break;

                case 28:
                    r = RuleRef();
                    break;

                default:
                    jj_la1[14] = jj_gen;
                    jj_consume_token(-1);
                    throw new ParseException();
                }
                switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk)
                {
                case 30:
                case 35:
                    switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk)
                    {
                    case 30:
                        jj_consume_token(30);
                        count = JSGFRuleCount.ZeroOrMore;
                        break;

                    case 35:
                        jj_consume_token(35);
                        count = JSGFRuleCount.OnceOrMore;
                        break;

                    default:
                        jj_la1[15] = jj_gen;
                        jj_consume_token(-1);
                        throw new ParseException();
                    }
                    break;

                default:
                    jj_la1[16] = jj_gen;
                    break;
                }
                switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk)
                {
                case Tag:
                    _tags = Tags();
                    break;

                default:
                    jj_la1[17] = jj_gen;
                    break;
                }
                break;

            case 36:
                jj_consume_token(36);
                r = Alternatives();
                jj_consume_token(37);
                switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk)
                {
                case 30:
                case 35:
                    switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk)
                    {
                    case 30:
                        jj_consume_token(30);
                        count = JSGFRuleCount.ZeroOrMore;
                        break;

                    case 35:
                        jj_consume_token(35);
                        count = JSGFRuleCount.OnceOrMore;
                        break;

                    default:
                        jj_la1[18] = jj_gen;
                        jj_consume_token(-1);
                        throw new ParseException();
                    }
                    break;

                default:
                    jj_la1[19] = jj_gen;
                    break;
                }
                switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk)
                {
                case Tag:
                    _tags = Tags();
                    break;

                default:
                    jj_la1[20] = jj_gen;
                    break;
                }
                break;

            case 38:
                jj_consume_token(38);
                r = Alternatives();
                jj_consume_token(39);
                count = JSGFRuleCount.Optional;
                switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk)
                {
                case Tag:
                    _tags = Tags();
                    break;

                default:
                    jj_la1[21] = jj_gen;
                    break;
                }
                break;

            default:
                jj_la1[22] = jj_gen;
                jj_consume_token(-1);
                throw new ParseException();
            }
            if (count != -1)
            {
                r = new JSGFRuleCount(r, count);
            }
            if (_tags != null)
            {
                for (int i = 0; i < _tags.Count; i++)
                {
                    //TODO: Check Behaviour
                    var tag = _tags[i];
                    if (tag[0] == '{')
                    {
                        tag = tag.Substring(1, tag.Length - 1);
                        tag = tag.Replace('\\', ' ');
                    }
                    r = new JSGFRuleTag(r, tag);
                }
            }
            { if (true)
              {
                  return(r);
              }
            }
        }