Skip to content

feat: fallback parser #15

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

Merged
merged 2 commits into from
Feb 27, 2025
Merged

feat: fallback parser #15

merged 2 commits into from
Feb 27, 2025

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Feb 27, 2025

indirect support for unimplemented languages via unicode-rbnf

Summary by CodeRabbit

  • New Features

    • Enhanced number pronunciation by incorporating a fallback mechanism to better handle languages with partial support.
  • Documentation

    • Updated language support indicators to reflect current functionality, displaying an "imperfect placeholder" status and a note outlining fallback behavior.
  • Chores

    • Added an external library to support improved number and ordinal formatting.

indirect support for unimplemented languages via unicode-rbnf
Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Warning

Rate limit exceeded

@JarbasAl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f9bc3f7 and 527d764.

📒 Files selected for processing (1)
  • ovos_number_parser/__init__.py (3 hunks)

Walkthrough

The pull request updates language support status in the README, modifies number pronunciation functions to include a fallback mechanism, and adds a new dependency. The README now marks several languages with an “imperfect placeholder” for ordinal pronunciation and notes the fallback use of the unicode-rbnf library. In the code, a try/except block is added to invoke RbnfEngine for unsupported languages instead of immediately raising a NotImplementedError. The dependency for unicode-rbnf is appended to the requirements file.

Changes

File(s) Change Summary
README.md Updated language support table: changed the "Pronounce Ordinal" status from ❌ to 🚧 for multiple languages; added a note on fallback to the unicode-rbnf library.
ovos_number_parser/__init__.py Added a try/except fallback in pronounce_number and pronounce_ordinal functions to use RbnfEngine (with FormatPurpose) for unsupported languages; new imports added.
requirements.txt Appended new dependency: unicode-rbnf.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Parser as NumberParser
    participant Engine as RbnfEngine

    User->>Parser: Call pronounce_number / pronounce_ordinal
    Parser->>Engine: Attempt formatting with RbnfEngine (try block)
    alt Engine supports language
        Engine-->>Parser: Return formatted number
        Parser-->>User: Return result
    else Engine does not support language
        Engine-->>Parser: Raises error
        Parser-->>User: Raise NotImplementedError
    end
Loading

Possibly related PRs

  • feat:galician #11: Updates the pronounce_number function for the Galician language, directly relating to the new fallback mechanism implemented in this PR.

Suggested labels

feature

Poem

I'm a little rabbit, hopping through code,
Changing ❌ to 🚧 with a cheerful mode.
Numbers now speak with a fallback spin,
Using RbnfEngine so errors don’t win.
With new dependency in my nibble-filled cheer,
I celebrate these changes, byte by byte, my dear!
🥕🐰 Happy coding under moonlit gear!


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.
  • @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 feature and removed feature labels Feb 27, 2025
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: 2

🧹 Nitpick comments (5)
requirements.txt (1)

1-2: Consider pinning the unicode-rbnf version for production stability.

The addition of unicode-rbnf is good for implementing the fallback parser, but without a version constraint, you might encounter compatibility issues in the future when the library updates.

 quebra_frases>=0.3.7
-unicode-rbnf
+unicode-rbnf>=0.3.0
README.md (1)

19-19: Fix hyphenation in "language-agnostic".

The term "language-agnostic" should be hyphenated when used as a modifier.

-🚧 - imperfect placeholder, usually a language agnostic implementation or external library
+🚧 - imperfect placeholder, usually a language-agnostic implementation or external library
🧰 Tools
🪛 LanguageTool

[uncategorized] ~19-~19: When ‘language-agnostic’ is used as a modifier, it is usually spelled with a hyphen.
Context: ...- 🚧 - imperfect placeholder, usually a language agnostic implementation or external library | ...

(SPECIFIC_HYPHEN)

ovos_number_parser/__init__.py (3)

280-280: Fix typo in error message.

There's a typo in the error message - "languags" should be "language".

-raise NotImplementedError(f"Unsupported languags: '{lang}'")
+raise NotImplementedError(f"Unsupported language: '{lang}'")

301-301: Fix the same typo in another error message.

The same typo "languags" appears in this error message as well.

-raise NotImplementedError(f"Unsupported languags: '{lang}'")
+raise NotImplementedError(f"Unsupported language: '{lang}'")

129-134: Consider adding logging for fallback attempts.

Adding logging when the fallback mechanism is activated would help with debugging and provide visibility into when the fallback is being used.

 # fallback to unicode RBNF
 try:
+    import logging
+    logging.debug(f"Using RBNF fallback for language '{lang}'")
     engine = RbnfEngine.for_language(lang.split("-")[0])
     fmt = FormatPurpose.ORDINAL if ordinals else FormatPurpose.CARDINAL
     return engine.format_number(number, fmt).text
🧰 Tools
🪛 Ruff (0.8.2)

134-134: Do not use bare except

(E722)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f8c6e20 and f9bc3f7.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • ovos_number_parser/__init__.py (3 hunks)
  • requirements.txt (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~19-~19: When ‘language-agnostic’ is used as a modifier, it is usually spelled with a hyphen.
Context: ...- 🚧 - imperfect placeholder, usually a language agnostic implementation or external library | ...

(SPECIFIC_HYPHEN)

🪛 Ruff (0.8.2)
ovos_number_parser/__init__.py

134-134: Do not use bare except

(E722)


135-135: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


169-169: Do not use bare except

(E722)


170-170: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

🔇 Additional comments (2)
README.md (1)

45-46: Well-documented fallback mechanism.

Good addition to the documentation explaining the fallback mechanism using unicode-rbnf. This makes it clear to users what happens when a language isn't directly supported.

ovos_number_parser/__init__.py (1)

3-3: LGTM: Import for fallback mechanism.

The import of RbnfEngine and FormatPurpose from unicode-rbnf appropriately supports the new fallback functionality.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@JarbasAl JarbasAl merged commit e819d79 into dev Feb 27, 2025
1 check passed
@JarbasAl JarbasAl deleted the feat/fallback branch February 27, 2025 11:51
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