ailia_tokenizer  1.3.0.0
Public Member Functions | Protected Member Functions | List of all members
ailiaTokenizer.AiliaTokenizerModel Class Reference
Inheritance diagram for ailiaTokenizer.AiliaTokenizerModel:
Inheritance graph
[legend]
Collaboration diagram for ailiaTokenizer.AiliaTokenizerModel:
Collaboration graph
[legend]

Public Member Functions

bool Create (int type, int flag)
 Create a instance. More...
 
bool Open (string model_path=null, string dictionary_path=null, string vocab_path=null)
 Open a model. More...
 
virtual void Close ()
 Destroys instance. More...
 
virtual void Dispose ()
 Release resources. More...
 
int[] Encode (string utf8)
 Perform encode. More...
 
int[] EncodeWithSpecialTokens (string utf8)
 Perform encode with special tokens. More...
 
string Decode (int[] tokens)
 Perform decode @pram tokens Input tokens. More...
 
string DecodeWithSpecialTokens (int[] tokens)
 Perform decode with special tokens @pram tokens Input tokens. More...
 
int GetVocabSize ()
 Gets the size of vocab. More...
 
string GetVocab (int token)
 Perform encode. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 

Member Function Documentation

◆ Close()

virtual void ailiaTokenizer.AiliaTokenizerModel.Close ( )
inlinevirtual

Destroys instance.

Destroys and initializes the instance.

110  {
111  if (net != IntPtr.Zero){
112  AiliaTokenizer.ailiaTokenizerDestroy(net);
113  net = IntPtr.Zero;
114  }
115  }

◆ Create()

bool ailiaTokenizer.AiliaTokenizerModel.Create ( int  type,
int  flag 
)
inline

Create a instance.

Parameters
typeType (AiliaTokenizer..AILIA_TOKENIZER_TYPE_*)
flagOR of flags (AiliaTokenizer..AILIA_TOKENIZER_FLAG_*)
Returns
If this function is successful, it returns true , or false otherwise.
36  {
37  if (net != null){
38  Close();
39  }
40 
41  int status = AiliaTokenizer.ailiaTokenizerCreate(ref net, type, flag);
42  if (status != 0){
43  return false;
44  }
45 
46  return true;
47  }

◆ Decode()

string ailiaTokenizer.AiliaTokenizerModel.Decode ( int[]  tokens)
inline

Perform decode @pram tokens Input tokens.

Returns
If this function is successful, it returns string , or empty string otherwise.
261  {
262  return DecodeCore(tokens, false);
263  }

◆ DecodeWithSpecialTokens()

string ailiaTokenizer.AiliaTokenizerModel.DecodeWithSpecialTokens ( int[]  tokens)
inline

Perform decode with special tokens @pram tokens Input tokens.

Returns
If this function is successful, it returns string , or empty string otherwise.
279  {
280  return DecodeCore(tokens, true);
281  }

◆ Dispose() [1/2]

virtual void ailiaTokenizer.AiliaTokenizerModel.Dispose ( )
inlinevirtual

Release resources.

125  {
126  Dispose(true);
127  }

◆ Dispose() [2/2]

virtual void ailiaTokenizer.AiliaTokenizerModel.Dispose ( bool  disposing)
inlineprotectedvirtual
130  {
131  if (disposing){
132  // release managed resource
133  }
134  Close(); // release unmanaged resource
135  }

◆ Encode()

int [] ailiaTokenizer.AiliaTokenizerModel.Encode ( string  utf8)
inline

Perform encode.

Parameters
utf8Input string
Returns
If this function is successful, it returns array of tokens , or empty array otherwise.
225  {
226  return EncodeCore(utf8, false);
227  }

◆ EncodeWithSpecialTokens()

int [] ailiaTokenizer.AiliaTokenizerModel.EncodeWithSpecialTokens ( string  utf8)
inline

Perform encode with special tokens.

Parameters
utf8Input string
Returns
If this function is successful, it returns array of tokens , or empty array otherwise.
243  {
244  return EncodeCore(utf8, true);
245  }

◆ GetVocab()

string ailiaTokenizer.AiliaTokenizerModel.GetVocab ( int  token)
inline

Perform encode.

Parameters
tokenToken
Returns
If this function is successful, it returns string , or null otherwise.
318  {
319  IntPtr ptr = IntPtr.Zero;
320  int status = AiliaTokenizer.ailiaTokenizerGetVocab(net, token, ref ptr);
321  if (status != 0){
322  return null;
323  }
324  return Marshal.PtrToStringAnsi(ptr);
325  }

◆ GetVocabSize()

int ailiaTokenizer.AiliaTokenizerModel.GetVocabSize ( )
inline

Gets the size of vocab.

Returns
If this function is successful, it returns the size of vocab , or -1 otherwise.
295  {
296  uint len = 0;
297  int status = AiliaTokenizer.ailiaTokenizerGetVocabSize(net, ref len);
298  if (status != 0){
299  return -1;
300  }
301  return (int)len;
302  }

◆ Open()

bool ailiaTokenizer.AiliaTokenizerModel.Open ( string  model_path = null,
string  dictionary_path = null,
string  vocab_path = null 
)
inline

Open a model.

Parameters
model_pathPath for model (don't load if null)
dictionary_pathPath for dictionary (don't load if null)
vocab_pathPath for vocab (don't load if null)
Returns
If this function is successful, it returns true , or false otherwise.
66  {
67  if (net == null){
68  return false;
69  }
70 
71  int status = 0;
72 
73  if (model_path != null){
74  status = AiliaTokenizer.ailiaTokenizerOpenModelFile(net, model_path);
75  if (status != 0){
76  return false;
77  }
78  }
79  if (dictionary_path != null){
80  status = AiliaTokenizer.ailiaTokenizerOpenDictionaryFile(net, dictionary_path);
81  if (status != 0){
82  return false;
83  }
84  }
85  if (vocab_path != null){
86  status = AiliaTokenizer.ailiaTokenizerOpenVocabFile(net, vocab_path);
87  if (status != 0){
88  return false;
89  }
90  }
91 
92  return true;
93  }

The documentation for this class was generated from the following file:
ailiaTokenizer.AiliaTokenizerModel.Dispose
virtual void Dispose()
Release resources.
Definition: AiliaTokenizerModel.cs:124
ailiaTokenizer.AiliaTokenizerModel.Close
virtual void Close()
Destroys instance.
Definition: AiliaTokenizerModel.cs:109