Click here to Skip to main content
15,886,024 members
Articles / Programming Languages / C# 4.0

Detect a written text's language

Rate me:
Please Sign up or sign in to vote.
4.96/5 (75 votes)
21 Oct 2009CPOL6 min read 155.5K   7.7K   114  
An article on how to detect the language of a written text.
using System;
using System.Collections;
namespace DialogueMaster.Babel
{
	/// <summary>
	/// Collects the number of votes for a single token.
	/// </summary>
 	internal sealed class TokenVoter : IComparable		
	{

		#region�Fields�(2)�

		private string m_Category;
		private double m_Score = 1;

		#endregion�Fields�

		#region�Constructors�(2)�

		public TokenVoter(string category, double score)
		{
			this.m_Category = category;
			this.m_Score = score;
		}

		public TokenVoter(string category)
		{
			this.m_Category = category;
		}

		#endregion�Constructors�

		#region�Properties�(2)�

		public string Category
		{
			get {return this.m_Category;}
		}

		public double Score
		{
			get {return this.m_Score;}
			set {this.m_Score = value;}
		}

		#endregion�Properties�

		#region�Methods�(2)�


		//�Public�Methods�(2)�

		public void AddOccurence()
		{
			this.m_Score++;
		}

		public override string ToString()
		{
			return this.m_Category+":"+this.m_Score.ToString();
		}


		#endregion�Methods�


		#region IComparable Members

		public int CompareTo(object obj)
		{
			if (obj is TokenVoter)
			{
				return -1* this.m_Score.CompareTo( ((TokenVoter)obj).Score);
			}
			return 0;
		}

		#endregion
	}

}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
Carsten started programming Basic and Assembler back in the 80’s when he got his first C64. After switching to a x86 based system he started programming in Pascal and C. He started Windows programming with the arrival of Windows 3.0. After working for various internet companies developing a linguistic text analysis and classification software for 25hours communications he is now working as a contractor.

Carsten lives in Hamburg, Germany with his wife and five children.

Comments and Discussions