SWATH(1)

πŸ’– SWATH β€” the Thai word segmentation queen πŸ’–

okay bestie, pull up a chair, because swath(1) is about to become your new obsession. it's the general-purpose Thai word segmentation utility, it lives in the General Commands Manual, and it is literally the moment.


✨ NAME ✨

swath β€” general-purpose Thai word segmentation utility πŸ¦‹


🌸 SYNOPSIS 🌸

swath [options] < infile > outfile

that's it. that's the whole vibe. in goes text, out comes text with words actually separated. slay. πŸ’…


πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the tea, bestie: Thai script has no word delimitor. none. zero. it's giving "figure it out yourself." and apps kinda need to know where words end before they can do anything useful with Thai text β€” like, idk, line wrapping? basic stuff? 😭

Swath is here to fix that. it provides a word analysis filter that inserts word delimitors into a given text stream. it reads text from standard input, analyzes it for word boundaries by consulting a Thai word list, and outputs to standard output the same text with the predefined word delimitors inserted. no cap.

currently, it can read plain text, HTML, RTF, LaTeX and Lambda (that's the Unicode version of LaTeX with the Omega typesetter kernel, iykyk) documents and insert common word delimitors for each format β€” pipe | for plain text, obviously. but you can always override this with a preferred delimitor. main character energy fr fr. ✨


πŸ’… OPTIONS πŸ’…

  • -b [delimitor] β€” define the string to be inserted as word delimitor in the output text. your delimitor, your rules. πŸŽ€
  • -d [dict-path] β€” specify an alternative dictionary location. dict-path must be either a directory containing the swath dictionary file swathdic.tri, or a path to the dictionary file itself. the dictionary file must be a trie file prepared using trietool(1) utility from the libdatrie package. if this option is given, swath will override normal dictionary search and will exit if the given dictionary cannot be found. otherwise, if SWATHDICT environment is set, it will try to open the dictionary from the location specified by its value. otherwise, it will try the current working directory, and finally the usual installed location. the search order is that girl. πŸ’€
  • -f [format] β€” specify format of the input. possible formats are: html, rtf, latex, lambda. pick your fighter. πŸ₯Š
  • -m [scheme] β€” choose word matching scheme when analyzing word boundaries. possible schemes are long (for longest or greedy matching) and max (for maximal matching, with least words preferred). maximal matching is the default value. max is the default bestie, don't forget. 🌈
  • -u input-enc,output-enc β€” specify encodings of the input and the output. input-enc and output-enc can be one of 'u' (for UTF-8 encoding) and 't' (for TIS-620 encoding). Swath will convert the character encoding as necessary. if this option is omitted, TIS-620 encodings on both input and output are assumed. yes, both. default. noted. πŸ“
  • -v, --verbose β€” turn on verbose mode. she's chatty now. πŸ—£οΈ
  • -help, --help β€” show help. a little help, as a treat. 🫢

🧚 ENVIRONMENT VARIABLES 🧚

  • SWATHDICT β€” if specified, swath will search for the dictionary from this location before the usual places (current working directory and usual installed directory, respectively). this value is overridden by the -d option. so like, -d is the louder sibling. πŸ‘‘

πŸ”₯ EXAMPLES πŸ”₯

for LaTeX (to be used with babel-thai package):

$ swath -f latex < thaifile.tex > thaifile.ttex
$ latex thaifile.ttex

for HTML (to provide web pages to web browsers that cannot wrap Thai lines properly, but support the <wbr> tag):

$ swath -f html < myweb.html > myweb-wbr.html

to preprocess a Thai UTF-8 encoded LaTeX file for babel-thai with tis620 inputenc:

$ swath -f latex -u u,t < thaifile.tex > thaifile.ttex
$ latex thaifile.ttex

this is equivalent to filtering with iconv(1):

$ iconv -f UTF-8 -t TIS-620 thaifile.tex | swath -f latex >
thaifile.ttex
$ latex thaifile.ttex

to use longest matching scheme with a LaTeX document:

$ swath -f latex -m long < thaifile.tex > thaifile.ttex
$ latex thaifile.ttex

to use an alternative dictionary from libthai:

$ swath -f latex -d /usr/share/libthai/thbrk.tri < thaifile.tex >
thaifile.ttex

look at those pipelines go. ate. πŸ’…βœ¨


πŸŽ€ AUTHOR πŸŽ€

this manual page was written by Theppitak Karoonboonyanan <theppitak@gmail.com>. iconic behavior, honestly. πŸ’œ


and that's the whole page, bestie!! πŸ¦‹ this one's from January 2008 and it's the SWATH(1) page, and yes we are still stanning it all these years later. go segment some Thai text, you absolute legend. mwah. πŸ˜˜πŸ’–πŸŒΈ