@@ -329,6 +329,26 @@ def word_tokenize(
329329
330330
331331def indices_words (words ):
332+ """Convert a list of words to a list of character index pairs.
333+
334+ This function takes a list of words and returns the start and end
335+ character indices for each word in the original text.
336+
337+ :param list words: list of words
338+ :return: list of tuples (start_index, end_index) for each word
339+ :rtype: list[tuple[int, int]]
340+
341+ :Example:
342+ ::
343+
344+ from pythainlp.tokenize import indices_words
345+
346+ indices_words(['สวัสดี', 'ครับ'])
347+ # output: [(0, 5), (6, 9)]
348+
349+ indices_words(['hello', 'world'])
350+ # output: [(0, 4), (5, 9)]
351+ """
332352 indices = []
333353 start_index = 0
334354 for word in words :
@@ -340,6 +360,26 @@ def indices_words(words):
340360
341361
342362def map_indices_to_words (index_list , sentences ):
363+ """Map character index pairs to actual words from sentences.
364+
365+ This function takes a list of character index pairs and a list of
366+ sentences, then extracts the corresponding words from the sentences.
367+
368+ :param list index_list: list of tuples (start_index, end_index)
369+ :param list sentences: list of sentences (strings)
370+ :return: list of lists containing extracted words for each sentence
371+ :rtype: list[list[str]]
372+
373+ :Example:
374+ ::
375+
376+ from pythainlp.tokenize import map_indices_to_words
377+
378+ indices = [(0, 5), (6, 9)]
379+ sentences = ['สวัสดีครับ']
380+ map_indices_to_words(indices, sentences)
381+ # output: [['สวัสดี', 'ครับ']]
382+ """
343383 result = []
344384 c = deque (index_list )
345385 n_sum = 0
@@ -735,6 +775,17 @@ def syllable_tokenize(
735775 <https://github.com/ponrawee/ssg>`_.
736776 * *tltk* - syllable tokenizer from tltk. See `tltk \
737777 <https://pypi.org/project/tltk/>`_.
778+
779+ :Example:
780+ ::
781+
782+ from pythainlp.tokenize import syllable_tokenize
783+
784+ syllable_tokenize("สวัสดีครับ", engine="dict")
785+ # output: ['สวัส', 'ดี', 'ครับ']
786+
787+ syllable_tokenize("ประเทศไทย", engine="dict")
788+ # output: ['ประ', 'เทศ', 'ไทย']
738789 """
739790 if engine not in ["dict" , "han_solo" , "ssg" , "tltk" ]:
740791 raise ValueError (
@@ -890,6 +941,15 @@ def word_tokenize(self, text: str) -> list[str]:
890941 :param str text: text to be tokenized
891942 :return: list of words, tokenized from the text
892943 :rtype: list[str]
944+
945+ :Example:
946+ ::
947+
948+ from pythainlp.tokenize import Tokenizer
949+
950+ tokenizer = Tokenizer()
951+ tokenizer.word_tokenize("สวัสดีครับ")
952+ # output: ['สวัสดี', 'ครับ']
893953 """
894954 return word_tokenize (
895955 text ,
@@ -904,5 +964,15 @@ def set_tokenize_engine(self, engine: str) -> None:
904964
905965 :param str engine: choose between different options of tokenizer engines
906966 (i.e. *newmm*, *mm*, *longest*, *deepcut*)
967+
968+ :Example:
969+ ::
970+
971+ from pythainlp.tokenize import Tokenizer
972+
973+ tokenizer = Tokenizer()
974+ tokenizer.set_tokenize_engine("newmm")
975+ tokenizer.word_tokenize("สวัสดีครับ")
976+ # output: ['สวัสดี', 'ครับ']
907977 """
908978 self .__engine = engine
0 commit comments