Example #1
0
        private void getTbSentences_Click(object sender, EventArgs e)
        {
            ClearList();

            string mrgFile = null;

            try
            {
                mrgFile = mrgFileCombo.Text;
                mrgFile = mrgFile.Substring(0, mrgFile.IndexOf(' '));
                mrgFile = _treeBankEngine.GetFullMrgPath(mrgFile);
            }
            catch (Exception)
            {
                MessageBox.Show("Invalid MRG file");
                return;
            }

            try
            {
                foreach (int sentNum in _treeBankEngine.GetSentenceNumbers(mrgFile))
                {
                    AppendOutput(_treeBankEngine.GetParseTree(mrgFile, sentNum));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        /// <summary>
        /// Gets the next training node
        /// </summary>
        /// <returns>Training node</returns>
        public override ClassifiableEntity GetNextInstance()
        {
            // try to move to next node in current sentence
            while (!_nodeEnum.MoveNext())
            {
                // try to move to next sentence in current MRG file
                while (!_sentEnum.MoveNext())
                {
                    // try to move to next MRG file...if there are none, we're done
                    if (!MoveToNextValidMrgFile())
                    {
                        return(null);
                    }

                    // start at first sentence of next MRG file
                    _sentEnum = TreeBankEngine.GetSentenceNumbers(CurrentMrgFile).GetEnumerator();
                }

                // filter all nodes in the tree, keeping the good ones
                TreeBankNode        root          = GetTrainingInstanceParseTree(CurrentMrgFile, _sentEnum.Current);
                List <TreeBankNode> filteredNodes = new List <TreeBankNode>();
                foreach (TreeBankNode n in root.AllNodes)
                {
                    if (Filter(n))
                    {
                        filteredNodes.Add(n);
                    }
                }

                _nodeEnum = filteredNodes.GetEnumerator();
            }

            return(_nodeEnum.Current);
        }
 private void mrgFile_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (mrgFile.SelectedItem != null)
     {
         sentence.Items.Clear();
         string mrgFilePath = _treeBankEngine.GetFullMrgPath(mrgFile.SelectedItem.ToString() + ".mrg");
         foreach (int sentNum in _treeBankEngine.GetSentenceNumbers(mrgFilePath))
         {
             sentence.Items.Add(sentNum);
         }
     }
 }
Example #4
0
        private void loadTbBtn_Click(object sender, EventArgs e)
        {
            string root = Directory.GetDirectoryRoot(".");

            _treeBankEngine = new TreeBankEngine(root + @"NLP\Resources\PennTreeBank_3\PARSED\MRG\WSJ",
                                                 root + @"NLP\Resources\Indexes\treebank_index");

            // populate MRG file combo box
            foreach (string mrgPath in _treeBankEngine.IndexedMrgFiles)
            {
                mrgFileCombo.Items.Add(Path.GetFileName(mrgPath) + " (" + _treeBankEngine.GetSentenceNumbers(mrgPath).Count + " sentences)");
            }

            treeBankGroupBox.Enabled = true;
            loadTbBtn.Enabled        = false;
        }