Method DetectLanguage
- Namespace
- LMKit.Translation
- Assembly
- LM-Kit.NET.dll
DetectLanguage(string, IEnumerable<Language>, CancellationToken)
Detects the language of the specified plain text.
public Language DetectLanguage(string text, IEnumerable<Language> languages = null, CancellationToken cancellationToken = default)
Parameters
text
stringThe text for which to detect the language.
languages
IEnumerable<Language>An optional collection of languages to consider during the operation. If omitted, the method defaults to utilizing the full range of languages specified within the Language enumeration, thus encompassing all supported languages.
cancellationToken
CancellationTokenOptional. A CancellationToken for handling cancellation requests.
Returns
- Language
The detected language as a member of the Language enumeration. If the language cannot be determined, the Undefined member will be returned.
Examples
using LMKit.Translation;
using LMKit.Model;
using System;
// Initialize the language model (LLM)
LLM languageModel = new LLM("path/to/your/model");
// Create an instance of TextTranslation using the LLM
TextTranslation textTranslation = new TextTranslation(languageModel);
// Text for language detection
string text = "こんにちは、お元気ですか?";
// Detect the language
Language detectedLanguage = textTranslation.DetectLanguage(text);
Console.WriteLine($"Detected Language: {detectedLanguage}");
// Output: "Detected Language: Japanese"
Remarks
This method analyzes the text content and identifies its language, supporting both single and multiline texts with various formatting. It leverages various language detection algorithms to determine the language from a set of possible languages.