forked from iancanderson/ingreedy
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add continuous language option #10
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c35e37a
Add: ContinuousLanguageLocale module
sota-horiuchi a9df09b
Improve: reverse format
sota-horiuchi 1516428
Remove: newline
sota-horiuchi ce01093
Add: Taiwan and Thailand to CONTINUOUS_LANGUAGES_LOCALES
sota-horiuchi 72046b1
Refactore: method to get current locale
sota-horiuchi 75e1643
Fix: Dictionary initialization arg order
sota-horiuchi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Ingreedy | ||
module ContinuousLanguageLocale | ||
CONTINUOUS_LANGUAGES_LOCALES = %i(ja th zh-TW) | ||
|
||
def use_whitespace?(locale) | ||
!CONTINUOUS_LANGUAGES_LOCALES.include?(locale) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'ingreedy/continuous_language_locale' | ||
|
||
RSpec.describe Ingreedy::ContinuousLanguageLocale do | ||
include Ingreedy::ContinuousLanguageLocale | ||
|
||
describe '#use_whitespace?' do | ||
context 'when the locale is a continuous language' do | ||
it 'returns false' do | ||
expect(use_whitespace?(:ja)).to be_falsey | ||
expect(use_whitespace?(:th)).to be_falsey | ||
expect(use_whitespace?(:'zh-TW')).to be_falsey | ||
end | ||
end | ||
|
||
context 'when the locale is not a continuous language' do | ||
it 'returns true' do | ||
expect(use_whitespace?(:en)).to be_truthy | ||
expect(use_whitespace?(:fr)).to be_truthy | ||
expect(use_whitespace?(:'zh-CN')).to be_truthy | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Take for example
sugger 300g
: sincesugger
contains g in the quantity, it transitions to the next rule after reading tosug
in continuous language.Basically, nothing is considered to come after quantity, so add
any.absent?
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.
I don't quite follow this change, but i'm happy that if the tests are passing then it's probably fine 👍
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.
In continuation languages, where whitespace is treated as optional (denoted as "maybe"), parsing issues arise when encountering words that include units as substrings (for example, the letter "g" in "sugger"). This complication becomes apparent when tested locally.
The rule was designed to interpret strings structured as name+quantity. By ensuring no additional characters follow the quantity, we can eliminate the misinterpretation of substrings such as "g" in "suger" being wrongly recognized as a unit of quantity.
I hope I've explained it well.
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.
Oh great, I see! Thanks for explaining