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

Feat/pronounce digits #41

Closed
wants to merge 3 commits into from
Closed

Feat/pronounce digits #41

wants to merge 3 commits into from

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Nov 27, 2022

port MycroftAI#150

Summary by CodeRabbit

  • New Features

    • Introduced a new function to pronounce numbers' digits in various formats (integer, float, and string).
  • Tests

    • Added test cases to verify the correct pronunciation of digits in different scenarios.

@JarbasAl JarbasAl added the enhancement New feature or request label Nov 27, 2022
@codecov
Copy link

codecov bot commented Nov 27, 2022

Codecov Report

❗ No coverage uploaded for pull request base (dev@08ed3c6). Click here to learn what that means.
The diff coverage is n/a.

@@          Coverage Diff          @@
##             dev     #41   +/-   ##
=====================================
  Coverage       ?   0.00%           
=====================================
  Files          ?      65           
  Lines          ?   16419           
  Branches       ?       0           
=====================================
  Hits           ?       0           
  Misses         ?   16419           
  Partials       ?       0           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

lingua_franca/format.py Show resolved Hide resolved
lingua_franca/lang/format_en.py Show resolved Hide resolved
return op_val + " point " + decimal_part
return op_val

if "." in str(number):
Copy link
Member

Choose a reason for hiding this comment

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

Any reason we treat non-str numbers differently here instead of just starting with number = str(number)?

Comment on lines +122 to +123
self.assertEqual(pronounce_digits(10.999999), "ten point nine nine")
self.assertEqual(pronounce_digits(10.999999, places=0), "ten")
Copy link
Member

Choose a reason for hiding this comment

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

These aren't correctly rounded; I think this should either treat places as "significant figures", or specifically note in the docstring that places are not sig figs and decimals are truncated as opposed to rounded

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe an extra flag for rounding or not defaulting to True?

Copy link
Member

Choose a reason for hiding this comment

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

I suspect its parsing as a string instead of using round()

Copy link
Member Author

Choose a reason for hiding this comment

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

The method is a formating method should not modify input, imho not rounding is the expected behaviour and rounding should be done before calling method if needed or via optional flag. This is reading digits not pronouncing the number, the rounding feels application specific even if I can't come up with a good use case where we don't want it....

@JarbasAl
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented Jul 17, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Jul 17, 2024

Warning

Rate limit exceeded

@JarbasAl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 3 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

Files that changed from the base of the PR and between d1f05a1 and 764e7bd.

Walkthrough

A new function pronounce_digits has been introduced to convert numbers into their spoken form, accommodating various formats such as floats, integers, and strings. This function provides options to pronounce all digits or just the significant figures. Corresponding changes were made in the English language formatting module, and unit tests were added to ensure the correctness of the new functionality.

Changes

Files Change Summaries
.../format.py Added pronounce_digits function and made minor formatting changes in pronounce_number.
.../format_en.py Added pronounce_digits_en function to handle English digit pronunciation.
.../test_format_en.py Added unit tests for pronounce_digits function, including tests for floats, integers, and strings.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant format.py
    participant format_en.py

    Caller->>+format.py: pronounce_digits(number, places, all_digits, lang)
    format.py->>+format_en.py: pronounce_digits_en(number, places, all_digits)
    format_en.py-->>-format.py: Pronounced digits string
    format.py-->>-Caller: Pronounced digits string
Loading

Poem

In code we sing the digits loud,
From ones and twos to numbers proud,
Floats and ints, no fear from strings,
Each numeral with voice now rings.
With tests to guide and check each call,
Speak digits true, no errors fall.
🌟🔢✨


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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 08ed3c6 and d1f05a1.

Files selected for processing (3)
  • lingua_franca/format.py (2 hunks)
  • lingua_franca/lang/format_en.py (1 hunks)
  • test/unittests/test_format_en.py (2 hunks)
Additional comments not posted (2)
lingua_franca/format.py (1)

37-37: Function registration is correct.

The pronounce_digits function has been correctly registered in the _REGISTERED_FUNCTIONS tuple. This is necessary for the function to be accessible as intended.

test/unittests/test_format_en.py (1)

39-39: Import statement updated correctly.

The import statement has been correctly updated to include pronounce_digits. This is necessary for the tests to access the newly added function.

Comment on lines +68 to +102
def pronounce_digits_en(number, places=2, all_digits=False):
if isinstance(number, str):
op_val = number
decimal_part = ""
if "." in number:
op_val, decimal_part = number.split(".")
if all_digits:
op_val = " ".join([pronounce_number_en(int(ch))
for ch in op_val])
else:

op_val = pronounce_number_en(int(op_val))
if decimal_part:
decimal_part = " ".join([pronounce_number_en(int(ch))
for ch in decimal_part[:places]])
return op_val + " point " + decimal_part
return op_val

if "." in str(number):
op_val, decimal_part = str(number).split(".")
decimal_part = " ".join([pronounce_number_en(int(ch))
for ch in decimal_part[:places]])
else:
op_val = str(number)
decimal_part = ""

if all_digits:
op_val = " ".join([pronounce_number_en(int(ch))
for ch in op_val])
else:
op_val = pronounce_number_en(int(op_val))
if decimal_part:
return op_val + " point " + decimal_part
return op_val

Copy link

Choose a reason for hiding this comment

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

Review of pronounce_digits_en function

The function pronounce_digits_en has been added to handle the pronunciation of digits. It allows for specifying the number of decimal places and whether to pronounce all digits. Here are a few observations and suggestions:

  1. Type Checking: The use of isinstance to differentiate behavior based on the type of number is a good practice. This ensures that the function can handle different types of inputs robustly.
  2. Handling of Decimal Parts: The logic to split and handle the decimal part of the number is clear and well-implemented. However, consider adding error handling for cases where the input is not as expected (e.g., non-numeric strings).
  3. Use of List Comprehensions: The use of list comprehensions for constructing the spoken form of the number is efficient and Pythonic.
  4. Potential Refactoring: The blocks of code handling the string and non-string inputs are quite similar and could potentially be refactored to reduce duplication. This could improve maintainability.
  5. Documentation: Ensure that the function's docstring is updated to reflect all parameters and possible edge cases.

Overall, the function implementation looks solid but consider the above points to further enhance the code quality and robustness.

lingua_franca/format.py Outdated Show resolved Hide resolved
test/unittests/test_format_en.py Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@JarbasAl JarbasAl closed this Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants