コード例 #1
0
        public DescriptionPattern ModDescription(Relation r)
        {
            bool neg = false, cat = false;

            switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
            {
            case 16:
            {
                Jj_consume_token(16);
                neg = true;
                break;
            }

            default:
                jj_la1[4] = jj_gen;
                break;
            }
            switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
            {
            case 17:
            {
                Jj_consume_token(17);
                cat = true;
                break;
            }

            default:
                jj_la1[5] = jj_gen;
                break;
            }
            DescriptionPattern node = Description(r, neg, cat);

            return(node);
        }
コード例 #2
0
 public DescriptionMatcher(DescriptionPattern n, Tree root, Tree tree,
                           IdentityDictionary <Tree, Tree> nodesToParents,
                           Dictionary <string, Tree> namesToNodes,
                           VariableStrings variableStrings,
                           IHeadFinder headFinder) :
     base(root, tree, nodesToParents, namesToNodes, variableStrings, headFinder)
 {
     myNode = n;
     // no need to reset anything - everything starts out as null or false.
     // lazy initialization of children to save time.
     // resetChildIter();
 }
コード例 #3
0
 public DescriptionPattern(Relation newRelation, DescriptionPattern oldPattern)
 {
     this.rel             = newRelation;
     this.negDesc         = oldPattern.negDesc;
     this.isLink          = oldPattern.isLink;
     this.linkedName      = oldPattern.linkedName;
     this.stringDesc      = oldPattern.stringDesc;
     this.descriptionMode = oldPattern.descriptionMode;
     this.descPattern     = oldPattern.descPattern;
     this.exactMatch      = oldPattern.exactMatch;
     this.stringFilter    = oldPattern.stringFilter;
     this.name            = oldPattern.name;
     this.SetChild(oldPattern.child);
     this.basicCatFunction = oldPattern.basicCatFunction;
     this.variableGroups   = oldPattern.variableGroups;
 }
コード例 #4
0
        public DescriptionPattern Description(Relation r, bool negateDesc, bool cat)
        {
            Token desc       = null;
            Token name       = null;
            Token linkedName = null;
            bool  link       = false;
            var   varGroups  = new List <Tuple <int, string> >();

            switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
            {
            case Identifier:
            case Blank:
            case Regex:
            {
                switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
                {
                case Identifier:
                {
                    desc = Jj_consume_token(Identifier);
                    break;
                }

                case Regex:
                {
                    desc = Jj_consume_token(Regex);
                    break;
                }

                case Blank:
                {
                    desc = Jj_consume_token(Blank);
                    break;
                }

                default:
                    jj_la1[6] = jj_gen;
                    Jj_consume_token(-1);
                    throw new ParseException();
                }
                //label_2:
                while (true)
                {
                    switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
                    {
                    case 18:
                    {
                        ;
                        break;
                    }

                    default:
                        jj_la1[7] = jj_gen;
                        //break label_2;
                        goto post_label_2;
                    }
                    Jj_consume_token(18);
                    Token groupNum = Jj_consume_token(Number);
                    Jj_consume_token(19);
                    Token groupVar = Jj_consume_token(Identifier);
                    varGroups.Add(new Tuple <int, string>(int.Parse(groupNum.Image), groupVar.Image));
                }
post_label_2:
                {
                    switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
                    {
                    case 20:
                    {
                        Jj_consume_token(20);
                        name = Jj_consume_token(Identifier);
                        if (knownVariables.Contains(name.Image))
                        {
                            throw new ParseException("Variable " + name.Image +
                                                     " has been declared twice, which makes no sense");
                        }
                        else
                        {
                            knownVariables.Add(name.Image);
                        }
                        if (underNegation)
                        {
                            throw new ParseException("No named tregex nodes allowed in the scope of negation.");
                        }
                        break;
                    }

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

            case 21:
            {
                Jj_consume_token(21);
                linkedName = Jj_consume_token(Identifier);
                switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
                {
                case 20:
                {
                    Jj_consume_token(20);
                    name = Jj_consume_token(Identifier);
                    break;
                }

                default:
                    jj_la1[9] = jj_gen;
                    break;
                }
                if (!knownVariables.Contains(linkedName.Image))
                {
                    throw new ParseException("Variable " + linkedName.Image +
                                             " was referenced before it was declared");
                }
                if (name != null)
                {
                    if (knownVariables.Contains(name.Image))
                    {
                        throw new ParseException("Variable " + name.Image +
                                                 " has been declared twice, which makes no sense");
                    }
                    else
                    {
                        knownVariables.Add(name.Image);
                    }
                }
                link = true;
                break;
            }

            case 20:
            {
                Jj_consume_token(20);
                name = Jj_consume_token(Identifier);
                if (!knownVariables.Contains(name.Image))
                {
                    throw new ParseException("Variable " + name.Image +
                                             " was referenced before it was declared");
                }
                break;
            }

            default:
                jj_la1[10] = jj_gen;
                Jj_consume_token(-1);
                throw new ParseException();
            }
            var ret = new DescriptionPattern(r, negateDesc, desc != null ? desc.Image : null,
                                             name != null ? name.Image : null, cat, basicCatFunction, varGroups, link,
                                             linkedName != null ? linkedName.Image : null);

            return(ret);
        }
コード例 #5
0
        public DescriptionPattern SubNode(Relation r)
        {
            DescriptionPattern result = null;
            TregexPattern      child  = null;

            switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
            {
            case 14:
            {
                Jj_consume_token(14);
                result = SubNode(r);
                Jj_consume_token(15);
                switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
                {
                case RELATION:
                case MultiRelation:
                case RelWStrArg:
                case 14:
                case 16:
                case 23:
                case 24:
                {
                    child = ChildrenDisj();
                    break;
                }

                default:
                    jj_la1[1] = jj_gen;
                    break;
                }
                if (child != null)
                {
                    var newChildren = new List <TregexPattern>();
                    newChildren.AddRange(result.GetChildren());
                    newChildren.Add(child);
                    result.SetChild(new CoordinationPattern(newChildren, true));
                }
                return(result);
            }

            case Identifier:
            case Blank:
            case Regex:
            case 16:
            case 17:
            case 20:
            case 21:
            {
                result = ModDescription(r);
                switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
                {
                case RELATION:
                case MultiRelation:
                case RelWStrArg:
                case 14:
                case 16:
                case 23:
                case 24:
                {
                    child = ChildrenDisj();
                    break;
                }

                default:
                    jj_la1[2] = jj_gen;
                    break;
                }
                if (child != null)
                {
                    result.SetChild(child);
                }
                return(result);
            }

            default:
                jj_la1[3] = jj_gen;
                Jj_consume_token(-1);
                throw new ParseException();
            }
        }
コード例 #6
0
ファイル: TregexParser.cs プロジェクト: gblosser/OpenNlp
 public DescriptionPattern Description(Relation r, bool negateDesc, bool cat)
 {
     Token desc = null;
     Token name = null;
     Token linkedName = null;
     bool link = false;
     var varGroups = new List<Tuple<int, string>>();
     switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
     {
         case Identifier:
         case Blank:
         case Regex:
         {
             switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
             {
                 case Identifier:
                 {
                     desc = Jj_consume_token(Identifier);
                     break;
                 }
                 case Regex:
                 {
                     desc = Jj_consume_token(Regex);
                     break;
                 }
                 case Blank:
                 {
                     desc = Jj_consume_token(Blank);
                     break;
                 }
                 default:
                     jj_la1[6] = jj_gen;
                     Jj_consume_token(-1);
                     throw new ParseException();
             }
             //label_2:
             while (true)
             {
                 switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
                 {
                     case 18:
                     {
                         ;
                         break;
                     }
                     default:
                         jj_la1[7] = jj_gen;
                         //break label_2;
                         goto post_label_2;
                 }
                 Jj_consume_token(18);
                 Token groupNum = Jj_consume_token(Number);
                 Jj_consume_token(19);
                 Token groupVar = Jj_consume_token(Identifier);
                 varGroups.Add(new Tuple<int, string>(int.Parse(groupNum.Image), groupVar.Image));
             }
             post_label_2:
             {
                 switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
                 {
                     case 20:
                     {
                         Jj_consume_token(20);
                         name = Jj_consume_token(Identifier);
                         if (knownVariables.Contains(name.Image))
                         {
                             throw new ParseException("Variable " + name.Image +
                                                              " has been declared twice, which makes no sense");
                         }
                         else
                         {
                             knownVariables.Add(name.Image);
                         }
                         if (underNegation)
                         {
                             throw new ParseException("No named tregex nodes allowed in the scope of negation.");
                         }
                         break;
                     }
                     default:
                         jj_la1[8] = jj_gen;
                         break;
                 }
                 break;
             }
         }
         case 21:
         {
             Jj_consume_token(21);
             linkedName = Jj_consume_token(Identifier);
             switch ((jj_ntk == -1) ? Jj_ntk_f() : jj_ntk)
             {
                 case 20:
                 {
                     Jj_consume_token(20);
                     name = Jj_consume_token(Identifier);
                     break;
                 }
                 default:
                     jj_la1[9] = jj_gen;
                     break;
             }
             if (!knownVariables.Contains(linkedName.Image))
             {
                 throw new ParseException("Variable " + linkedName.Image +
                                                  " was referenced before it was declared");
             }
             if (name != null)
             {
                 if (knownVariables.Contains(name.Image))
                 {
                     throw new ParseException("Variable " + name.Image +
                                                      " has been declared twice, which makes no sense");
                 }
                 else
                 {
                     knownVariables.Add(name.Image);
                 }
             }
             link = true;
             break;
         }
         case 20:
         {
             Jj_consume_token(20);
             name = Jj_consume_token(Identifier);
             if (!knownVariables.Contains(name.Image))
             {
                 throw new ParseException("Variable " + name.Image +
                                                  " was referenced before it was declared");
             }
             break;
         }
         default:
             jj_la1[10] = jj_gen;
             Jj_consume_token(-1);
             throw new ParseException();
     }
     var ret = new DescriptionPattern(r, negateDesc, desc != null ? desc.Image : null,
         name != null ? name.Image : null, cat, basicCatFunction, varGroups, link,
         linkedName != null ? linkedName.Image : null);
     return ret;
 }
コード例 #7
0
 public DescriptionMatcher(DescriptionPattern n, Tree root, Tree tree,
     IdentityDictionary<Tree, Tree> nodesToParents,
     Dictionary<string, Tree> namesToNodes,
     VariableStrings variableStrings,
     IHeadFinder headFinder) :
         base(root, tree, nodesToParents, namesToNodes, variableStrings, headFinder)
 {
     myNode = n;
     // no need to reset anything - everything starts out as null or false.  
     // lazy initialization of children to save time.
     // resetChildIter();
 }
コード例 #8
0
 public DescriptionPattern(Relation newRelation, DescriptionPattern oldPattern)
 {
     this.rel = newRelation;
     this.negDesc = oldPattern.negDesc;
     this.isLink = oldPattern.isLink;
     this.linkedName = oldPattern.linkedName;
     this.stringDesc = oldPattern.stringDesc;
     this.descriptionMode = oldPattern.descriptionMode;
     this.descPattern = oldPattern.descPattern;
     this.exactMatch = oldPattern.exactMatch;
     this.stringFilter = oldPattern.stringFilter;
     this.name = oldPattern.name;
     this.SetChild(oldPattern.child);
     this.basicCatFunction = oldPattern.basicCatFunction;
     this.variableGroups = oldPattern.variableGroups;
 }