-
-
Notifications
You must be signed in to change notification settings - Fork 392
Double pinyin query #2427
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
Double pinyin query #2427
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
73c4a69
to
22f6ad7
Compare
@VictoriousRaptor what's the status of this pr? |
POC. I'm using it daily and so far so good. Since there're many double pinyin mappings we should make it user configurable. Is it acceptable to allow users to edit a json file that defines the mapping? |
well I can't think anything better...maybe I do want this to be plugin-able, but can't think of a good way to design the api. |
0c01c95
to
f673000
Compare
This comment has been minimized.
This comment has been minimized.
- Check settings or it won't work as expected
There was a problem hiding this 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
🧹 Nitpick comments (1)
Flow.Launcher.Infrastructure/PinyinAlphabet.cs (1)
137-144
: Consider adding input validation for robustness.While the current implementation is functional, adding a simple validation check could prevent potential issues.
private string ToDoublePin(string fullPinyin) { + if (string.IsNullOrEmpty(fullPinyin)) + return fullPinyin; + if (currentDoublePinyinTable.TryGetValue(fullPinyin, out var doublePinyinValue)) { return doublePinyinValue; } return fullPinyin; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
Flow.Launcher.Infrastructure/PinyinAlphabet.cs
(1 hunks)Flow.Launcher.Infrastructure/UserSettings/Settings.cs
(5 hunks)Flow.Launcher/Languages/en.xaml
(1 hunks)Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs
(3 hunks)Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- Flow.Launcher.Infrastructure/UserSettings/Settings.cs
🧰 Additional context used
🧠 Learnings (1)
Flow.Launcher/Languages/en.xaml (1)
Learnt from: taooceros
PR: Flow-Launcher/Flow.Launcher#2616
File: Flow.Launcher/Flow.Launcher.csproj:7-7
Timestamp: 2024-10-08T15:52:58.573Z
Learning: In the Flow Launcher project, the version number in the `Flow.Launcher.csproj` file is dynamically updated during the CI/CD process.
🪛 GitHub Check: Check Spelling
Flow.Launcher/Languages/en.xaml
[warning] 114-114:
Neng
is not a recognized word. (unrecognized-spelling)
[warning] 114-114:
Neng
is not a recognized word. (unrecognized-spelling)
[warning] 113-113:
Ruan
is not a recognized word. (unrecognized-spelling)
[warning] 113-113:
Ruan
is not a recognized word. (unrecognized-spelling)
[warning] 111-111:
Xiao
is not a recognized word. (unrecognized-spelling)
[warning] 111-111:
Xiao
is not a recognized word. (unrecognized-spelling)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (9)
Flow.Launcher.Infrastructure/PinyinAlphabet.cs (3)
24-37
: LGTM! Clean dependency injection and reactive pattern implementation.The constructor properly initializes dependencies and sets up reactive updates for settings changes.
78-82
: Good fix for the translation eligibility logic.The method properly addresses the past review concern about rejecting valid double-pinyin queries with odd lengths. The logic is now more straightforward and user-friendly.
94-133
: Excellent fixes addressing past review concerns.The implementation now correctly:
- Updates the
previousIsChinese
flag (line 114)- Maps indices to point to the actual translated text, not spaces
- Handles both Chinese and non-Chinese character transitions properly
The past review concerns about off-by-one errors and flag updates have been resolved.
Flow.Launcher/Languages/en.xaml (1)
108-120
: Comprehensive localization support for double pinyin feature.The localization strings properly support the new double pinyin functionality. The static analysis warnings about "Neng", "Ruan", and "Xiao" are false positives - these are legitimate Chinese words/names used in the pinyin schema names.
Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml (1)
350-387
: Well-structured hierarchical UI for pinyin settings.The grouped card layout with conditional visibility creates an intuitive user experience:
- Base pinyin setting controls overall feature
- Double pinyin toggle only appears when pinyin is enabled
- Schema selection only appears when double pinyin is enabled
The data binding and visibility logic is correctly implemented.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs (4)
38-38
: Good addition of dropdown data class for double pinyin schemas.Consistent with the existing pattern used for other dropdown data classes in the view model.
267-275
: Excellent dependency management between pinyin settings.The logic properly ensures that
UseDoublePinyin
is automatically disabled whenShouldUsePinyin
is set to false, maintaining consistent state and preventing invalid configurations.
277-284
: Clean implementation of double pinyin properties.The
UseDoublePinyin
property andDoublePinyinSchemas
list follow the established patterns in the view model and properly support the UI binding requirements.
181-181
: Proper localization update for the new dropdown.Ensures the double pinyin schema dropdown labels are updated when language changes, maintaining consistency with other dropdown controls.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for Double Pinyin in search by exposing new toggles in the UI, loading a JSON-based mapping table, and wiring it through settings, view models, and the PinyinAlphabet.
- UI: new switch and combo box for enabling double-pinyin and selecting a schema
- Settings & ViewModel: new
UseDoublePinyin
andDoublePinyinSchema
properties, with binding and localization - Core logic: JSON file of mappings, loading in
PinyinAlphabet
, and a newTranslationMapping
class with unit tests
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
SettingPages/Views/SettingsPaneGeneral.xaml | Added cards/toggles and schema selector |
SettingsPaneGeneralViewModel.cs | Introduced UseDoublePinyin , schema list |
Resources/double_pinyin.json | New mapping table for all supported schemas |
Languages/en.xaml | Added localization for toggles and schemas |
Flow.Launcher.csproj | Ensured JSON is copied to output |
TranslationMapping.cs | New mapping utility with AddNewIndex /MapToOriginalIndex |
TranslationMappingTest.cs | Unit tests for TranslationMapping |
UserSettings/Settings.cs | Added settings, JSON serialization, enum |
Infrastructure/StringMatcher.cs | Switched to ShouldTranslate predicate |
Infrastructure/PinyinAlphabet.cs | Loads JSON, applies double-pinyin translation |
Infrastructure/IAlphabet.cs | Updated interface to use ShouldTranslate |
Comments suppressed due to low confidence (3)
Flow.Launcher.Infrastructure/TranslationMapping.cs:29
- Method name 'endConstruct' doesn't follow .NET naming conventions; consider renaming to 'EndConstruct'.
public void endConstruct()
Flow.Launcher.Infrastructure/TranslationMapping.cs:29
- The behavior of
endConstruct
isn't covered by unit tests; consider adding tests to verify it prevents further calls toAddNewIndex
after construction.
public void endConstruct()
Flow.Launcher/Flow.Launcher.csproj:130
- Using 'Update' for a new resource entry may not include the JSON in the build; consider using 'Include' or verify that default globbing picks it up so it’s reliably copied under the Resources folder at runtime.
<None Update="Resources\double_pinyin.json">
LGTM |
This pull request introduces a comprehensive set of changes to enhance Pinyin support in the application, including the addition of Double Pinyin (“双拼”) functionality, improved translation mappings, and related settings. The most significant updates include the implementation of the
IAlphabet
interface, the refactoring of thePinyinAlphabet
class, the introduction of Double Pinyin schemas, and updates to the user settings and localization files.UI in General Panel
Pinyin and Double Pinyin Enhancements:
IAlphabet
interface to define methods for language translation and determining translatability. (Flow.Launcher.Infrastructure/IAlphabet.cs
)PinyinAlphabet
class to support Double Pinyin, utilize a cache for translations, and dynamically reload schemas based on user settings. (Flow.Launcher.Infrastructure/PinyinAlphabet.cs
)Flow.Launcher.Infrastructure/UserSettings/Settings.cs
) [1] [2]Translation Mapping Improvements:
TranslationMapping
class to simplify and optimize the mapping of original to translated indices. (Flow.Launcher.Infrastructure/TranslationMapping.cs
)TranslationMapping
to validate its functionality. (Flow.Launcher.Test/TranslationMappingTest.cs
)Localization and Resource Updates:
Flow.Launcher/Languages/en.xaml
)double_pinyin.json
to project resources for schema definitions. (Flow.Launcher/Flow.Launcher.csproj
)Codebase Simplifications:
StringMatcher.cs
to use the newShouldTranslate
method fromIAlphabet
. (Flow.Launcher.Infrastructure/StringMatcher.cs
)IsAcronym
andIsAcronymCount
static for better encapsulation. (Flow.Launcher.Infrastructure/StringMatcher.cs
) [1] [2]