1. A method, comprising: receiving input of a plurality of sample phrases each comprising a plurality of words; representing each sample phrase as a node in a tree; forming a mathematical expression for each pair of nodes in the tree, the mathematical expression comprising a plurality of words found in the sample phrases of a pair of nodes and an indication of whether a word is a common word that occurs in each of the plurality of phrases or an optional word that occurs in some of the plurality of phrases for the pair of nodes; and generating a compact mathematical expression by comparing mathematical expressions, wherein the compact mathematical expression includes each of the plurality of words found in the sample phrases and an indication of whether each of the plurality of words is a common word or an optional word.