def add_tag_trees(self): f = file('geo_dataset.txt', 'r') with_trees = [] for line in f: line = re.sub("\n", '', line) l = line.split(',') question = l[0] tree = tagger.to_tree(question) with_trees.append(line + "," + tree + "\n") f.close() f = file('rest_with_trees', 'w+') for w in with_trees: f.write(w) f.close()
def main(): questions_filename = raw_input('>>> File name containing the questions: ') queries_filename = raw_input('>>> File name containing the queries: ') queries = json.load(open(queries_filename, 'r')) questions = open(questions_filename, 'r').readlines() q = [] t = [] for question in questions: temp = question.split('\t\t') q.append(temp[0]) t.append(temp[1].strip()) questions = [] for (i, question) in enumerate(q): temp = {} temp['query'] = queries[t[i]] temp['question'] = question temp['tree'] = stanford_client.to_tree(question) questions.append(temp) f = open('IMS_questions.txt','w') f.write(json.dumps(questions, sort_keys=True,indent=4, separators=(',', ': ')))