calculating term frequencies across documents