def test_latin(self): self.assertEqual( u"Jean Michel Jarre", util.translate_from_sortname(u"Jean Michel Jarre", u"Jarre, Jean Michel") ) self.assertNotEqual( u"Jarre, Jean Michel", util.translate_from_sortname(u"Jean Michel Jarre", u"Jarre, Jean Michel") )
def test_kanji(self): self.failUnlessEqual( u"Tetsuya Komuro", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya")) self.failIfEqual( u"Komuro, Tetsuya", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya")) self.failIfEqual( u"小室哲哉", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya"))
def test_kanji(self): self.assertEqual( "Tetsuya Komuro", util.translate_from_sortname("小室哲哉", "Komuro, Tetsuya")) # see _reverse_sortname(), cases with 3 or 4 chunks self.assertEqual("c b a", util.translate_from_sortname("小室哲哉", "a, b, c")) self.assertEqual("b a, d c", util.translate_from_sortname("小室哲哉", "a, b, c, d"))
def test_latin(self): self.assertEqual( u"Jean Michel Jarre", util.translate_from_sortname(u"Jean Michel Jarre", u"Jarre, Jean Michel")) self.assertNotEqual( u"Jarre, Jean Michel", util.translate_from_sortname(u"Jean Michel Jarre", u"Jarre, Jean Michel"))
def test_kanji(self): self.assertEqual( u"Tetsuya Komuro", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya")) self.assertNotEqual( u"Komuro, Tetsuya", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya")) self.assertNotEqual( u"小室哲哉", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya"))
def test_latin(self): self.failUnlessEqual( u"Jean Michel Jarre", util.translate_from_sortname(u"Jean Michel Jarre", u"Jarre, Jean Michel")) self.failIfEqual( u"Jarre, Jean Michel", util.translate_from_sortname(u"Jean Michel Jarre", u"Jarre, Jean Michel"))
def test_kanji2(self): self.assertEqual( u"Ayumi Hamasaki & Keiko", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko") ) self.assertNotEqual( u"浜崎あゆみ & KEIKO", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko") ) self.assertNotEqual( u"Hamasaki, Ayumi & Keiko", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko") )
def test_kanji2(self): self.failUnlessEqual( u"Ayumi Hamasaki & Keiko", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko")) self.failIfEqual( u"浜崎あゆみ & KEIKO", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko")) self.failIfEqual( u"Hamasaki, Ayumi & Keiko", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko"))
def test_kanji2(self): self.assertEqual( u"Ayumi Hamasaki & Keiko", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko")) self.assertNotEqual( u"浜崎あゆみ & KEIKO", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko")) self.assertNotEqual( u"Hamasaki, Ayumi & Keiko", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko"))
def test_cyrillic(self): self.assertEqual( U"Pyotr Ilyich Tchaikovsky", util.translate_from_sortname(u"Пётр Ильич Чайковский", u"Tchaikovsky, Pyotr Ilyich")) self.assertNotEqual( u"Tchaikovsky, Pyotr Ilyich", util.translate_from_sortname(u"Пётр Ильич Чайковский", u"Tchaikovsky, Pyotr Ilyich")) self.assertNotEqual( u"Пётр Ильич Чайковский", util.translate_from_sortname(u"Пётр Ильич Чайковский", u"Tchaikovsky, Pyotr Ilyich"))
def test_cyrillic(self): self.assertEqual( u"Pyotr Ilyich Tchaikovsky", util.translate_from_sortname(u"Пётр Ильич Чайковский", u"Tchaikovsky, Pyotr Ilyich"), ) self.assertNotEqual( u"Tchaikovsky, Pyotr Ilyich", util.translate_from_sortname(u"Пётр Ильич Чайковский", u"Tchaikovsky, Pyotr Ilyich"), ) self.assertNotEqual( u"Пётр Ильич Чайковский", util.translate_from_sortname(u"Пётр Ильич Чайковский", u"Tchaikovsky, Pyotr Ilyich"), )
def _translate_artist_node(node, config=None): transl, translsort = None, None if config and config.setting['translate_artist_names']: locale = config.setting["artist_locale"] lang = locale.split("_")[0] if "alias_list" in node.children: found_primary = found_locale = False for alias in node.alias_list[0].alias: if alias.attribs.get( "type") != "Search hint" and "locale" in alias.attribs: if alias.locale == locale: transl, translsort = alias.text, alias.attribs[ "sort_name"] if alias.attribs.get("primary") == "primary": return (transl, translsort) found_locale = True elif alias.locale == lang and not (found_locale or found_primary): transl, translsort = alias.text, alias.attribs[ "sort_name"] if alias.attribs.get("primary") == "primary": found_primary = True if lang == "en" and not transl: transl = translate_from_sortname(node.name[0].text, node.sort_name[0].text) return (transl, translsort)
def _translate_artist_node(node, config=None): transl = None if config and config.setting['translate_artist_names']: locale = config.setting["artist_locale"] lang = locale.split("_")[0] if "alias_list" in node.children: for alias in node.alias_list[0].alias: if "locale" in alias.attribs: if alias.locale == locale: return alias.text elif alias.locale == lang: transl = alias.text if lang == "en" and not transl: transl = translate_from_sortname(node.name[0].text, node.sort_name[0].text) return transl
def _translate_artist_node(node, config=None): transl = None if config and config.setting['translate_artist_names']: locale = config.setting["artist_locale"] lang = locale.split("_")[0] if "alias_list" in node.children: for alias in node.alias_list[0].alias: if "locale" in alias.attribs: if alias.locale == locale: return alias.text elif alias.locale == lang: transl = alias.text if lang == "en" and not transl: transl = translate_from_sortname(node.name[0].text, node.sort_name[0].text) return transl
def _translate_artist_node(node): config = get_config() transl, translsort = None, None if config.setting['translate_artist_names']: locale = config.setting["artist_locale"] lang = locale.split("_")[0] if "aliases" in node: result = (-1, (None, None)) for alias in node['aliases']: if not alias["primary"]: continue if "locale" not in alias: continue parts = [] if alias['locale'] == locale: score = 0.8 elif alias['locale'] == lang: score = 0.6 elif alias['locale'].split("_")[0] == lang: score = 0.4 else: continue parts.append((score, 5)) if alias["type"] == "Artist name": score = 0.8 elif alias["type"] == "Legal Name": score = 0.5 else: # as 2014/09/19, only Artist or Legal names should have the # Primary flag score = 0.0 parts.append((score, 5)) comb = linear_combination_of_weights(parts) if comb > result[0]: result = (comb, (alias['name'], alias["sort-name"])) transl, translsort = result[1] if not transl: translsort = node['sort-name'] transl = translate_from_sortname(node['name'] or "", translsort) else: transl, translsort = node['name'], node['sort-name'] return (transl, translsort)
def _translate_artist_node(node): transl, translsort = None, None if config.setting['translate_artist_names']: locale = config.setting["artist_locale"] lang = locale.split("_")[0] if "alias_list" in node.children: result = (-1, (None, None)) for alias in node.alias_list[0].alias: if alias.attribs.get("primary") != "primary": continue if "locale" not in alias.attribs: continue parts = [] if alias.locale == locale: score = 0.8 elif alias.locale == lang: score = 0.6 elif alias.locale.split("_")[0] == lang: score = 0.4 else: continue parts.append((score, 5)) if alias.attribs.get("type") == "Artist name": score = 0.8 elif alias.attribs.get("type") == "Legal Name": score = 0.5 else: # as 2014/09/19, only Artist or Legal names should have the # Primary flag score = 0.0 parts.append((score, 5)) comb = linear_combination_of_weights(parts) if comb > result[0]: result = (comb, (alias.text, alias.attribs["sort_name"])) transl, translsort = result[1] if not transl: translsort = node.sort_name[0].text transl = translate_from_sortname(node.name[0].text, translsort) else: transl, translsort = node.name[0].text, node.sort_name[0].text return (transl, translsort)
def _translate_artist_node(node): transl, translsort = None, None if config.setting['translate_artist_names']: locale = config.setting["artist_locale"] lang = locale.split("_")[0] if "aliases" in node: result = (-1, (None, None)) for alias in node['aliases']: if not alias["primary"]: continue if "locale" not in alias: continue parts = [] if alias['locale'] == locale: score = 0.8 elif alias['locale'] == lang: score = 0.6 elif alias['locale'].split("_")[0] == lang: score = 0.4 else: continue parts.append((score, 5)) if alias["type"] == "Artist name": score = 0.8 elif alias["type"] == "Legal Name": score = 0.5 else: # as 2014/09/19, only Artist or Legal names should have the # Primary flag score = 0.0 parts.append((score, 5)) comb = linear_combination_of_weights(parts) if comb > result[0]: result = (comb, (alias['name'], alias["sort-name"])) transl, translsort = result[1] if not transl: translsort = node['sort-name'] transl = translate_from_sortname(node['name'] or "", translsort) else: transl, translsort = node['name'], node['sort-name'] return (transl, translsort)
def _translate_artist_node(node): transl, translsort = None, None if config.setting['translate_artist_names']: locale = config.setting["artist_locale"] lang = locale.split("_")[0] if "alias_list" in node.children: result = (-1, (None, None)) for alias in node.alias_list[0].alias: if alias.attribs.get("primary") != "primary": continue if "locale" not in alias.attribs: continue parts = [] if alias.locale == locale: score = 0.8 elif alias.locale == lang: score = 0.6 elif alias.locale.split("_")[0] == lang: score = 0.4 else: continue parts.append((score, 5)) if alias.attribs.get("type") == u"Artist name": score = 0.8 elif alias.attribs.get("type") == u"Legal Name": score = 0.5 else: # as 2014/09/19, only Artist or Legal names should have the # Primary flag score = 0.0 parts.append((score, 5)) comb = linear_combination_of_weights(parts) if comb > result[0]: result = (comb, (alias.text, alias.attribs["sort_name"])) transl, translsort = result[1] if not transl: translsort = node.sort_name[0].text transl = translate_from_sortname(node.name[0].text, translsort) else: transl, translsort = node.name[0].text, node.sort_name[0].text return (transl, translsort)
def _translate_artist_node(node): transl, translsort = None, None if config.setting['translate_artist_names']: locale = config.setting["artist_locale"] lang = locale.split("_")[0] if "alias_list" in node.children: found_primary = found_locale = False for alias in node.alias_list[0].alias: if alias.attribs.get("type") != "Search hint" and "locale" in alias.attribs: if alias.locale == locale: transl, translsort = alias.text, alias.attribs["sort_name"] if alias.attribs.get("primary") == "primary": return (transl, translsort) found_locale = True elif alias.locale == lang and not (found_locale or found_primary): transl, translsort = alias.text, alias.attribs["sort_name"] if alias.attribs.get("primary") == "primary": found_primary = True if lang == "en" and not transl: transl = translate_from_sortname(node.name[0].text, node.sort_name[0].text) return (transl, translsort)
def test_cyrillic(self): self.failUnlessEqual(U"Pyotr Ilyich Tchaikovsky", util.translate_from_sortname(u"Пётр Ильич Чайковский", u"Tchaikovsky, Pyotr Ilyich")) self.failIfEqual(u"Tchaikovsky, Pyotr Ilyich", util.translate_from_sortname(u"Пётр Ильич Чайковский", u"Tchaikovsky, Pyotr Ilyich")) self.failIfEqual(u"Пётр Ильич Чайковский", util.translate_from_sortname(u"Пётр Ильич Чайковский", u"Tchaikovsky, Pyotr Ilyich"))
def test_kanji(self): self.failUnlessEqual(u"Tetsuya Komuro", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya")) self.failIfEqual(u"Komuro, Tetsuya", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya")) self.failIfEqual(u"小室哲哉", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya"))
def test_kanji2(self): self.failUnlessEqual(u"Ayumi Hamasaki & Keiko", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko")) self.failIfEqual(u"浜崎あゆみ & KEIKO", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko")) self.failIfEqual(u"Hamasaki, Ayumi & Keiko", util.translate_from_sortname(u"浜崎あゆみ & KEIKO", u"Hamasaki, Ayumi & Keiko"))
def _translate_artist_node(node): config = get_config() transl, translsort = None, None if config.setting['translate_artist_names']: if config.setting['translate_artist_names_script_exception']: threshhold = config.setting["artist_script_exception_weighting"] / 100 detected_scripts = list_script_weighted(node["name"], threshhold) for script_id in config.setting["artist_script_exceptions"]: if script_id in detected_scripts: return node['name'], node['sort-name'] def check_higher_score(locale_dict, locale, score): return locale not in locale_dict or score > locale_dict[locale][0] # Prepare dictionaries of available locale aliases full_locales = {} root_locales = {} if "aliases" in node: for alias in node['aliases']: if not alias["primary"]: continue if "locale" not in alias: continue full_locale = alias['locale'] root_locale = full_locale.split("_")[0] full_parts = [] root_parts = [] score = 0.8 full_parts.append((score, 5)) if '_' in full_locale: score = 0.4 root_parts.append((score, 5)) if alias["type"] == "Artist name": score = 0.8 elif alias["type"] == "Legal Name": score = 0.5 else: # as 2014/09/19, only Artist or Legal names should have the # Primary flag score = 0.0 full_parts.append((score, 5)) root_parts.append((score, 5)) comb = linear_combination_of_weights(full_parts) if check_higher_score(full_locales, full_locale, comb): full_locales[full_locale] = (comb, (alias['name'], alias["sort-name"])) comb = linear_combination_of_weights(root_parts) if check_higher_score(root_locales, root_locale, comb): root_locales[root_locale] = (comb, (alias['name'], alias["sort-name"])) # First pass to match full locale if available for locale in config.setting["artist_locales"]: if locale in full_locales: return full_locales[locale][1] # Second pass to match root locale if available for locale in config.setting["artist_locales"]: lang = locale.split("_")[0] if lang in root_locales: return root_locales[lang][1] # No matches found in available alias locales translsort = node['sort-name'] transl = translate_from_sortname(node['name'] or "", translsort) else: transl, translsort = node['name'], node['sort-name'] return (transl, translsort)
def _translate_artist_node(node): config = get_config() transl, translsort = None, None if config.setting['translate_artist_names']: if config.setting['translate_artist_names_script_exception']: log_text = 'Script alpha characters found in "{0}": '.format( node["name"], ) detected_scripts = detect_script_weighted(node["name"]) if detected_scripts: log_text += "; ".join( list("{0} ({1:.1f}%)".format( scr_id, detected_scripts[scr_id] * 100) for scr_id in detected_scripts)) else: log_text += "None" log.debug(log_text) if detected_scripts: if config.setting["script_exceptions"]: log_text = " found in selected scripts: " + "; ".join( list("{0} ({1}%)".format(scr[0], scr[1]) for scr in config.setting["script_exceptions"])) for script_id, script_weighting in config.setting[ "script_exceptions"]: if script_id in detected_scripts and detected_scripts[ script_id] >= script_weighting / 100: log.debug("Match" + log_text) return node['name'], node['sort-name'] log.debug("No match" + log_text) else: log.warning( "No scripts selected for translation exception match check." ) def check_higher_score(locale_dict, locale, score): return locale not in locale_dict or score > locale_dict[locale][0] # Prepare dictionaries of available locale aliases full_locales = {} root_locales = {} if "aliases" in node: for alias in node['aliases']: if not alias["primary"]: continue if "locale" not in alias: continue full_locale = alias['locale'] root_locale = full_locale.split("_")[0] full_parts = [] root_parts = [] score = 0.8 full_parts.append((score, 5)) if '_' in full_locale: score = 0.4 root_parts.append((score, 5)) if alias["type"] == "Artist name": score = 0.8 elif alias["type"] == "Legal Name": score = 0.5 else: # as 2014/09/19, only Artist or Legal names should have the # Primary flag score = 0.0 full_parts.append((score, 5)) root_parts.append((score, 5)) comb = linear_combination_of_weights(full_parts) if check_higher_score(full_locales, full_locale, comb): full_locales[full_locale] = (comb, (alias['name'], alias["sort-name"])) comb = linear_combination_of_weights(root_parts) if check_higher_score(root_locales, root_locale, comb): root_locales[root_locale] = (comb, (alias['name'], alias["sort-name"])) # First pass to match full locale if available for locale in config.setting["artist_locales"]: if locale in full_locales: return full_locales[locale][1] # Second pass to match root locale if available for locale in config.setting["artist_locales"]: lang = locale.split("_")[0] if lang in root_locales: return root_locales[lang][1] # No matches found in available alias locales translsort = node['sort-name'] transl = translate_from_sortname(node['name'] or "", translsort) else: transl, translsort = node['name'], node['sort-name'] return (transl, translsort)
def test_kanji(self): self.assertEqual(u"Tetsuya Komuro", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya")) self.assertNotEqual(u"Komuro, Tetsuya", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya")) self.assertNotEqual(u"小室哲哉", util.translate_from_sortname(u"小室哲哉", u"Komuro, Tetsuya"))
def test_latin(self): self.assertEqual("thename", util.translate_from_sortname("thename", "sort, name"))
def test_latin(self): self.failUnlessEqual(u"Jean Michel Jarre", util.translate_from_sortname(u"Jean Michel Jarre", u"Jarre, Jean Michel")) self.failIfEqual(u"Jarre, Jean Michel", util.translate_from_sortname(u"Jean Michel Jarre", u"Jarre, Jean Michel"))