Skip to content

Commit

Permalink
fixes to phoneme guesser function
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadlaxa committed Sep 9, 2024
1 parent b1f251a commit d945fb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def read_symbol_types_from_yaml(folder_path):
if 'symbols' in data and isinstance(data['symbols'], list): # Ensure 'symbols' is in data and is a list
for item in data['symbols']:
if isinstance(item, dict) and 'symbol' in item and 'type' in item:
symbol_types[item['symbol']] = item['type']
# Convert symbol to string to ensure consistency
symbol = str(item['symbol'])
symbol_types[symbol] = item['type']
else:
print(f"Unexpected item format in {filename}: {item}")
else:
Expand Down
18 changes: 10 additions & 8 deletions OU Dictionary Editor/OpenUtau_Dictionary_Editor.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -1645,19 +1645,21 @@ class Dictionary(TkinterDnD.Tk):
# Read symbol types from YAML files
symbol_types = read_symbol_types_from_yaml(TEMPLATES)
# Set to keep track of already existing phonemes
existing_phonemes = {symbol['symbol'] for symbol in self.symbols_list}
existing_phonemes = {str(symbol['symbol']) for symbol in self.symbols_list}
new_phonemes = []
# Iterate through the dictionary to find unique phonemes

# Iterate through the dictionary to find unique phonemes
for grapheme, phonemes in self.dictionary.items():
for phoneme in phonemes:
if phoneme not in existing_phonemes:
phoneme_str = str(phoneme) # Convert phoneme to string
if phoneme_str not in existing_phonemes:
# Determine the phoneme type, defaulting to 'unknown' if not found
phoneme_type = symbol_types.get(phoneme, 'unknown')
new_phonemes.append({'symbol': phoneme, 'type': phoneme_type, 'rename': ''})
existing_phonemes.add(phoneme)
phoneme_type = symbol_types.get(phoneme_str, 'unknown')
new_phonemes.append({'symbol': phoneme_str, 'type': phoneme_type, 'rename': ''})
existing_phonemes.add(phoneme_str)

# Sort the new phonemes alphabetically by 'symbol'
new_phonemes_sorted = sorted(new_phonemes, key=lambda x: x['symbol'])
new_phonemes_sorted = sorted(new_phonemes, key=lambda x: str(x['symbol']))

# Add the sorted phonemes to symbols and symbols_list
for phoneme_data in new_phonemes_sorted:
Expand All @@ -1667,7 +1669,7 @@ class Dictionary(TkinterDnD.Tk):
self.symbols_list.append(phoneme_data)

# After adding, sort self.symbols_list alphabetically by 'symbol' to keep consistency
self.symbols_list = sorted(self.symbols_list, key=lambda x: x['symbol'])
self.symbols_list = sorted(self.symbols_list, key=lambda x: str(x['symbol']))
self.open_symbol_editor()

def show_context_menu(self, event):
Expand Down

0 comments on commit d945fb0

Please sign in to comment.