/// <summary>
 /// Constructor
 /// </summary>
 /// <param name="nouns">Nouns to get predicates trees for (null for all)</param>
 /// <param name="nomBankEngine">NomBank engine to draw training predicate trees from</param>
 /// <param name="instanceFilter">Instance filter to apply</param>
 /// <param name="sections">TreeBank sections to draw instances from</param>
 public NomBankPredicateTreeInstanceProvider(Set <string> nouns,
                                             NomBankEngine nomBankEngine,
                                             InstanceFilterDelegate instanceFilter,
                                             Set <int> sections)
     : base(nomBankEngine, instanceFilter, sections)
 {
     Nouns          = nouns;
     _filteredNodes = new List <NomBankNode>();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="labelPredicates">Whether or not to label predicates</param>
 /// <param name="labelSupportVerbs">Whether or not to label support verbs</param>
 /// <param name="autoParsedNomBankEngine">Automatically parsed version of NomBank, from which to draw parse tree structure</param>
 /// <param name="goldParsedNomBankEngine">Gold-parsed version of NomBank, from which to draw predicate and support verb labels. This is
 /// necessary because auto-parsed versions of NomBank don't include annotations for instances whose arguments cannot all be minimally
 /// subsumed.</param>
 /// <param name="instanceFilter">Instance filter to apply</param>
 /// <param name="sections">TreeBank sections to draw instances from (null for all sections)</param>
 public NomBankParseTreeInstanceProvider(bool labelPredicates,
                                         bool labelSupportVerbs,
                                         NomBankEngine autoParsedNomBankEngine,
                                         NomBankEngine goldParsedNomBankEngine,
                                         InstanceFilterDelegate instanceFilter,
                                         Set <int> sections)
     : base(autoParsedNomBankEngine, instanceFilter, sections)
 {
     _labelPredicates         = labelPredicates;
     _labelSupportVerbs       = labelSupportVerbs;
     _goldParsedNomBankEngine = goldParsedNomBankEngine;
 }
예제 #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        public TestForm()
        {
            InitializeComponent();

            // initialize engine
            string root = Directory.GetDirectoryRoot(".");

            _nomBankEngine = new NomBankEngine(root + @"NLP\Resources\PennTreeBank_3\parsed\mrg\wsj",
                                               root + @"NLP\Resources\nombank.1.0\nombank.1.0",
                                               root + @"NLP\Resources\nombank.1.0\frames",
                                               root + @"NLP\Resources\nombank.1.0\nombank-morph.dict.1.0",
                                               root + @"NLP\Resources\nombank.1.0\nomlex-plus.1.0",
                                               root + @"NLP\Resources\Indexes\nombank_index");
            // populate noun box
            foreach (string noun in _nomBankEngine.AllNouns)
            {
                nounCombo.Items.Add(noun);
            }

            // populate class box
            foreach (string nlClass in _nomBankEngine.NomLexEngine.Classes)
            {
                classCombo.Items.Add(nlClass);
            }

            // populate NomLex noun box
            List <string> nomLexNouns = new List <string>(_nomBankEngine.NomLexEngine.Nouns);

            nomLexNouns.Sort();
            foreach (string nomLexNoun in nomLexNouns)
            {
                nomLexNounCombo.Items.Add(nomLexNoun);
            }

            foreach (NomBankNodeLabel.NodeType t in Enum.GetValues(typeof(NomBankNodeLabel.NodeType)))
            {
                nodeTypeCombo.Items.Add(t);
            }

            foreach (NomBankNodeLabel.NodeFeature f in Enum.GetValues(typeof(NomBankNodeLabel.NodeFeature)))
            {
                nodeFeatureCombo.Items.Add(f);
            }
        }
예제 #4
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();
                }
            }
        }
        /// <summary>
        /// Gets next training instance for models build over NomBank
        /// </summary>
        /// <returns>Next training instance</returns>
        public override ClassifiableEntity GetNextInstance()
        {
            // try to move to next node
            while (!_nodes.MoveNext())
            {
                NomBankEngine nomBankEngine = TreeBankEngine as NomBankEngine;

                // try to move to next NounInfo
                while (!MoveToNextValidNounInfo(ref _nounInfo))
                {
                    // try to move to next noun...if there are none we're done
                    if (!_nouns.MoveNext())
                    {
                        return(null);
                    }

                    // start before first NounInfo for current noun
                    _nounInfo = nomBankEngine.GetNounInfo(_nouns.Current).GetEnumerator();
                }

                // filter all nodes in the tree, keeping the ones that pass
                NomBankNode root = nomBankEngine.GetNomBankTree(_nounInfo.Current);
                _filteredNodes.Clear();  // reuse node collection for better memory usage
                foreach (NomBankNode n in root.AllNodes)
                {
                    if (Filter(n))
                    {
                        _filteredNodes.Add(n);
                    }
                }

                _nodes = _filteredNodes.GetEnumerator();
            }

            return(_nodes.Current);
        }