Add test and code for word segmentation