コード例 #1
0
        /// <summary>
        /// Gets training instance parse tree as a NomBank node, marking predicates and support verbs
        /// as determined from constructor.
        /// </summary>
        /// <param name="mrgFile">MRG file of tree</param>
        /// <param name="sentenceNumber">Sentence number of tree</param>
        /// <returns>Training instance parse tree as a NomBank node</returns>
        protected override TreeBankNode GetTrainingInstanceParseTree(string mrgFile, int sentenceNumber)
        {
            // get parse tree as usual
            TreeBankNode parseTree = base.GetTrainingInstanceParseTree(mrgFile, sentenceNumber);

            // turn parse tree into NomBank tree
            NomBankNode nomBankParseTree = new NomBankNode(parseTree);

            // label predicate and support verb nodes
            if (_labelPredicates || _labelSupportVerbs)
            {
                /* get MRG file in gold-parsed NomBank engine...we must use the gold NomBank engine for marking stuff because
                 * the automatic version won't know about all of the markables due to syntactic parse errors that prevent some
                 * propositions from being included in the auto-parse propositions file */
                string goldMrgFile = _goldParsedNomBankEngine.GetFullMrgPath(mrgFile);

                foreach (NomBankNode token in nomBankParseTree.Tokens)
                {
                    int tokenNumber = token.TokenNumber;

                    if (_labelPredicates)
                    {
                        if (_goldParsedNomBankEngine.TokenIsMarkable(goldMrgFile, sentenceNumber, tokenNumber))
                        {
                            token.AddLabel(new NomBankNodeLabel(NomBankNodeLabel.NodeType.Predicate, 1), true);
                        }
                    }

                    if (_labelSupportVerbs)
                    {
                        if (_goldParsedNomBankEngine.TokenIsSupportVerb(goldMrgFile, sentenceNumber, tokenNumber))
                        {
                            token.AddLabel(new NomBankNodeLabel(NomBankNodeLabel.NodeType.Support, 1), true);
                        }
                    }
                }
            }

            return(nomBankParseTree);
        }
コード例 #2
0
        /// <summary>
        /// Tests the current node
        /// </summary>
        /// <param name="nomBankEngine">NomBankEngine to use in testing</param>
        public void Test(NomBankEngine nomBankEngine)
        {
            // check predicate node
            if (IsPredicate && !nomBankEngine.TokenIsMarkable(MrgFile, SentenceNumber, TokenNumber))
            {
                throw new Exception("Invalid markable token entry");
            }

            // check support verbs
            if (IsSupportVerb && !nomBankEngine.TokenIsSupportVerb(MrgFile, SentenceNumber, TokenNumber))
            {
                throw new Exception("Support verb mismatch");
            }

            // check morphological variant
            if (IsRoot && !nomBankEngine.ContainsMorphologicalVariantOf(Information.Noun))
            {
                throw new Exception("Noun does not exist in section");
            }

            // test children nodes
            IEnumerator <TreeBankNode> childEnum = Children;

            while (childEnum.MoveNext())
            {
                (childEnum.Current as NomBankNode).Test(nomBankEngine);
            }

            RoleSet roleSet = (Root as NomBankNode).RoleSet;

            foreach (Role role in roleSet)
            {
                if (roleSet.Get(role.Number).Description != role.Description)
                {
                    throw new Exception();
                }
            }
        }