Query Optimization for On-Demand Information Extraction Tasks over Text Databases