Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move utterance normalizer to own repo #48

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Aug 5, 2024

companion to OpenVoiceOS/ovos-utterance-normalizer#1

Summary by CodeRabbit

  • New Features

    • Integration of the ovos_utterance_normalizer package for tokenization and normalization functionalities.
    • Updated dependency to include ovos-utterance-normalizer.
  • Bug Fixes

    • Resolved potential issues by replacing deprecated tokenization and normalization classes with updated implementations.
  • Refactor

    • Removed outdated normalization and tokenization classes, enhancing the codebase's maintainability.
  • Chores

    • Adjusted module paths in test files to reflect the new structure.

@JarbasAl JarbasAl added the refactor code improvements with no functional changes label Aug 5, 2024
Copy link

coderabbitai bot commented Aug 5, 2024

Walkthrough

The recent updates to the codebase involve a significant shift in functionality, primarily through the migration of various classes and methods from ovos_classifiers to ovos_utterance_normalizer. This restructuring enhances maintainability and leverages improved implementations for text normalization, tokenization, and numeric parsing. Overall, these changes streamline the code by reducing redundancy and consolidating functionality into a dedicated module.

Changes

Files Change Summary
ovos_classifiers/heuristics/machine_comprehension.py
ovos_classifiers/heuristics/postag.py
ovos_classifiers/heuristics/summarization.py
ovos_classifiers/skovos/features/__init__.py
ovos_classifiers/tasks/tagger.py
Updated import of word_tokenize from ovos_classifiers.heuristics.tokenize to ovos_utterance_normalizer.tokenization.
ovos_classifiers/heuristics/normalize.py Removed Normalizer class and its subclasses; added import from ovos_utterance_normalizer.normalizer.
ovos_classifiers/heuristics/numeric.py Entire file removed; replaced with import statement from ovos_utterance_normalizer.numeric.
ovos_classifiers/heuristics/time.py Updated imports for number and time parsing from ovos_classifiers.heuristics to ovos_utterance_normalizer.
ovos_classifiers/heuristics/tokenize.py Major refactor: removed multiple classes and functions; imports everything from ovos_utterance_normalizer.tokenization.
ovos_classifiers/opm/heuristics.py Updated imports for Normalizer and language normalizers from ovos_classifiers.heuristics.normalize to ovos_utterance_normalizer.normalizer.
requirements.txt Added dependency on ovos-utterance-normalizer.
setup.py Removed entry for UtteranceNormalizerPlugin from UTTERANCE_ENTRY_POINT.
test/unittests/test_numeric.py Updated module paths for EnglishNumberParser and word_tokenize to the new locations.

Sequence Diagram(s)

sequenceDiagram
    participant A as Application
    participant B as Normalization Module
    participant C as Tokenization Module
    participant D as Numeric Parsing Module

    A->>B: Request text normalization
    B->>A: Return normalized text

    A->>C: Request tokenization
    C->>A: Return tokenized output

    A->>D: Request numeric parsing
    D->>A: Return parsed numbers
Loading

🐇 In fields so wide and bright,
New layers bloom with pure delight.
Tokenize and parse with glee,
From ovos roots, we set them free! 🌼
A hop, a skip, a code so neat,
With changes made, our work's complete!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 07166e5 and 1a2ea83.

Files selected for processing (13)
  • ovos_classifiers/heuristics/machine_comprehension.py (1 hunks)
  • ovos_classifiers/heuristics/normalize.py (1 hunks)
  • ovos_classifiers/heuristics/numeric.py (1 hunks)
  • ovos_classifiers/heuristics/postag.py (1 hunks)
  • ovos_classifiers/heuristics/summarization.py (1 hunks)
  • ovos_classifiers/heuristics/time.py (1 hunks)
  • ovos_classifiers/heuristics/tokenize.py (1 hunks)
  • ovos_classifiers/opm/heuristics.py (1 hunks)
  • ovos_classifiers/skovos/features/init.py (1 hunks)
  • ovos_classifiers/tasks/tagger.py (1 hunks)
  • requirements.txt (1 hunks)
  • setup.py (1 hunks)
  • test/unittests/test_numeric.py (1 hunks)
Files skipped from review due to trivial changes (4)
  • ovos_classifiers/heuristics/machine_comprehension.py
  • ovos_classifiers/opm/heuristics.py
  • ovos_classifiers/tasks/tagger.py
  • test/unittests/test_numeric.py
Additional context used
Ruff
ovos_classifiers/heuristics/numeric.py

1-1: from ovos_utterance_normalizer.numeric import * used; unable to detect undefined names

(F403)

ovos_classifiers/heuristics/normalize.py

1-1: from ovos_utterance_normalizer.normalizer import * used; unable to detect undefined names

(F403)

ovos_classifiers/heuristics/tokenize.py

1-1: from ovos_utterance_normalizer.tokenization import * used; unable to detect undefined names

(F403)

ovos_classifiers/heuristics/time.py

6-6: ovos_utterance_normalizer.tokenization.ReplaceableNumber imported but unused

Remove unused import

(F401)

Additional comments not posted (6)
requirements.txt (1)

11-12: Dependency addition approved.

The addition of ovos-utterance-normalizer aligns with the PR's objective of moving the utterance normalizer to its own repository.

ovos_classifiers/heuristics/summarization.py (1)

2-2: Import source change approved.

The change in the import source for word_tokenize aligns with the PR's objective of moving the utterance normalizer to its own repository.

setup.py (1)

Line range hint 47-47:
Entry point removal approved.

The removal of the entry point for ovos-utterance-normalizer aligns with the PR's objective of moving the utterance normalizer to its own repository.

ovos_classifiers/heuristics/postag.py (1)

6-6: Update import statement to reflect new module structure.

The import statement has been updated to import word_tokenize from ovos_utterance_normalizer.tokenization instead of ovos_classifiers.heuristics.tokenize. Ensure that the new module provides the same functionality and that all dependencies are correctly updated.

ovos_classifiers/heuristics/time.py (1)

5-6: Update import statements to reflect new module structure.

The import statements have been updated to import EnglishNumberParser, GermanNumberParser, ReplaceableNumber, ReplaceableTimedelta, ReplaceableTime, ReplaceableDate, Token, and word_tokenize from ovos_utterance_normalizer instead of ovos_classifiers.heuristics. Ensure that the new module provides the same functionality and that all dependencies are correctly updated.

Tools
Ruff

6-6: ovos_utterance_normalizer.tokenization.ReplaceableNumber imported but unused

Remove unused import

(F401)

ovos_classifiers/skovos/features/__init__.py (1)

19-19: Update import statement to reflect new module structure.

The import statement has been updated to import word_tokenize from ovos_utterance_normalizer.tokenization instead of ovos_classifiers.heuristics.tokenize. Ensure that the new module provides the same functionality and that all dependencies are correctly updated.

from ovos_classifiers.heuristics.numeric import EnglishNumberParser, GermanNumberParser
from ovos_classifiers.heuristics.tokenize import ReplaceableNumber, ReplaceableTimedelta, \
from ovos_utterance_normalizer.numeric import EnglishNumberParser, GermanNumberParser
from ovos_utterance_normalizer.tokenization import ReplaceableNumber, ReplaceableTimedelta, \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused import.

The import ReplaceableNumber is not used in the file and should be removed to clean up the code.

- from ovos_utterance_normalizer.tokenization import ReplaceableNumber, ReplaceableTimedelta, \
+ from ovos_utterance_normalizer.tokenization import ReplaceableTimedelta, \
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from ovos_utterance_normalizer.tokenization import ReplaceableNumber, ReplaceableTimedelta, \
from ovos_utterance_normalizer.tokenization import ReplaceableTimedelta, \
Tools
Ruff

6-6: ovos_utterance_normalizer.tokenization.ReplaceableNumber imported but unused

Remove unused import

(F401)

string_num_scale_az = {v: k for k, v in string_num_scale_az.items()}

return multiplies, string_num_ordinal_az, string_num_scale_az
from ovos_utterance_normalizer.numeric import *
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid wildcard imports.

Using import * can lead to namespace pollution and makes it harder to track which names are in the namespace. It is better to import specific entities.

- from ovos_utterance_normalizer.numeric import *
+ from ovos_utterance_normalizer.numeric import NumericParser, parse_number, parse_ordinal, parse_fraction
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from ovos_utterance_normalizer.numeric import *
from ovos_utterance_normalizer.numeric import NumericParser, parse_number, parse_ordinal, parse_fraction
Tools
Ruff

1-1: from ovos_utterance_normalizer.numeric import * used; unable to detect undefined names

(F403)

# return them pretty regularly
utterance = re.sub(r'\b(\w*)-(\w*)\b', r'\1 \2', utterance)
return super().remove_symbols(utterance)
from ovos_utterance_normalizer.normalizer import *
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid wildcard imports.

Using import * can lead to namespace pollution and makes it harder to track which names are in the namespace. It is better to import specific entities.

- from ovos_utterance_normalizer.normalizer import *
+ from ovos_utterance_normalizer.normalizer import Normalizer, CatalanNormalizer, CzechNormalizer, PortugueseNormalizer, RussianNormalizer, UkrainianNormalizer, EnglishNormalizer, AzerbaijaniNormalizer, GermanNormalizer
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from ovos_utterance_normalizer.normalizer import *
from ovos_utterance_normalizer.normalizer import Normalizer, CatalanNormalizer, CzechNormalizer, PortugueseNormalizer, RussianNormalizer, UkrainianNormalizer, EnglishNormalizer, AzerbaijaniNormalizer, GermanNormalizer
Tools
Ruff

1-1: from ovos_utterance_normalizer.normalizer import * used; unable to detect undefined names

(F403)

"""
from nltk.tokenize.sonority_sequencing import SyllableTokenizer
return SyllableTokenizer().tokenize(utterance)
from ovos_utterance_normalizer.tokenization import *
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid wildcard imports.

Using import * can lead to namespace pollution and makes it harder to track which names are in the namespace. It is better to import specific entities.

- from ovos_utterance_normalizer.tokenization import *
+ from ovos_utterance_normalizer.tokenization import Token, ReplaceableEntity, ReplaceableNumber, ReplaceableDate, ReplaceableTime, ReplaceableTimedelta, partition_list, sentence_tokenize, word_tokenize, word_tokenize_pt, word_tokenize_ca, subword_tokenize, syllable_tokenize
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from ovos_utterance_normalizer.tokenization import *
from ovos_utterance_normalizer.tokenization import Token, ReplaceableEntity, ReplaceableNumber, ReplaceableDate, ReplaceableTime, ReplaceableTimedelta, partition_list, sentence_tokenize, word_tokenize, word_tokenize_pt, word_tokenize_ca, subword_tokenize, syllable_tokenize
Tools
Ruff

1-1: from ovos_utterance_normalizer.tokenization import * used; unable to detect undefined names

(F403)

@JarbasAl JarbasAl merged commit dfd9dc2 into dev Aug 5, 2024
2 of 6 checks passed
@JarbasAl JarbasAl deleted the refactor/move_to_ovos_utterance_normalizer_repo branch August 5, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor code improvements with no functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant