Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Utilities » Downloads
 
Add your own
alternative version
Go to top

XTract: A tool for excerpting relevant text

, 22 Apr 2005
Extracting the best fixed length excerpt from a document based on search terms.
xtract_demo.zip
Xtract.csproj.user
App.ico
xtract_src.zip
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Xtract
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox edExcerpt;
		private System.Windows.Forms.TextBox edRawText;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem mnuStart;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.edExcerpt = new System.Windows.Forms.TextBox();
			this.edRawText = new System.Windows.Forms.TextBox();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.mnuStart = new System.Windows.Forms.MenuItem();
			this.SuspendLayout();
			// 
			// edExcerpt
			// 
			this.edExcerpt.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.edExcerpt.Location = new System.Drawing.Point(0, 233);
			this.edExcerpt.Multiline = true;
			this.edExcerpt.Name = "edExcerpt";
			this.edExcerpt.Size = new System.Drawing.Size(488, 64);
			this.edExcerpt.TabIndex = 1;
			this.edExcerpt.Text = "textBox2";
			// 
			// edRawText
			// 
			this.edRawText.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.edRawText.Location = new System.Drawing.Point(0, 0);
			this.edRawText.Multiline = true;
			this.edRawText.Name = "edRawText";
			this.edRawText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.edRawText.Size = new System.Drawing.Size(488, 224);
			this.edRawText.TabIndex = 2;
			this.edRawText.Text = "textBox3";
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.mnuStart});
			// 
			// mnuStart
			// 
			this.mnuStart.Index = 0;
			this.mnuStart.Text = "Start";
			this.mnuStart.Click += new System.EventHandler(this.mnuStart_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(488, 297);
			this.Controls.Add(this.edRawText);
			this.Controls.Add(this.edExcerpt);
			this.Menu = this.mainMenu1;
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//fake latin text courtesy of:
			//http://www.lipsum.com/
			//Best fake latin text generator I have ever used
			edRawText.Text="Lorem ipsum dolor sit amet, consectetuer\r\n" + 
				"adipiscing *apple* elit. Aliquam ante nulla, luctus quis,\r\n" +
				"porta nec, lacinia vel, justo. Mauris eleifend\r\n" +
				"diam eget eros. Nam tincidunt, ligula et tristique\r\n" +
				"congue, neque quam lobortis orci, eu sagittis urna\r\n" +
				"odio non nunc. Fusce quam metus, interdum quis,\r\n" +
				"faucibus non, dictum sed, tortor. In hac habitasse\r\n" +
				"platea *almond* dictumst *pear*. Phasellus arcu tellus, pulvinar\r\n" +
				"ut, commodo non, lacinia a, wisi. Sed arcu. Sed\r\n" +
				"odio. Nam vel orci. In nisl ante, rhoncus eget,\r\n" +
				"consequat *apple pear almond* eget, gravida vel, orci. Morbi orci\r\n" +
				"quam, feugiat eget, consectetuer eu, porta\r\n" +
				"nonummy, ligula. Lorem ipsum dolor sit amet,\r\n" +
				"consectetuer adipiscing elit. Integer lorem arcu,\r\n" +
				"viverra hendrerit, semper ac, vestibulum vel,\r\n" +
				"turpis. Sed varius erat quis est. Praesent\r\n" +
				"suscipit libero scelerisque massa. Vestibulum ante\r\n" +
				"ipsum primis *pear* in faucibus orci luctus et ultrices\r\n" +
				"posuere cubilia Curae; Nunc quis wisi a eros\r\n" +
				"pellentesque semper. Aenean molestie. \r\n" ;


			this.edExcerpt.Text="";
		
		}

		

		private void mnuStart_Click(object sender, System.EventArgs e)
		{
			GZTW.SearchStuff.ExtractAndRank er=new GZTW.SearchStuff.ExtractAndRank();
			er.Process(this.edRawText.Text,new string[]{"almond","pear","apple"});
			this.edExcerpt.Text="Search terms: almond, pear, apple\r\nRanking: " + er.Ranking.ToString() + "\r\nExcerpt: " +er.Extract;
		
		}







	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Member 96

Canada Canada
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 22 Apr 2005
Article Copyright 2005 by Member 96
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid