Example #1
0
def update_json():
	json1 = collections.OrderedDict()
	json1 = get_infos.open_json('test1')
	json2 = collections.OrderedDict()
	json2 = get_infos.open_json('test2')
	utterances1_dict = {i['text']:i for i in json1.get('utterances')}	

	utterances2_dict = {i['text']:i for i in json2.get('utterances')}

	utterances2_dict.update(utterances1_dict)

	json2['utterances'] = [value for value in utterances2_dict.values()]
	with open('jsonfile/json2.json','w') as f:
		f.write(json.dumps(json2,ensure_ascii=False,indent=4))
Example #2
0
def get_intens():
    intent = collections.OrderedDict()
    intent = get_infos.open_json('Service_identifier')
    other_intent = excel_table_byindex('./data/intents.xlsx')
    # print(other_intent)
    # return
    intent.get('utterances').extend(other_intent)
    # intent['utterances'] = intent.get('utterances') + other_intent

    with open('jsonfile/intents.json', 'w') as f:
        f.write(json.dumps(intent, ensure_ascii=False, indent=4))
Example #3
0
def get_airport():
    airport = collections.OrderedDict()
    airport = get_infos.open_json('airport')
    new_airport = excel_table_byindex('./data/airports.xlsx')
    # print(new_airport)
    international = airport.get('国际')
    new_dict = {}
    for item in new_airport:
        port = new_dict.get(item[0], [])
        # print(port)
        code = collections.OrderedDict()
        code['id'] = item[1]
        code['name'] = item[2]
        port.append(code)
        new_dict[item[0]] = port
    # international.update(new_dict)
    for key, value in new_dict.items():
        flag = False
        # value = {item['id']:item for item in value}
        # for air_id in value.keys():
        old_codes = [
            port['id'] for value2 in international.values() for port in value2
        ]
        new_codes = [item['id'] for item in value]
        inter_code = set(new_codes).intersection(set(old_codes))
        if inter_code:
            port_dict = {item['id']: item for item in value}
            differ_code = set(new_codes).difference(set(old_codes))
            add_data = [port_dict[k] for k in differ_code]
            # 查找原始数据的key,将不存在的数据添加进去
            for key2, value2 in international.items():
                if inter_code.intersection(set([item['id']
                                                for item in value2])):
                    international[key2].extend(add_data)
                    break
        else:
            international[key] = value
            # for key2,value2 in international.items():
            #     for air in value2:
            #         if air_id == air['id']:
            #             # 是同一个城市
            #             flag = True
            #             break

    airport['国际'] = international

    with open('jsonfile/new-airport.json', 'w') as f:
        f.write(json.dumps(airport, ensure_ascii=False, indent=4))
Example #4
0
def get_airport():
    order_json = collections.OrderedDict()
    row_data = get_infos.open_json('alternative_names')
    other_data = excel_table_byindex('./data/other_name.xlsx')
    new_dict = {}
    for item in other_data:
        new_dict[item[0]] = [
            value for key, value in item.items()
            if not (value.strip() == '' or key == 0)
        ]

    row_data['V5.4'] = new_dict
    # print(row_data)
    # return
    with open('jsonfile/new_alternative_names.json', 'w') as f:
        f.write(json.dumps(row_data, ensure_ascii=False, indent=2))
Example #5
0
        elif types == 'start_end':
            entities = start_end_json(item)
        elif types == 'end_start':
            entities = end_start_json(item)
        else:
            print('types error')
            return

        start_json['entities'] = entities
        start_jsons.append(start_json)

    print(len(start_jsons))
    return start_jsons
    # with open('jsonfile/%s.json'%types,'w') as f:
    #     f.write(json.dumps(start_jsons,ensure_ascii=False,indent=4,sort_keys=True))


if __name__ == '__main__':
    city = get_city_json()
    start = get_json('start')
    end = get_json('end')
    start_end = get_json('start_end')
    end_start = get_json('end_start')
    apirport = get_airline_json()
    json_data = start + end + start_end + end_start + apirport + city
    row_data = collections.OrderedDict()
    row_data = open_json('Flight-Tickets')
    row_data['utterances'].extend(json_data)
    with open('jsonfile/json-data3.json', 'w') as f:
        f.write(json.dumps(row_data, ensure_ascii=False, indent=4))