Build term document matrix