2018-08-15 22:37:23 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.NLP.Tokenize
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// BotSharp Tokenizer Factory
|
|
|
|
|
|
/// Tokenizers divide strings into lists of substrings.
|
|
|
|
|
|
/// The particular tokenizer requires implement interface
|
|
|
|
|
|
/// models to be installed.BotSharp.NLP also provides a simpler, regular-expression based tokenizer, which splits text on whitespace and punctuation.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class TokenizerFactory<ITokenize> where ITokenize : ITokenizer, new()
|
|
|
|
|
|
{
|
2018-08-17 20:49:29 +00:00
|
|
|
|
private SupportedLanguage _lang;
|
|
|
|
|
|
|
2018-08-15 22:37:23 +00:00
|
|
|
|
private ITokenize _tokenizer;
|
|
|
|
|
|
|
2018-08-17 20:49:29 +00:00
|
|
|
|
private TokenizationOptions _options;
|
|
|
|
|
|
|
|
|
|
|
|
public TokenizerFactory(TokenizationOptions options, SupportedLanguage lang)
|
2018-08-15 22:37:23 +00:00
|
|
|
|
{
|
2018-08-17 20:49:29 +00:00
|
|
|
|
_lang = lang;
|
|
|
|
|
|
_options = options;
|
2018-08-15 22:37:23 +00:00
|
|
|
|
_tokenizer = new ITokenize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-17 20:49:29 +00:00
|
|
|
|
public List<Token> Tokenize(string sentence)
|
2018-08-15 22:37:23 +00:00
|
|
|
|
{
|
2018-08-17 20:49:29 +00:00
|
|
|
|
return _tokenizer.Tokenize(sentence, _options);
|
2018-08-15 22:37:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|