def _make_hwy_exit_poi_name(self): ''' ''' self.log.info('start make mid_temp_hwy_exit_poi_name') sqlcmd = ''' SELECT distinct node_id, poi.poi_id, rdf_poi_name.language_code, rdf_poi_name.name, trans_group.trans_type, trans_group.trans_name FROM mid_temp_hwy_exit_poi as poi LEFT JOIN rdf_poi_names ON poi.poi_id = rdf_poi_names.poi_id LEFT JOIN rdf_poi_name ON rdf_poi_names.name_id = rdf_poi_name.name_id LEFT JOIN mid_temp_hwy_exit_poi_name_trans_group AS trans_group ON rdf_poi_names.name_id = trans_group.name_id LEFT JOIN rdf_poi_address ON poi.poi_id = rdf_poi_address.poi_id LEFT JOIN wkt_location ON rdf_poi_address.location_id = wkt_location.location_id LEFT JOIN node_tbl ON ST_DWithin(node_tbl.the_geom, poi.the_geom, 0.000002694945852358566745) ORDER BY node_id, poi.poi_id, language_code ''' temp_file_obj = cache_file.open('hwy_exit_poi_name') names = self.get_batch_data(sqlcmd) multi_name = None pre_node_id = None curr_node_id = None for nameinfo in names: curr_node_id = nameinfo[0] poi_id = nameinfo[1] lang_code = nameinfo[2] official_name = nameinfo[3] trans_type = nameinfo[4] trans_name = nameinfo[5] if not curr_node_id: # POI id不存在 self.log.error("No node ID.") continue if pre_node_id != curr_node_id: if pre_node_id: json_name = multi_name.json_format_dump() if not json_name: self.log.error('Json Name is none. node_id=%d' % curr_node_id) self._store_name_to_temp_file(temp_file_obj, pre_node_id, poi_id, json_name) # 初始化 multi_name = MultiLangNameRDF(lang_code, official_name) multi_name = self.set_trans_name(multi_name, None, trans_name, trans_type, None, None) pre_node_id = curr_node_id else: alter_name = MultiLangNameRDF(lang_code, official_name) alter_name = self.set_trans_name(alter_name, None, trans_name, trans_type, None, None) multi_name.add_alter(alter_name) # ## 最后一个node的名称 if multi_name: json_name = multi_name.json_format_dump() if not json_name: self.log.error('Json Name is none. nodeid=%s, poi_id=%s' % (curr_node_id, poi_id)) self._store_name_to_temp_file(temp_file_obj, pre_node_id, poi_id, json_name) # ## 把名称导入数据库 temp_file_obj.seek(0) self.pg.copy_from2(temp_file_obj, 'mid_temp_hwy_exit_poi_name') self.pg.commit2() cache_file.close(temp_file_obj, True) self.log.info('end make mid_temp_hwy_exit_poi_name') return 0
def _make_tollgate_name(self): '''高速收费站名称''' self.log.info('Start make hwy toll name') self.CreateTable2('hwy_tollgate_name') temp_file_obj = cache_file.open('temp_toll_facil_name') multi_name_obj = None alter_name_obj = None for one_junction_name in self._get_tollgate_names(): (node_id, seq_nm_list, language_list, names_list) = one_junction_name name_list = zip(seq_nm_list, language_list, names_list) name_list.sort(cmp=lambda x, y: cmp(x[0], y[0]), reverse=False) for name_info in name_list: seq_nm = name_info[0] language = name_info[1].split('|') name = name_info[2].split('|') one_names = zip(language, name) one_names.sort(cmp=lambda x, y: cmp(x[0], y[0]), reverse=False) if int(seq_nm) == 1: for index in xrange(0, len(one_names)): (org_lang, name) = one_names[index] lang = LANG_CODE_DICT.get(int(org_lang)) if not lang: self.log.error('Unknown language code.') continue if index == 0: if lang not in ('CHI', 'CHT'): self.log.error('no CHI or CHT name') break multi_name_obj = MultiLangNameRDF(lang, name) else: multi_name_obj = self.set_trans_name( multi_name_obj, None, name, lang, None, # phone None # lang ) else: for index in xrange(0, len(one_names)): (org_lang, name) = one_names[index] lang = LANG_CODE_DICT.get(int(org_lang)) if not lang: self.log.error('Unknown language_code=%s.' % org_lang) continue if index == 0: if lang not in ('CHI', 'CHT'): self.log.error('no CHI or CHT name') break alter_name_obj = MultiLangNameRDF(lang, name) else: alter_name_obj = self.set_trans_name( alter_name_obj, None, name, lang, None, # phonetic None # lang_code ) multi_name_obj.add_alter(alter_name_obj) if multi_name_obj: json_name = multi_name_obj.json_format_dump() if not json_name: self.log.error('no json name o.O') # 存到本地的临时文件 self._store_name_to_temp_file(temp_file_obj, node_id, json_name) # ## 把名称导入数据库 temp_file_obj.seek(0) self.pg.copy_from2(temp_file_obj, 'hwy_tollgate_name') self.pg.commit2() cache_file.close(temp_file_obj, True) self.log.info('end make hwy toll name')
def _make_hwy_exit_name(self): temp_file_obj = cache_file.open('link_name') # 创建临时文件 prev_link_id = None curr_link_id = None prev_is_exit_name = None curr_is_exit_name = None prev_is_junction_name = None curr_is_junction_name = None multi_name_obj = None for nameinfo in self._get_exit_names(): curr_link_id = nameinfo[0] ref_node_id = '' nonref_node_id = '' curr_is_exit_name = nameinfo[1] curr_is_junction_name = nameinfo[2] lang_code = nameinfo[3] # 官方语言种别 official_name = nameinfo[4] # 官方语言种别道路名称 trans_langs = nameinfo[5] # 翻译语言种别 trans_names = nameinfo[6] # 翻译语言种别道路名称 if not curr_link_id: # link id不存在 self.log.error("No Link ID.") continue if prev_link_id != curr_link_id: # Link id 变更 if prev_link_id: # ## 保存上一条link的名称 json_name = multi_name_obj.json_format_dump() if not json_name: self.log.error('Json Name is none. linkid=%d' % prev_link_id) # 存到本地的临时文件 self._store_name_to_temp_file(temp_file_obj, prev_link_id, ref_node_id, nonref_node_id, prev_is_exit_name, prev_is_junction_name, json_name) # ## 初始化 multi_name_obj = MultiLangNameRDF(lang_code, official_name) multi_name_obj = self.set_trans_name(multi_name_obj, None, trans_names, trans_langs, None, # phonetic None # lang_codes ) prev_link_id = curr_link_id prev_is_exit_name = curr_is_exit_name prev_is_junction_name = curr_is_junction_name else: # Link_id 没有变化 if(prev_is_exit_name != curr_is_exit_name or prev_is_junction_name != curr_is_junction_name): json_name = multi_name_obj.json_format_dump() if not json_name: self.log.error('Json Name is none. linkid=%d' % prev_link_id) # 存到本地的临时文件 self._store_name_to_temp_file(temp_file_obj, prev_link_id, ref_node_id, nonref_node_id, prev_is_exit_name, prev_is_junction_name, json_name) multi_name_obj = MultiLangNameRDF(lang_code, official_name) multi_name_obj = self.set_trans_name(multi_name_obj, None, trans_names, trans_langs, None, # phonetic None # lang_code ) prev_link_id = curr_link_id prev_is_exit_name = curr_is_exit_name prev_is_junction_name = curr_is_junction_name else: alter_name = MultiLangNameRDF(lang_code, official_name) alter_name = self.set_trans_name(alter_name, None, trans_names, trans_langs, None, None ) multi_name_obj.add_alter(alter_name) # ## 最后一条link的名称 if multi_name_obj: json_name = multi_name_obj.json_format_dump() if not json_name: self.log.error('Json Name is none. linkid=%s' % prev_link_id) # 存到本地的临时文件 self._store_name_to_temp_file(temp_file_obj, prev_link_id, ref_node_id, nonref_node_id, prev_is_exit_name, prev_is_junction_name, json_name) # ## 把名称导入数据库 temp_file_obj.seek(0) self.pg.copy_from2(temp_file_obj, 'mid_temp_hwy_exit_name') self.pg.commit2() # close file # temp_file_obj.close() cache_file.close(temp_file_obj, True) self.CreateIndex2('temp_link_name_link_id_idx') self.log.info('End Make Link Name.') return 0
def _make_hwy_sapa_name(self): temp_file_obj = cache_file.open('sapa_name') # 创建临时文件 curr_poi_id = None prev_poi_id = None multi_name_obj = None for nameinfo in self._get_sapa_names(): curr_poi_id = nameinfo[0] lang_code = nameinfo[2] official_name = nameinfo[3] trans_langs = nameinfo[4] trans_names = nameinfo[5] if not curr_poi_id: # POI id不存在 self.log.error("No poi ID.") continue if prev_poi_id != curr_poi_id: # POI id 变更 if prev_poi_id: # ## 保存上一POI的名称 json_name = multi_name_obj.json_format_dump() if not json_name: self.log.error('Json Name is none. poi_id=%d' % prev_poi_id) # 存到本地的临时文件 self._store_name_to_temp_file(temp_file_obj, prev_poi_id, json_name) # ## 初始化 multi_name_obj = MultiLangNameRDF(lang_code, official_name) multi_name_obj = self.set_trans_name( multi_name_obj, None, trans_names, trans_langs, None, # phonetic_strings None) prev_poi_id = curr_poi_id else: # POI_id 没有变化 alter_name = MultiLangNameRDF(lang_code, official_name) alter_name = self.set_trans_name(alter_name, None, trans_names, trans_langs, None, None) multi_name_obj.add_alter(alter_name) # ## 最后一条link的名称 if multi_name_obj: json_name = multi_name_obj.json_format_dump() if not json_name: self.log.error('Json Name is none. pio_id=%s' % prev_poi_id) # 存到本地的临时文件 self._store_name_to_temp_file(temp_file_obj, prev_poi_id, json_name) # ## 把名称导入数据库 temp_file_obj.seek(0) self.pg.copy_from2(temp_file_obj, 'mid_temp_hwy_sapa_name') self.pg.commit2() # close file # temp_file_obj.close() cache_file.close(temp_file_obj, True) self.CreateIndex2('temp_link_name_link_id_idx') self.log.info('End Make Link Name.') return 0
def _make_link_name(self): "道路名称(包括道路番号)字典" self.log.info('Make Link Name.') sqlcmd = """ SELECT gid, name.link_id, language_code, street_name, trans_types, trans_names, route_type, is_name_on_roadsign, name.road_name_id, iso_country_code, phonetic_strings, phonetic_language_codes FROM mid_temp_road_name as name LEFT JOIN mid_temp_road_name_trans_group as trans ON name.road_name_id = trans.road_name_id LEFT JOIN temp_rdf_nav_link ON name.link_id = temp_rdf_nav_link.link_id LEFT JOIN mid_temp_road_phonetic as tts ON name.road_name_id = tts.road_name_id order by link_id, gid; """ temp_file_obj = cache_file.open('link_name') # 创建临时文件 names = self.get_batch_data(sqlcmd) prev_link_id = None curr_link_id = None multi_name_obj = None for nameinfo in names: curr_link_id = nameinfo[1] lang_code = nameinfo[2] # 官方语言种别 official_name = nameinfo[3] # 官方语言种别道路名称 trans_langs = nameinfo[4] # 翻译语言种别 trans_names = nameinfo[5] # 翻译语言种别道路名称 route_type = nameinfo[6] # 番号种别 is_office_name = nameinfo[7] road_name_id = nameinfo[8] iso_country_code = nameinfo[9] phonetic_strings = nameinfo[10] # TTS音素 phonetic_lang_codes = nameinfo[11] # 音素语言种别 if not curr_link_id: # link id不存在 self.log.error("No Link ID.") continue if prev_link_id != curr_link_id: # Link id 变更 if prev_link_id: # ## 保存上一条link的名称 json_name = multi_name_obj.json_format_dump() if not json_name: self.log.error('Json Name is none. linkid=%d' % prev_link_id) # 存到本地的临时文件 self._store_name_to_temp_file(temp_file_obj, prev_link_id, json_name) # ## 初始化 name_type = self._get_name_type(is_office_name, route_type, True) multi_name_obj = MultiLangNameRDF(lang_code, official_name, name_type) if phonetic_strings: # 有音素 tts_obj = self.get_tts_name(iso_country_code, lang_code, name_type, phonetic_strings, phonetic_lang_codes) if tts_obj: multi_name_obj.set_tts(tts_obj) else: self.log.warning('No TTS. linkid=%d, name_id=%d' % (curr_link_id, road_name_id)) multi_name_obj = self.set_trans_name(multi_name_obj, iso_country_code, trans_names, trans_langs, phonetic_strings, phonetic_lang_codes) prev_link_id = curr_link_id else: # Link_id 没有变化 name_type = self._get_name_type(is_office_name, route_type) alter_name = MultiLangNameRDF(lang_code, official_name, name_type) if phonetic_strings: tts_obj = self.get_tts_name(iso_country_code, lang_code, name_type, phonetic_strings, phonetic_lang_codes) if tts_obj: alter_name.set_tts(tts_obj) else: self.log.warning('No TTS. linkid=%d, name_id=%d' % (curr_link_id, road_name_id)) alter_name = self.set_trans_name(alter_name, iso_country_code, trans_names, trans_langs, phonetic_strings, phonetic_lang_codes) multi_name_obj.add_alter(alter_name) # ## 最后一条link的名称 json_name = multi_name_obj.json_format_dump() if not json_name: self.log.error('Json Name is none. linkid=' % prev_link_id) # 存到本地的临时文件 self._store_name_to_temp_file(temp_file_obj, prev_link_id, json_name) # ## 把名称导入数据库 temp_file_obj.seek(0) self.pg.copy_from2(temp_file_obj, 'temp_link_name') self.pg.commit2() # close file #temp_file_obj.close() cache_file.close(temp_file_obj, True) self.CreateIndex2('temp_link_name_link_id_idx') self.log.info('End Make Link Name.') return 0