Skip to content

Commit

Permalink
feat/opm plugin (#57)
Browse files Browse the repository at this point in the history
* feat/utterance_plugin

companion to OpenVoiceOS/ovos-core#163

* rm comment

* rm try except
  • Loading branch information
JarbasAl authored May 12, 2024
1 parent 33a40e8 commit d3723c8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lingua_franca/opm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Optional, List

from ovos_plugin_manager.templates.transformers import UtteranceTransformer
from ovos_utils.log import LOG

from lingua_franca.parse import normalize


class UtteranceNormalizer(UtteranceTransformer):

def __init__(self, name="ovos-lf-utterance-normalizer", priority=5):
super().__init__(name, priority)

@staticmethod
def strip_punctuation(utterance: str):
return utterance.rstrip('.').rstrip('?').rstrip('!').rstrip(',').rstrip(';')

def transform(self, utterances: List[str],
context: Optional[dict] = None) -> (list, dict):
context = context or {}
norm = [self.strip_punctuation(u) for u in utterances] + utterances
try:
lang = context.get("lang") or self.config.get("lang", "en-us")
norm += [normalize(u, lang=lang, remove_articles=False) for u in norm] + \
[normalize(u, lang=lang, remove_articles=True) for u in norm]
except:
LOG.exception("lingua_franca utterance normalization failed")

return list(set(norm)), context
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,7 @@ def get_version():
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
entry_points={
'neon.plugin.text': 'ovos-lf-utterance-normalizer=lingua_franca.opm:UtteranceNormalizer'
}
)

0 comments on commit d3723c8

Please sign in to comment.