LanguageDetector.cs 946 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using MediaBrowser.Model.Serialization;
  3. namespace NLangDetect.Core
  4. {
  5. // TODO IMM HI: change to non-static class
  6. // TODO IMM HI: hide other, unnecassary classes via internal?
  7. public static class LanguageDetector
  8. {
  9. private const double _DefaultAlpha = 0.5;
  10. #region Public methods
  11. public static void Initialize(IJsonSerializer json)
  12. {
  13. DetectorFactory.LoadProfiles(json);
  14. }
  15. public static void Release()
  16. {
  17. DetectorFactory.Clear();
  18. }
  19. public static string DetectLanguage(string plainText)
  20. {
  21. if (string.IsNullOrEmpty(plainText)) { throw new ArgumentException("Argument can't be null nor empty.", nameof(plainText)); }
  22. var detector = DetectorFactory.Create(_DefaultAlpha);
  23. detector.Append(plainText);
  24. return detector.Detect();
  25. }
  26. #endregion
  27. }
  28. }