Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Detect a written text's language

, 21 Oct 2009 CPOL
An article on how to detect the language of a written text.
using System;
using System.Collections;
using System.Diagnostics;
using System.Configuration.Install;
using System.Management.Instrumentation;

namespace DialogueMaster.Babel
{
	/// <summary>
	/// Installs the counters for Babel.
	/// </summary>
	public class Installer : System.Management.Instrumentation.DefaultManagementProjectInstaller
	{
		public Installer()
		{
		}
		
		public static void InstallCounters()
		{
            if (!PerformanceCounterCategory.Exists("DialogueMaster Babel")) 
			{

				CounterCreationDataCollection ccdJanusTables = new CounterCreationDataCollection();

				// tables
				CounterCreationData cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.NumberOfItems64;
				cd.CounterName = "Tables created";
				cd.CounterHelp = "Total number of NGram-Tables created";
				ccdJanusTables.Add(cd);

				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
				cd.CounterName = "Tables created / sec";
				cd.CounterHelp = "Number of NGram-Tables created per second";
				ccdJanusTables.Add(cd);


				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.RawFraction;
				cd.CounterName = "Avg. table creation time";
				cd.CounterHelp = "Average time it takes to create a table";
				ccdJanusTables.Add(cd);

				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.RawBase;
				cd.CounterName = "base for avg. table creation time";
				cd.CounterHelp = "base for Average time it takes to create a table";
				ccdJanusTables.Add(cd);


				// Comparison
				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.NumberOfItems64;
				cd.CounterName = "Comparisons";
				cd.CounterHelp = "Total number of comparisons";
				ccdJanusTables.Add(cd);

				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
				cd.CounterName = "Comparisons / sec";
				cd.CounterHelp = "Number of comparisons created per second";
				ccdJanusTables.Add(cd);

				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.RawFraction;
				cd.CounterName = "Avg. comparison time";
				cd.CounterHelp = "Average time it takes to compare two tables";
				ccdJanusTables.Add(cd);

				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.RawBase;
				cd.CounterName = "base for Avg. comparison time";
				cd.CounterHelp = "base for Average time it takes to compare two tables";
				ccdJanusTables.Add(cd);

				// Classifications
				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.NumberOfItems64;
				cd.CounterName = "Classifications";
				cd.CounterHelp = "Total number of classifications";
				ccdJanusTables.Add(cd);

				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
				cd.CounterName = "Classifications / sec";
				cd.CounterHelp = "Number of classifications created per second";
				ccdJanusTables.Add(cd);

				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.RawFraction;
				cd.CounterName = "Avg. classification time";
				cd.CounterHelp = "Average time it takes to classify a text";
				ccdJanusTables.Add(cd);

				cd = new CounterCreationData();
				cd.CounterType = PerformanceCounterType.RawBase;
				cd.CounterName = "base for Avg. classification time";
				cd.CounterHelp = "base for Average time it takes to classify a text";
				ccdJanusTables.Add(cd);

                PerformanceCounterCategory.Create("DialogueMaster Babel", "DialogueMaster Janus language detection engine", PerformanceCounterCategoryType.SingleInstance, ccdJanusTables);
			}
		}

		public static void UninstallCounters()
		{
            if (PerformanceCounterCategory.Exists("DialogueMaster Babel")) 
			{
                PerformanceCounterCategory.Delete("DialogueMaster Babel");
			}
		}

		public override void Install(IDictionary stateSaver)
		{
			base.Install(stateSaver);
			InstallCounters();
			
		}

		
	}
}

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)

Share

About the Author

Carsten Zeumer
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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150224.1 | Last Updated 21 Oct 2009
Article Copyright 2009 by Carsten Zeumer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid