20. The system of claim 11 , wherein the operations comprise: determining that no substitution contexts are classified in the first category; and in response to determining that no substitution contexts are in the first category, classifying a general context into the first category.
11. A system comprising: one or more computers and one or more storage devices storing instructions that are operable, when executed by the one or more computers, to cause the one or more computers to perform operations comprising: receiving a query having an original term; determining one or more substitution contexts for the original term, wherein a substitution context includes one or more conditions for substituting an original term with a substitute term, wherein the one or more conditions specify one or more context terms from the query and an indication of a position in the query of the original term relative to the one or more context terms; generating a context hierarchy including the one or more substitution contexts for the original term, wherein any conditions of a parent context in the context hierarchy also apply to each of one or more child contexts of a parent context, and wherein each child context in the context hierarchy includes all of the context terms of a parent context of the child context as well as an additional context term that does not occur in the parent context of the child context; determining a respective score for each substitution context of the one or more substitution contexts including comparing the substitution context to its parent substitution context to compute a measure of how much an additional term of the substitution context adds meaning to the original term when choosing substitute terms for the original term; classifying each of the substitution contexts into a first category or a second category based on a respective score of each substitution context; associating the original term with one or more substitution contexts in the first category; and providing only substitution contexts in the first category to a substitute term generation process that generates substitute terms for the original term in the query.