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: list join util #269

Merged
merged 2 commits into from
Nov 7, 2024
Merged

feat: list join util #269

merged 2 commits into from
Nov 7, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Nov 7, 2024

join word lists with "or" or "and"

split from #268

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new JSON files for word connectors in multiple languages, including Azerbaijani, Catalan, Czech, Danish, German, English, Persian, Polish, Slovenian, and Ukrainian.
    • Added functionality to join lists of items using language-specific connectors ("and" and "or"), enhancing multilingual support.
  • Bug Fixes

    • Improved language handling in the CommonQuerySkill class to ensure correct processing of noise words based on primary language codes.

Copy link
Contributor

coderabbitai bot commented Nov 7, 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 2 minutes and 21 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 6810e19 and 949989f.

Walkthrough

A series of new JSON files named word_connectors.json have been added across multiple language directories within the ovos_workshop/res/text/ structure. Each file contains key-value pairs that translate the logical connectors "and" and "or" into various languages, including Azerbaijani, Catalan, Czech, Danish, German, English, Persian, Polish, Slovenian, Ukrainian, and more. Additionally, modifications have been made to the common_query_skill.py and ovos.py files to enhance language handling and introduce new functions for joining lists with language-specific connectors.

Changes

File Path Change Summary
ovos_workshop/res/text/az/word_connectors.json New file added with translations: "and": "və", "or": "ya"
ovos_workshop/res/text/ca/word_connectors.json New file added with translations: "and": "i", "or": "o"
ovos_workshop/res/text/cs/word_connectors.json New file added with translations: "and": "a", "or": "nebo"
ovos_workshop/res/text/da/word_connectors.json New file added with translations: "and": "og", "or": "eller"
ovos_workshop/res/text/de/word_connectors.json New file added with translations: "and": "und", "or": "oder"
ovos_workshop/res/text/en/word_connectors.json New file added with translations: "and": "and", "or": "or"
ovos_workshop/res/text/fa/word_connectors.json New file added with translations: "and": "و", "or": "یا"
ovos_workshop/res/text/pl/word_connectors.json New file added with translations: "and": "oraz", "or": "lub"
ovos_workshop/res/text/sl/word_connectors.json New file added with translations: "and": "in", "or": "ali"
ovos_workshop/res/text/uk/word_connectors.json New file added with translations: "and": "та", "or": "або"
ovos_workshop/skills/common_query_skill.py Updated language handling to use primary language code for noise words and file paths.
ovos_workshop/skills/ovos.py Added functions for retrieving language-specific connectors and joining word lists.

Possibly related PRs

  • fix:langcodes #241: The changes in this PR enhance language resource management and dialect support, which could relate to the introduction of new language-specific JSON files like word_connectors.json for Azerbaijani.

Suggested reviewers

  • goldyfruit

Poem

🐇 In fields of words, we hop and play,
New connectors bloom in bright array.
"And" and "or" in tongues so sweet,
Multilingual joy, a lovely treat!
With JSON paths, our skills take flight,
Hopping through languages, pure delight! 🌼


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 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.

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 21 lines in your changes missing coverage. Please review.

Project coverage is 51.36%. Comparing base (7c02206) to head (949989f).
Report is 79 commits behind head on dev.

Files with missing lines Patch % Lines
ovos_workshop/skills/ovos.py 14.28% 18 Missing ⚠️
ovos_workshop/skills/common_query_skill.py 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #269      +/-   ##
==========================================
- Coverage   53.41%   51.36%   -2.06%     
==========================================
  Files          37       36       -1     
  Lines        4362     4213     -149     
==========================================
- Hits         2330     2164     -166     
- Misses       2032     2049      +17     

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

@github-actions github-actions bot added feature and removed feature labels Nov 7, 2024
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: 1

🧹 Outside diff range and nitpick comments (3)
ovos_workshop/skills/common_query_skill.py (2)

92-93: LGTM: Consistent language handling in property accessors.

The property accessors correctly handle the primary language code extraction. Consider extracting the language code splitting into a private method to avoid code duplication.

+    def _get_primary_lang(self) -> str:
+        return self.lang.split("-")[0]

     @property
     def translated_noise_words(self) -> List[str]:
-        return self._translated_noise_words.get(self.lang.split("-")[0], [])
+        return self._translated_noise_words.get(self._get_primary_lang(), [])

     @translated_noise_words.setter
     def translated_noise_words(self, val: List[str]):
-        self._translated_noise_words[self.lang.split("-")[0]] = val
+        self._translated_noise_words[self._get_primary_lang()] = val

Also applies to: 98-99


183-183: LGTM: Consistent language handling in remove_noise method.

The language parameter handling is correctly implemented. This change would also benefit from using the suggested _get_primary_lang method.

     def remove_noise(self, phrase: str, lang: str = None) -> str:
-        lang = (lang or self.lang).split("-")[0]
+        lang = lang.split("-")[0] if lang else self._get_primary_lang()
ovos_workshop/skills/ovos.py (1)

2546-2578: Improve type hints and input validation

The function implementation is good but could use some improvements:

  1. Add type hint for sep parameter
  2. Add validation for connector parameter
  3. Move connector mapping to module level
+ # At module level
+ SUPPORTED_CONNECTORS = {
+     "and": _get_connector_word,
+     "or": _get_connector_word
+ }

- def join_word_list(items: List[str], connector: str, sep: str, lang:str) -> str:
+ def join_word_list(items: List[str], connector: str, sep: Optional[str], lang: str) -> str:
     """Join a list into a phrase using the given connector word
     
     Examples:
         join_word_list([1,2,3], "or") ->  "1, 2 or 3"
         join_word_list([1,2,3], "and") ->  "1, 2 and 3"
         join_word_list([1,2,3], "and", ";") ->  "1; 2 and 3"
     
     Args:
         items (array): items to be joined
         connector (str): connecting word ("and" or "or")
         sep (str, optional): separator character, default = ","
         lang (str): BCP-47 language code
     Returns:
         str: the connected list phrase
     Raises:
         ValueError: If connector is not "and" or "or"
     """
+    if connector not in SUPPORTED_CONNECTORS:
+        raise ValueError(f"Connector must be one of: {list(SUPPORTED_CONNECTORS.keys())}")
     
-    cons = {
-        "and": _get_and_word,
-        "or": _get_or_word
-    }
     if not items:
         return ""
     if len(items) == 1:
         return str(items[0])
     
     if not sep:
         sep = ", "
     else:
         sep += " "
     return (sep.join(str(item) for item in items[:-1]) +
-            " " + cons[connector](lang) +
+            " " + SUPPORTED_CONNECTORS[connector](connector, lang) +
             " " + items[-1])
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c71926e and 6810e19.

📒 Files selected for processing (12)
  • ovos_workshop/res/text/az/word_connectors.json (1 hunks)
  • ovos_workshop/res/text/ca/word_connectors.json (1 hunks)
  • ovos_workshop/res/text/cs/word_connectors.json (1 hunks)
  • ovos_workshop/res/text/da/word_connectors.json (1 hunks)
  • ovos_workshop/res/text/de/word_connectors.json (1 hunks)
  • ovos_workshop/res/text/en/word_connectors.json (1 hunks)
  • ovos_workshop/res/text/fa/word_connectors.json (1 hunks)
  • ovos_workshop/res/text/pl/word_connectors.json (1 hunks)
  • ovos_workshop/res/text/sl/word_connectors.json (1 hunks)
  • ovos_workshop/res/text/uk/word_connectors.json (1 hunks)
  • ovos_workshop/skills/common_query_skill.py (4 hunks)
  • ovos_workshop/skills/ovos.py (2 hunks)
✅ Files skipped from review due to trivial changes (10)
  • ovos_workshop/res/text/az/word_connectors.json
  • ovos_workshop/res/text/ca/word_connectors.json
  • ovos_workshop/res/text/cs/word_connectors.json
  • ovos_workshop/res/text/da/word_connectors.json
  • ovos_workshop/res/text/de/word_connectors.json
  • ovos_workshop/res/text/en/word_connectors.json
  • ovos_workshop/res/text/fa/word_connectors.json
  • ovos_workshop/res/text/pl/word_connectors.json
  • ovos_workshop/res/text/sl/word_connectors.json
  • ovos_workshop/res/text/uk/word_connectors.json
🧰 Additional context used
🪛 Ruff
ovos_workshop/skills/ovos.py

2523-2523: Undefined name json

(F821)


2542-2542: Undefined name json

(F821)

🔇 Additional comments (3)
ovos_workshop/skills/common_query_skill.py (2)

70-72: LGTM: Improved language code handling.

The extraction of the primary language code using split("-")[0] is a good practice for resource file handling, ensuring compatibility with locale-specific language codes (e.g., "en-US" → "en").


82-83: LGTM: Proper language-specific noise words storage.

The implementation correctly stores noise words in a dictionary using the primary language code as the key, which is a clean and efficient approach.

ovos_workshop/skills/ovos.py (1)

2067-2067: LGTM: Good improvement to localization

The replacement of join_list with join_word_list in ask_selection improves the localization capabilities by using language-specific connectors.

ovos_workshop/skills/ovos.py Outdated Show resolved Hide resolved
@JarbasAl JarbasAl merged commit 4052ac9 into dev Nov 7, 2024
8 checks passed
This was referenced Nov 7, 2024
This was referenced Nov 14, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 18, 2024
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