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

fix:voc_match #327

Merged
merged 1 commit into from
Jan 30, 2025
Merged

fix:voc_match #327

merged 1 commit into from
Jan 30, 2025

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Jan 30, 2025

handle variations in accents/punctuation in the .voc files

this is common in written chat and in some postprocessing applied to STTs

example, ocp pipeline was not matching "noticias" vs "notícias" (News in portuguese)

Summary by CodeRabbit

  • New Features

    • Added a utility function to remove accents and punctuation from strings
    • Enhanced vocabulary matching with an option to ignore accents and punctuation
  • Improvements

    • Updated voc_match method to provide more flexible string comparison

handle variations in accents/punctuation in the .voc files

this is common in written chat and in some postprocessing applied to STTs

example, ocp pipeline was not matching "noticias" vs "notícias" (News in portuguese)
Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Walkthrough

The pull request introduces modifications to the ovos_workshop/skills/ovos.py file, focusing on enhancing string matching and utility functions. A new method remove_accents_and_punct is added to normalize strings by removing accents and punctuation. The voc_match method is updated with an additional ensure_ascii parameter, providing more flexible vocabulary matching capabilities. The import statements are also refined, adding new imports from various OVOS-related modules.

Changes

File Change Summary
ovos_workshop/skills/ovos.py - Added imports for string, unicodedata, and various OVOS config/number parsing functions
- Introduced new utility method remove_accents_and_punct() for string normalization
- Updated voc_match() method signature with ensure_ascii parameter

Suggested Reviewers

  • NeonDaniel

Suggested Labels

fix

Possibly related PRs

Poem

🐰 A Rabbit's Ode to String Refinement

In code's wild garden, accents take flight,
Punctuation dances out of sight
With remove_accents, we clean the way
Matching vocabularies in a brand new play
Hop, hop, hooray for cleaner text! 🎉

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@github-actions github-actions bot added fix and removed fix labels Jan 30, 2025
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 49.02%. Comparing base (43bfe5b) to head (6c6c1af).
Report is 24 commits behind head on dev.

Files with missing lines Patch % Lines
ovos_workshop/skills/ovos.py 60.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #327      +/-   ##
==========================================
- Coverage   49.27%   49.02%   -0.26%     
==========================================
  Files          37       37              
  Lines        4426     4439      +13     
==========================================
- Hits         2181     2176       -5     
- Misses       2245     2263      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JarbasAl JarbasAl merged commit 43b1e20 into dev Jan 30, 2025
6 of 8 checks passed
Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
ovos_workshop/skills/ovos.py (1)

2774-2791: Consider enhancing the utility function before moving to ovos-utils.

The implementation looks good but could be improved before moving to ovos-utils:

  1. Consider adding input validation for None/non-string inputs
  2. Consider adding optional parameters to:
    • Specify which punctuation marks to preserve (currently hardcoded to { and })
    • Control whether to preserve whitespace
  3. Consider adding unit tests before the move

Here's a suggested enhancement:

 def remove_accents_and_punct(input_str: str) -> str:
+    if not isinstance(input_str, str):
+        raise TypeError("Input must be a string")
+    if not input_str:
+        return input_str
+        
     rm_chars = [c for c in string.punctuation if c not in ("{", "}")]
     # Normalize to NFD (Normalization Form Decomposed), which separates characters and diacritical marks
     nfkd_form = unicodedata.normalize('NFD', input_str)
     # Remove characters that are not ASCII letters or punctuation we want to keep
     return ''.join([char for char in nfkd_form
                     if unicodedata.category(char) != 'Mn' and char not in rm_chars])
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 097ae6a and 6c6c1af.

📒 Files selected for processing (1)
  • ovos_workshop/skills/ovos.py (7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: unit_tests (3.9)
🔇 Additional comments (3)
ovos_workshop/skills/ovos.py (3)

7-7: LGTM! Required imports added.

The new imports for string and unicodedata modules are appropriately placed with other standard library imports and are necessary for the new accent/punctuation normalization functionality.

Also applies to: 11-11


Line range hint 2215-2252: LGTM! Enhanced vocabulary matching with accent/punctuation handling.

The changes improve the vocabulary matching by:

  1. Adding the ensure_ascii parameter with a sensible default (True) for backward compatibility
  2. Applying accent/punctuation normalization to both the input and vocabulary terms when enabled

This enhancement will help match variations like "noticias" and "notícias" as intended.


Line range hint 2215-2252: Verify the accent normalization with test cases.

The implementation looks correct for handling accent variations in .voc files. To ensure robustness, consider testing with these cases:

  1. Words with multiple accents
  2. Words with punctuation and accents
  3. Template variables with accents inside curly braces
  4. Empty strings and edge cases

Also applies to: 2774-2791

✅ Verification successful

Implementation correctly handles accents and template variables

The accent normalization implementation is robust and correct:

  • Uses Unicode NFD normalization for reliable accent handling
  • Properly preserves template variables with { and }
  • Correctly processes both utterances and vocabulary entries
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Create a test .voc file with accented words
echo "notícias
noticias
{news}" > test.voc

# Test the voc_match function with various inputs
python3 -c '
from ovos_workshop.skills.ovos import remove_accents_and_punct

test_cases = [
    "notícias",
    "noticias",
    "notícias!",
    "!noticias!",
    "{nótícias}",
    "",
    "múltiple accénts"
]

for test in test_cases:
    normalized = remove_accents_and_punct(test)
    print(f"Original: {test}")
    print(f"Normalized: {normalized}\n")
'

Length of output: 792


Script:

#!/bin/bash
# Find the implementation of remove_accents_and_punct
rg -A 5 "def remove_accents_and_punct" 

# Look for test cases
fd "test.*\.py" --exec rg -l "remove_accents_and_punct"

# Check template variable handling
rg "{.*?}" "*.voc" || true  # Don't fail if no .voc files found

Length of output: 603


Script:

#!/bin/bash
# Get the complete implementation of remove_accents_and_punct
ast-grep --pattern 'def remove_accents_and_punct($params) {
  $$$
}'

# Also check for any usage examples
rg -B 2 -A 5 "remove_accents_and_punct\(" 

Length of output: 1207


Script:

#!/bin/bash
# Try to get the complete function implementation with a different pattern
rg -A 15 "^def remove_accents_and_punct"

# Also check if there are any related utility functions
rg "import.*unicodedata|from.*unicodedata"

Length of output: 1362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant