Skip to content

Commit

Permalink
preload pipeline plugs
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 2, 2024
1 parent baf9373 commit 76f506c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions ovos_core/intent_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, bus, config=None):
# internal, track skills that call self.deactivate to avoid reactivating them again
self._deactivations = defaultdict(list)
self.bus.on('intent.service.skills.deactivate', self._handle_deactivate)
self.get_pipeline() # trigger initial load of pipeline plugins (more may be lazy loaded on demand)

def _handle_transformers(self, message):
"""
Expand Down Expand Up @@ -122,9 +123,9 @@ def get_pipeline(self, skips=None, session=None, skip_stage_matchers=False) -> L
log_deprecation("'skips' kwarg has been deprecated!", "1.0.0")
skips = [OVOSPipelineFactory._MAP.get(p, p) for p in skips]

pipeline: List[str] = [OVOSPipelineFactory._MAP.get(p, p) for p in session.pipeline
pipeline: List[str] = [OVOSPipelineFactory._MAP.get(p, p)
for p in session.pipeline
if p not in skips]

matchers: List[Tuple[str, Callable]] = OVOSPipelineFactory.create(pipeline, use_cache=True, bus=self.bus,
skip_stage_matchers=skip_stage_matchers)
# Sort matchers to ensure the same order as in `pipeline`
Expand Down
24 changes: 12 additions & 12 deletions ovos_core/intent_services/stop_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,6 @@ def match_medium(self, utterances: List[str], lang: str, message: Message) -> Op

return self.match_low(utterances, lang, message)

def _get_closest_lang(self, lang: str) -> Optional[str]:
if self._voc_cache:
lang = standardize_lang_tag(lang)
closest, score = closest_match(lang, list(self._voc_cache.keys()))
# https://langcodes-hickford.readthedocs.io/en/sphinx/index.html#distance-values
# 0 -> These codes represent the same language, possibly after filling in values and normalizing.
# 1- 3 -> These codes indicate a minor regional difference.
# 4 - 10 -> These codes indicate a significant but unproblematic regional difference.
if score < 10:
return closest
return None

def match_low(self, utterances: List[str], lang: str, message: Message) -> Optional[PipelineMatch]:
""" before fallback_low , fuzzy match stop intent
Expand Down Expand Up @@ -250,6 +238,18 @@ def match_low(self, utterances: List[str], lang: str, message: Message) -> Optio
skill_id=None,
utterance=utterance)

def _get_closest_lang(self, lang: str) -> Optional[str]:
if self._voc_cache:
lang = standardize_lang_tag(lang)
closest, score = closest_match(lang, list(self._voc_cache.keys()))
# https://langcodes-hickford.readthedocs.io/en/sphinx/index.html#distance-values
# 0 -> These codes represent the same language, possibly after filling in values and normalizing.
# 1- 3 -> These codes indicate a minor regional difference.
# 4 - 10 -> These codes indicate a significant but unproblematic regional difference.
if score < 10:
return closest
return None

def voc_match(self, utt: str, voc_filename: str, lang: str,
exact: bool = False):
"""
Expand Down

0 comments on commit 76f506c

Please sign in to comment.