Skip to content
Split run-together words

Split run-together words with a dictionary

Split run-together words with a dictionary

Read a string with no spaces over the words of a dictionary, every way it tiles into them, and let a grammar choose which tilings to keep (segmentation). Without a dictionary, segment by the text’s own statistics.

$ cat words.txt
the
cat
sat
thecat
on
mat

Count the readings

thecatsat tiles two ways, the cat sat and thecat sat; a grammar asking for three words keeps one:

$ trex grammar --grammar-text 's := <s> ident | ident' --segment thecatsat --dict words.txt --count
2

$ trex grammar --grammar-text 's := ident ident ident' --segment thecatsat --dict words.txt --count
1

With @p weights on the rules, --best gives the probability of the most probable tiling.