Skip to content

Commit

Permalink
normalize lang
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 12, 2024
1 parent 52bbef8 commit 0233f69
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 16 deletions.
1 change: 0 additions & 1 deletion ovos_plugin_manager/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ovos_plugin_manager.templates.segmentation import Segmenter



def find_segmentation_plugins() -> dict:
"""
Find all installed plugins
Expand Down
2 changes: 1 addition & 1 deletion ovos_plugin_manager/templates/coreference.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def lang(self):
msg = dig_for_message()
if msg:
lang = msg.data.get("lang")
return standardize_lang_tag(lang or "en-us")
return standardize_lang_tag(lang or "en-US")

def contains_corefs(self, text, lang=None):
lang = standardize_lang_tag(lang or self.lang, macro=True)
Expand Down
2 changes: 1 addition & 1 deletion ovos_plugin_manager/templates/hotwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HotWordEngine:
lang (str): language code (BCP-47)
"""

def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"):
def __init__(self, key_phrase="hey mycroft", config=None, lang="en-US"):
self.key_phrase = str(key_phrase).lower()
mycroft_config = Configuration()
if config is None:
Expand Down
6 changes: 3 additions & 3 deletions ovos_plugin_manager/templates/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, config: Optional[Dict[str, Union[str, int]]] = None):
Can contain "lang" for default language, "hint_lang" for a hint language, and "boost" for language boost score.
"""
self.config = config or {}
self.default_language = self.config.get("lang", "en-us")
self.default_language = self.config.get("lang", "en-US")
self.hint_language = self.config.get("hint_lang") or self.config.get('user') or self.default_language
self.boost = self.config.get("boost")

Expand Down Expand Up @@ -46,7 +46,7 @@ def detect(self, text: str) -> str:
text (str): The text to detect the language of.
Returns:
str: The detected language code (e.g., 'en-us').
str: The detected language code (e.g., 'en-US').
"""

@abc.abstractmethod
Expand Down Expand Up @@ -85,7 +85,7 @@ def __init__(self, config: Optional[Dict[str, str]] = None):
"""
self.config = config or {}
# translate from, unless specified/detected otherwise
self.default_language = self.config.get("lang") or "en-us"
self.default_language = self.config.get("lang") or "en-US"
# translate to
self.internal_language = (Configuration().get('language') or
dict()).get("internal") or \
Expand Down
2 changes: 1 addition & 1 deletion ovos_plugin_manager/templates/postag.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def lang(self):
msg = dig_for_message()
if msg:
lang = msg.data.get("lang")
return standardize_lang_tag(lang or "en-us")
return standardize_lang_tag(lang or "en-US")

def postag(self, spans, lang=None):
lang = lang or self.lang
Expand Down
2 changes: 1 addition & 1 deletion ovos_plugin_manager/templates/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def lang(self):
msg = dig_for_message()
if msg:
lang = msg.data.get("lang")
return standardize_lang_tag(lang or "en-us")
return standardize_lang_tag(lang or "en-US")

@staticmethod
def __extract(text, markers):
Expand Down
2 changes: 1 addition & 1 deletion ovos_plugin_manager/templates/stt.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def recognizer(self, val):
def lang(self):
return standardize_lang_tag(self._lang or \
self.config.get("lang") or \
Configuration().get("lang", "en-us"))
Configuration().get("lang", "en-US"))

@lang.setter
def lang(self, val):
Expand Down
2 changes: 1 addition & 1 deletion ovos_plugin_manager/templates/tokenization.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def lang(self):
msg = dig_for_message()
if msg:
lang = msg.data.get("lang")
return standardize_lang_tag(lang or "en-us")
return standardize_lang_tag(lang or "en-US")

def span_tokenize(self, text, lang=None):
return span_indexed_word_tokenize(text)
Expand Down
4 changes: 2 additions & 2 deletions ovos_plugin_manager/templates/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def _get_ctxt(self, kwargs=None) -> TTSContext:

LOG.debug(f"TTS kwargs: {kwargs}")
return TTSContext(plugin_id=self.plugin_id,
lang=kwargs.get("lang") or Configuration().get("lang", "en-us"),
lang=kwargs.get("lang") or Configuration().get("lang", "en-US"),
voice=kwargs.get("voice", "default"),
synth_kwargs=kwargs)

Expand Down Expand Up @@ -934,7 +934,7 @@ def lang(self):
if message:
sess = SessionManager.get(message)
return sess.lang
return self.config.get("lang") or 'en-us'
return self.config.get("lang") or 'en-US'

@lang.setter
@deprecated("language is defined per request in get_tts, self.lang is not used",
Expand Down
2 changes: 2 additions & 0 deletions ovos_plugin_manager/utils/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def get_config_options(cls, lang: str, plugin_type: PluginTypes,
@param include_dialects: If True, include any ISO 639-1 matched codes
@return: list of valid GUI-compatible config dicts
"""
lang = standardize_lang_tag(lang)
# NOTE: mycroft-gui will crash if theres more than 20 options according to @aiix
# TODO - validate that this is true and 20 is a real limit
blacklist = blacklist or []
Expand Down Expand Up @@ -188,6 +189,7 @@ def get_plugin_options(cls, lang: str, plugin_type: PluginTypes) -> list:
@param plugin_type: Type of plugins to return
@return: list of plugin specs with capabilities and config options
"""
lang = standardize_lang_tag(lang)
plugs = {}
for entry in cls.get_config_options(lang, plugin_type):
engine = entry["engine"]
Expand Down
11 changes: 7 additions & 4 deletions ovos_plugin_manager/wakewords.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import json
import os

from hashlib import md5
from typing import Optional

from ovos_utils.lang import standardize_lang_tag
from ovos_utils.log import LOG
from ovos_utils.xdg_utils import xdg_data_home

from ovos_plugin_manager.templates.hotwords import HotWordEngine
from ovos_plugin_manager.utils import normalize_lang, \
PluginTypes, PluginConfigTypes
from ovos_plugin_manager.utils import PluginTypes, PluginConfigTypes


def find_wake_word_plugins() -> dict:
Expand Down Expand Up @@ -135,6 +136,7 @@ def load_module(module: str, hotword: str, hotword_config: dict,
@param loop: Unused
@return: Initialized HotWordEngine
"""
lang = standardize_lang_tag(lang)
# config here is config['hotwords'][module]
LOG.info(f'Loading "{hotword}" wake word via {module} with '
f'config: {hotword_config}')
Expand All @@ -149,7 +151,7 @@ def load_module(module: str, hotword: str, hotword_config: dict,
@classmethod
def create_hotword(cls, hotword: str = "hey mycroft",
config: Optional[dict] = None,
lang: str = "en-us", loop=None) -> HotWordEngine:
lang: str = "en-US", loop=None) -> HotWordEngine:
"""
Get an initialized HotWordEngine by configured name
@param hotword: string hotword to load
Expand All @@ -158,6 +160,7 @@ def create_hotword(cls, hotword: str = "hey mycroft",
@param loop: Unused
@return: Initialized HotWordEngine
"""
lang = standardize_lang_tag(lang)
ww_configs = get_hotwords_config(config)
if hotword not in ww_configs:
LOG.warning(f"replace ` ` in {hotword} with `_`")
Expand Down

0 comments on commit 0233f69

Please sign in to comment.