Skip to content

Commit

Permalink
0.2.0 (#14)
Browse files Browse the repository at this point in the history
# Changelog

##
[0.1.2a2](https://github.com/NeonGeckoCom/neon-utterance-plugin-translator/tree/0.1.2a2)
(2023-11-09)

[Full
Changelog](0.1.1...0.1.2a2)

**Closed issues:**

- Update translation logic to support a list of internal languages
[\#9](#9)
- Prepare for PyPI Release
[\#2](#2)
- Add Unit Tests
[\#1](#1)

**Merged pull requests:**

- Update GitHub Automation
[\#13](#13)
([NeonDaniel](https://github.com/NeonDaniel))
- Add support for configuration disabling language detection
[\#12](#12)
([NeonDaniel](https://github.com/NeonDaniel))
- Config handling bugfix and logging/formatting changes
[\#10](#10)
([NeonDaniel](https://github.com/NeonDaniel))



\* *This Changelog was automatically generated by
[github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
  • Loading branch information
NeonDaniel authored Dec 16, 2023
2 parents 3429549 + 7e6587b commit f7af0bc
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 238 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/build_tests.yml

This file was deleted.

32 changes: 4 additions & 28 deletions .github/workflows/license_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,10 @@ name: Run License Tests
on:
push:
workflow_dispatch:
pull_request:
branches:
- master

jobs:
license_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install Build Tools
run: |
python -m pip install build wheel
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt install python3-dev swig libssl-dev
- name: Install core repo
run: |
pip install .
- name: Install licheck
run: |
pip install git+https://github.com/NeonJarbas/lichecker
- name: Install test dependencies
run: |
pip install pytest pytest-timeout pytest-cov
- name: Test Licenses
run: |
pytest tests/license_tests.py
uses: neongeckocom/.github/.github/workflows/license_tests.yml@master
28 changes: 28 additions & 0 deletions .github/workflows/propose_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Propose Stable Release
on:
workflow_dispatch:
inputs:
release_type:
type: choice
description: Release Type
options:
- patch
- minor
- major
jobs:
update_version:
uses: neongeckocom/.github/.github/workflows/propose_semver_release.yml@master
with:
branch: dev
release_type: ${{ inputs.release_type }}
update_changelog: True
version_file: "version.py"
pull_changes:
uses: neongeckocom/.github/.github/workflows/pull_master.yml@master
needs: update_version
with:
pr_reviewer: neonreviewers
pr_assignee: ${{ github.actor }}
pr_draft: false
pr_title: ${{ needs.update_version.outputs.version }}
pr_body: ${{ needs.update_version.outputs.changelog }}
35 changes: 5 additions & 30 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
# This workflow will generate a release distribution and upload it to PyPI

name: Publish Build and GitHub Release
on:
push:
branches:
- master

jobs:
tag_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Version
run: |
VERSION=$(python setup.py --version)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- uses: ncipollo/release-action@v1
with:
token: ${{secrets.GITHUB_TOKEN}}
tag: ${{env.VERSION}}
build_and_publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install Build Tools
run: |
python -m pip install build wheel
- name: Build Distribution Packages
run: |
python setup.py bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{secrets.PYPI_TOKEN}}
build_and_publish_pypi_and_release:
uses: neongeckocom/.github/.github/workflows/publish_stable_release.yml@master
secrets: inherit
37 changes: 9 additions & 28 deletions .github/workflows/publish_test_build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This workflow will generate a distribution and upload it to PyPI

name: Publish Alpha Build
on:
push:
Expand All @@ -7,31 +9,10 @@ on:
- 'version.py'

jobs:
build_and_publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install Build Tools
run: |
python -m pip install build wheel
- name: Increment Version
run: |
VER=$(python setup.py --version)
python version_bump.py
- name: Push Version Change
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Increment Version
- name: Build Distribution Packages
run: |
python setup.py bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{secrets.PYPI_TOKEN}}
publish_alpha_release:
uses: neongeckocom/.github/.github/workflows/publish_alpha_release.yml@master
secrets: inherit
with:
version_file: "version.py"
setup_py: "setup.py"
publish_prerelease: true
19 changes: 0 additions & 19 deletions .github/workflows/pull_master.yml

This file was deleted.

16 changes: 2 additions & 14 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@ on:
workflow_dispatch:

jobs:
build_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install Build Tools
run: |
python -m pip install build wheel
- name: Build Distribution Packages
run: |
python setup.py bdist_wheel
py_build_tests:
uses: neongeckocom/.github/.github/workflows/python_build_tests.yml@master
unit_tests:
strategy:
matrix:
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

## [0.1.2a2](https://github.com/NeonGeckoCom/neon-utterance-plugin-translator/tree/0.1.2a2) (2023-11-09)

[Full Changelog](https://github.com/NeonGeckoCom/neon-utterance-plugin-translator/compare/0.1.1...0.1.2a2)

**Closed issues:**

- Update translation logic to support a list of internal languages [\#9](https://github.com/NeonGeckoCom/neon-utterance-plugin-translator/issues/9)
- Prepare for PyPI Release [\#2](https://github.com/NeonGeckoCom/neon-utterance-plugin-translator/issues/2)
- Add Unit Tests [\#1](https://github.com/NeonGeckoCom/neon-utterance-plugin-translator/issues/1)

**Merged pull requests:**

- Update GitHub Automation [\#13](https://github.com/NeonGeckoCom/neon-utterance-plugin-translator/pull/13) ([NeonDaniel](https://github.com/NeonDaniel))
- Add support for configuration disabling language detection [\#12](https://github.com/NeonGeckoCom/neon-utterance-plugin-translator/pull/12) ([NeonDaniel](https://github.com/NeonDaniel))
- Config handling bugfix and logging/formatting changes [\#10](https://github.com/NeonGeckoCom/neon-utterance-plugin-translator/pull/10) ([NeonDaniel](https://github.com/NeonDaniel))



\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
63 changes: 48 additions & 15 deletions neon_utterance_translator_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,76 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from ovos_plugin_manager.language import OVOSLangDetectionFactory, OVOSLangTranslationFactory
from typing import Optional, List
from ovos_config import Configuration
from ovos_plugin_manager.language import (OVOSLangDetectionFactory,
OVOSLangTranslationFactory)
from ovos_utils.log import LOG

from neon_transformers import UtteranceTransformer
from neon_transformers.tasks import UtteranceTask


class UtteranceTranslator(UtteranceTransformer):
task = UtteranceTask.TRANSLATION

def __init__(self, name="utterance_translator", config=None, priority=5):
def __init__(self, name: str = "neon_utterance_translator_plugin",
config: Optional[dict] = None, priority: int = 5):
"""
Create an Utterance Transformer to handle translating inputs.
@param name: name of the transformer; used to determine default config
@param config: optional dict config for this plugin
@param priority: priority value for this plugin (1-100 with lower values
taking priority over higher values)
"""
super().__init__(name, priority, config)
self.language_config = self.config.get("language") or {}
self.supported_langs = self.language_config.get('supported_langs') or ['en']
self.internal_lang = self.language_config.get("internal") or 'en-us' or self.supported_langs[0]
self.lang_detector = OVOSLangDetectionFactory.create()
self.translator = OVOSLangTranslationFactory.create()
self.language_config = Configuration().get("language")
self.supported_langs = self.language_config.get('supported_langs') or \
['en']
self.internal_lang = self.language_config.get("internal") or \
self.supported_langs[0]
LOG.debug("Initializing translator")
self.translator = OVOSLangTranslationFactory.create(
self.language_config)
if self.config.get("enable_detector", True):
self.lang_detector = OVOSLangDetectionFactory.create(
self.language_config)
else:
self.lang_detector = None
LOG.info("Detection module disabled in configuration")

def transform(self, utterances, context=None):
def transform(self, utterances: List[str], context: Optional[dict] = None) \
-> (List[str], dict):
"""
Transform and get context for input utterances.
@param utterances: List of string utterances to evaluate
@param context: Optional dict context associated with utterances
@returns: list of transformed utterances, dict calculated context
"""
metadata = []
was_translated = False
for idx, ut in enumerate(utterances):
try:
original = ut
detected_lang = self.lang_detector.detect(original)
if context != None and context.get('lang') != '':
if self.lang_detector:
detected_lang = self.lang_detector.detect(original)
else:
detected_lang = context.get('lang',
self.internal_lang).split('-',
1)[0]
if context and context.get('lang'):
lang = context.get('lang')
if detected_lang != lang.split('-', 1)[0]:
LOG.warning(f"Specified lang: {lang} but detected {detected_lang}")
LOG.warning(f"Specified lang: {lang} but detected "
f"{detected_lang}")
else:
LOG.debug(f"Detected language: {detected_lang}")
else:
LOG.warning(f"No lang provided but detected {detected_lang}")
LOG.warning(f"No lang provided. Detected {detected_lang}")
lang = detected_lang
if lang.split('-', 1)[0] not in self.supported_langs:
LOG.warning(f"There is no: {lang} in supported languages. "
f"Utterance will be translated to {self.internal_lang}")
LOG.warning(f"There is no: {lang} in supported languages "
f"{self.supported_langs}. Utterance will be "
f"translated to {self.internal_lang}")
utterances[idx] = self.translator.translate(
original,
self.internal_lang,
Expand Down
6 changes: 3 additions & 3 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
neon_transformers~=0.1
ovos_plugin_manager~=0.0,>=0.0.17
ovos_utils~=0.0,>=0.0.22
neon_utils>=0.17.3,<2.0.0
ovos_plugin_manager~=0.0.17
ovos_utils~=0.0.22
neon_utils~=1.0
3 changes: 2 additions & 1 deletion requirements/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest
neon-lang-plugin-libretranslate
neon-lang-plugin-libretranslate
ovos-bus-client
Loading

0 comments on commit f7af0bc

Please sign in to comment.