Exemplo n.º 1
0
 def _Do(self):
     # 初始化language code
     # from component.rdf.dictionary_rdf import comp_dictionary_rdf
     self.__dict_rdf = None
     if common.common_func.JudgementCountry('hkg','rdf') \
        or common.common_func.JudgementCountry('mac','rdf'):
         self.__dict_rdf = comp_dictionary_rdf_hkg_mac()
     else:
         self.__dict_rdf = comp_dictionary_rdf()
     self.__dict_rdf.set_language_code()
     # ## 方向名称和番号
     self._group_trans_name()
     self._make_signpost_element_phonetic()
     self._make_signpost_element()
     # ## 出口番号
     self._group_trans_exit_no()
     self._make_signpost_exit_no_phonetic()
     self._make_signpost_exit_no()
     # ## 制作PassLink
     # link最少
     # self._make_signpost_passlink()
     # 距离最短
     self._make_short_distance_passlink()
     # ## 把所有SignPost信息都做合起来
     self._merge_all_sigpost_info()
     # ## InLink往前推
     self._push_forward_inlink()
     return 0
 def _Do(self):
     # 初始化language code
     # from component.rdf.dictionary_rdf import comp_dictionary_rdf
     dict_rdf = comp_dictionary_rdf()
     dict_rdf.set_language_code()
     # ## 方向名称和番号
     self._group_trans_name()
     self._make_signpost_element_phonetic()
     self._make_signpost_element()
     # ## 出口番号
     self._group_trans_exit_no()
     self._make_signpost_exit_no_phonetic()
     self._make_signpost_exit_no()
     # ## 制作PassLink
     # link最少
     # self._make_signpost_passlink()
     # 距离最短
     self._make_short_distance_passlink()
     # ## 把所有SignPost信息都做合起来
     self._merge_all_sigpost_info()
     # ## InLink往前推
     self._push_forward_inlink()
     return 0
    def _make_signpost_exit_no(self):
        self.CreateTable2('mid_temp_signpost_exit_no')
        temp_file_obj = cache_file.open('signpost_exit_no')  # 创建临时文件
        sqlcmd = """
        SELECT dest.sign_id, dest.destination_number,
               exit_number, language_code,
               alt_exit_number,
               trans_exit_langs,
               trans_exit_nums,
               iso_country_code,
               phonetic_strings,
               phonetic_language_codes
          FROM rdf_sign_destination as dest
          left join mid_temp_sign_destination_trans_group as trans_group
          ON dest.sign_id = trans_group.sign_id
             and dest.destination_number = trans_group.destination_number
          LEFT JOIN temp_rdf_nav_link
          on dest_link_id = link_id
          LEFT JOIN mid_temp_sign_destination_phonetic AS phonetic
          ON dest.sign_id = phonetic.sign_id AND
             dest.destination_number = phonetic.destination_number
          WHERE exit_number is not null
          ORDER BY dest.sign_id, dest.destination_number;
        """
        dict_rdf = comp_dictionary_rdf()
        exits = self.get_batch_data(sqlcmd)
        for exit_info in exits:
            sign_id = exit_info[0]
            dest_number = exit_info[1]
            exit_number = exit_info[2]
            lang_code = exit_info[3]
            alt_exit_number = exit_info[4]
            trans_langs = exit_info[5]  # 翻译语言
            trans_exit_nums = exit_info[6]  # 翻译文本
            iso_country_code = exit_info[7]
            phonetic_strings = exit_info[8]
            phonetic_lang_codes = exit_info[9]
            sign_post_exit = SignPostExit(sign_id, dest_number)
            name_type = 'office_name'
            if exit_number:
                exit_no = MultiLangNameRDF(lang_code, exit_number, name_type)
                if phonetic_strings:  # 有音素
                    tts_obj = dict_rdf.get_tts_name(iso_country_code,
                                                lang_code,
                                                exit_no.get_name_type(),
                                                phonetic_strings,
                                                phonetic_lang_codes
                                                )
                    if tts_obj:
                        exit_no.set_tts(tts_obj)
                    else:
                        self.log.warning('No TTS. sign_id=%d, dest_number=%d' %
                                         (sign_id, dest_number))
                exit_no = dict_rdf.set_trans_name(exit_no,
                                                  iso_country_code,
                                                  trans_exit_nums,
                                                  trans_langs,
                                                  phonetic_strings,
                                                  phonetic_lang_codes,
                                                  )
                # exit_no.set_trans(trans_exit_nums, trans_langs)
                sign_post_exit.set_exit_no(exit_no)
            else:
                continue
            if alt_exit_number:
                name_type = 'alter_name'
                alt_exit_no = MultiLangNameRDF(lang_code,
                                               alt_exit_number,
                                               name_type)

                sign_post_exit.set_alter_exit_no(alt_exit_no)
            str_info = sign_post_exit.to_string()
            self._store_name_to_temp_file(temp_file_obj, str_info)

        # ## 把名称导入数据库
        temp_file_obj.seek(0)
        self.pg.copy_from2(temp_file_obj, 'mid_temp_signpost_exit_no')
        self.pg.commit2()
        # close file
        #temp_file_obj.close()
        cache_file.close(temp_file_obj,True)
        return 0
    def _make_signpost_element(self):
        self.CreateTable2('mid_temp_signpost_element')
        temp_file_obj = cache_file.open('signpost_element')  # 创建临时文件
        # 排序:sign_id, destination_number(方向ID), entry_number
        # 同个方向上的名称做group (sign_id, destination_number)
        sqlcmd = """
            SELECT element.sign_id,
                   element.destination_number,
                   entry_number,
                   text_type,
                   element."text" as official_name,
                   element.language_code,
                   direction_code,
                   entry_type,
                   text_number,
                   trans_types,
                   trans_group.trans_names as trans_names,
                   iso_country_code,
                   phonetic_strings,
                   phonetic_language_codes
              FROM rdf_sign_element as element
              LEFT JOIN mid_temp_sign_element_trans_group as trans_group
              ON element.sign_element_id = trans_group.sign_element_id
              LEFT JOIN rdf_sign_destination AS dest
              ON element.sign_id = dest.sign_id and
                  element.destination_number = dest.destination_number
              LEFT JOIN temp_rdf_nav_link
              on dest_link_id = link_id
              LEFT JOIN mid_temp_sign_element_phonetic as phonetic
              ON element.sign_element_id = phonetic.sign_element_id
              order by sign_id, destination_number, entry_number
              ;
        """
        signs = self.get_batch_data(sqlcmd)
        from component.rdf.dictionary_rdf import INVALID_SHIELD_ID
        prev_sign_id = None
        curr_sign_id = None
        prev_dest_num = None
        curr_dest_num = None
        signpost = None
        signpost_name = None
        dict_rdf = comp_dictionary_rdf()
        for sign_info in signs:
            curr_sign_id = sign_info[0]
            curr_dest_num = sign_info[1]  # 方向ID
            # entry_number = sign_info[2]  # 同个方向上的名称序号
            text_type = sign_info[3]  # T: 名称, R: 番号
            official_name = sign_info[4]  # 官方语言下的文本
            lang_code = sign_info[5]  # 官方语言种别——ISO Country Code
            # dir_code = sign_info[6]  # 方向, E, S, W, N, '-'
            trans_types = sign_info[9]  # 翻译语言种别
            trans_names = sign_info[10]  # 翻译文本
            iso_country_code = sign_info[11]
            phonetic_strings = sign_info[12]
            phonetic_lang_codes = sign_info[13]
            if not curr_sign_id:
                self.log.error('None sign_id.')
                continue
            if not curr_dest_num:
                self.log.error('None destination_number. sign_id=%d'
                               % curr_sign_id)
                continue
            if (prev_sign_id != curr_sign_id or  # 不同的看板
                prev_dest_num != curr_dest_num):  # 不同的方向
                # 保存上一条
                if prev_dest_num:
                    signpost.set_signpost_name(signpost_name)
                    str_info = signpost.to_string()
                    self._store_name_to_temp_file(temp_file_obj, str_info)
                # 新的一条
                prev_sign_id = curr_sign_id
                prev_dest_num = curr_dest_num
                signpost = SignPostElement(curr_sign_id, curr_dest_num)
                signpost_name = None

            # 名称不存在,或为空
            if not official_name:
                self.log.error('None Name. sign_id=%d.' % prev_sign_id)
                continue
            # ## 番号
            if self._is_route_number(text_type):
                if iso_country_code == 'SGP':
                    shield_id = 4111
                else:
                    shield_id = INVALID_SHIELD_ID
                shield_number = official_name
                shield_obj = MultiLangShieldRDF(shield_id,
                                                shield_number,
                                                lang_code
                                                )
                shield_obj.set_trans(trans_names, trans_types)
                # ## shield不做TTS
#                 shield_obj = dict_rdf.set_trans_name(shield_obj,
#                                                      iso_country_code,
#                                                      trans_names,
#                                                      trans_types,
#                                                      phonetic_strings,
#                                                      phonetic_lang_codes,
#                                                     )
                signpost.add_route_no(shield_obj)
            else:  # 名称
                name_type = 'office_name'
                if signpost_name:  # 同个方向上的其他名称
                    trans_name_obj = MultiLangNameRDF(lang_code,
                                                      official_name,
                                                      name_type)
                    if phonetic_strings:  # 有音素
                        tts_obj = dict_rdf.get_tts_name(iso_country_code,
                                                        lang_code,
                                                        name_type,
                                                        phonetic_strings,
                                                        phonetic_lang_codes
                                                        )
                        if tts_obj:
                            trans_name_obj.set_tts(tts_obj)
                        else:
                            self.log.warning('No TTS.sign_id=%d,dest_number=%d'
                                              % (curr_sign_id, curr_dest_num))
                    trans_name_obj = dict_rdf.set_trans_name(trans_name_obj,
                                                       iso_country_code,
                                                       trans_names,
                                                       trans_types,
                                                       phonetic_strings,
                                                       phonetic_lang_codes,
                                                       )
                    signpost_name.add_alter(trans_name_obj)
                else:  # 当前方向上的第一名称
                    signpost_name = MultiLangNameRDF(lang_code,
                                                     official_name,
                                                     name_type)
                    if phonetic_strings:  # 有音素
                        name_type = signpost_name.get_name_type()
                        tts_obj = dict_rdf.get_tts_name(iso_country_code,
                                                        lang_code,
                                                        name_type,
                                                        phonetic_strings,
                                                        phonetic_lang_codes
                                                        )
                        if tts_obj:
                            signpost_name.set_tts(tts_obj)
                        else:
                            self.log.warning('No TTS.sign_id=%d,dest_number=%d'
                                              % (curr_sign_id, curr_dest_num))

                    signpost_name = dict_rdf.set_trans_name(signpost_name,
                                                            iso_country_code,
                                                            trans_names,
                                                            trans_types,
                                                            phonetic_strings,
                                                            phonetic_lang_codes
                                                            )
        # 最后一条
        signpost.set_signpost_name(signpost_name)
        str_info = signpost.to_string()
        self._store_name_to_temp_file(temp_file_obj, str_info)

        # ## 把名称导入数据库
        temp_file_obj.seek(0)
        self.pg.copy_from2(temp_file_obj, 'mid_temp_signpost_element')
        self.pg.commit2()
        # close file
        #temp_file_obj.close()
        cache_file.close(temp_file_obj,True)
        return 0
Exemplo n.º 5
0
    def CreateOneComponent(self, comp_name):
        if comp_name == 'ImportJCV':
            from component.rdf import import_csv_data_rdf
            return import_csv_data_rdf.import_junctionview_data_rdf()
            pass
        if comp_name == 'Guideinfo_Lane':
            from component.rdf import guideinfo_lane_rdf
            return guideinfo_lane_rdf.comp_guideinfo_lane_rdf()
            pass
        if comp_name == 'Guideinfo_TowardName':
            #from component.rdf import guideinfo_towardname_rdf
            # return guideinfo_towardname_rdf.comp_guideinfo_towardname_rdf()
            pass
        if comp_name == 'rawdata':
            from component.rdf import rawdata_rdf
            return rawdata_rdf.comp_rawdata_rdf()
            pass
        if comp_name == 'park':
            from component.rdf import park_rdf
            return park_rdf.comp_park_rdf()
            pass
        if comp_name == 'slope':
            from component.rdf import slope_rdf
            return slope_rdf.comp_slope_rdf()
            pass
        if comp_name == 'Link':
            from component.rdf import link_rdf
            return link_rdf.comp_link_rdf()
            pass
        if comp_name == 'Node':
            from component.rdf import node_rdf
            return node_rdf.comp_node_rdf()
            pass
        if comp_name == 'Node_Height':
            from component.rdf import node_height_rdf
            return node_height_rdf.comp_node_height_rdf()
            pass
        if comp_name == 'Dictionary':
            if common.common_func.JudgementCountry('hkg','rdf') \
              or common.common_func.JudgementCountry('mac','rdf'):
                from component.rdf import dictionary_rdf_hkgmac
                return dictionary_rdf_hkgmac.comp_dictionary_rdf_hkg_mac()
            else:
                from component.rdf import dictionary_rdf
                return dictionary_rdf.comp_dictionary_rdf()
            pass
        if comp_name == 'Regulation':
            from component.rdf import regulation_rdf
            return regulation_rdf.comp_regulation_rdf()
        if comp_name == 'Guideinfo_SpotGuide':
            from component.rdf import guideinfo_spotguide_rdf
            return guideinfo_spotguide_rdf.comp_guideinfo_spotguide_rdf()
            pass
        if comp_name == 'Link_Name':
            from component.rdf import linkname_rdf
            return linkname_rdf.comp_linkname_rdf()
        if comp_name == 'Trans_Geom':
            from component.rdf import trans_geom_rdf
            return trans_geom_rdf.comp_trans_geom_rdf()
        if comp_name == 'trans_Srid':
            from component.rdf import trans_srid_rdf
            return trans_srid_rdf.comp_trans_srid_rdf()
        if comp_name == 'Admin':
            from component.rdf import admin_rdf
            return admin_rdf.comp_admin_rdf()
        if comp_name == 'Guideinfo_Caution':
            from component.rdf import guideinfo_caution_rdf
            return guideinfo_caution_rdf.comp_guideinfo_caution_rdf()

        if comp_name == 'Guideinfo_Caution_highaccident':
            from component.rdf import guideinfo_caution_highaccident_rdf
            return guideinfo_caution_highaccident_rdf.comp_guideinfo_caution_highaccident_rdf(
            )

        if comp_name == 'Guideinfo_Safety_Zone':
            from component.rdf.guideinfo_safety_zone_rdf import comp_guideinfo_safety_zone_rdf
            return comp_guideinfo_safety_zone_rdf()
        if comp_name == 'GuideInfo_SignPost':
            from component.rdf.guideinfo_signpost_rdf import comp_guideinfo_signpost_rdf
            return comp_guideinfo_signpost_rdf()

        if comp_name == 'guideinfo_signpost_uc':
            from component.rdf import guideinfo_singpost_uc_rdf
            return guideinfo_singpost_uc_rdf.comp_guideinfo_signpost_uc_rdf()
        if comp_name == 'Guideinfo_ForceGuide':
            from component.rdf import guideinfo_forceguide_rdf
            return guideinfo_forceguide_rdf.comp_guideinfo_forceguide_rdf()
        if comp_name == 'Guideinfo_NaturalGuidence':
            from component.rdf import guideinfo_natural_guidence
            return guideinfo_natural_guidence.comp_natural_guidence()
        if comp_name == 'Guideinfo_building':
            from component.rdf import guideinfo_building_rdf
            return guideinfo_building_rdf.comp_guideinfo_building_rdf()
            pass
        if comp_name == 'Shield':
            from component.rdf import shield_rdf
            return shield_rdf.comp_shield_rdf()
        if comp_name == 'Highway':
            from component.rdf.hwy.highway_rdf import HighwayRDF
            return HighwayRDF()
        if comp_name == 'Highway_Prepare':
            from component.rdf.hwy.hwy_prepare_rdf import HwyPrepareRDF
            return HwyPrepareRDF()
        if comp_name == 'stopsign':
            from component.rdf import stopsign_rdf
            return stopsign_rdf.comp_stopsign_rdf()
            pass

        if comp_name == 'Name_filter_and_sort':
            from component.default import rdb_name
            return rdb_name.rdb_name_language_order()

        return comp_factory.CreateOneComponent(self, comp_name)