Skip to content

Sandbox 491#1

Closed
j--baker wants to merge 9 commits intoapache:masterfrom
j--baker:SANDBOX-491
Closed

Sandbox 491#1
j--baker wants to merge 9 commits intoapache:masterfrom
j--baker:SANDBOX-491

Conversation

@j--baker
Copy link
Contributor

@j--baker j--baker commented Mar 3, 2015

Please review these changes to LevenshteinDistance and FuzzyScore.

  • The extra parameters are now final fields.
  • The other helper methods not used to implement StringMetric are now private and static.
  • The unlimited version of the Levenshtein distance algorithm has been restored from commons-lang3.

j--baker added 4 commits March 3, 2015 13:58
- Restore the non-threshold implementation of the Levenshtein distance algorithm from commons-lang3's StringUtils.  This version avoids copying arrays.  compare(left, right) no longer delegates to compare(left, right, threshold).
- Fix the threshold implementation's table striping ASCII art.
- Add "threshold" field to LevenshteinDistance.  If this is null, then the unlimited version of the algorithm is used.  Else, the limited version is used.
- Add default and threshold versions of the constructor.
- Add static getDefaultInstance() which returns the unlimited version.
- Add "locale" field to FuzzyDistance.  Add default and Locale constructor.  Add static getDefaultInstance().  A null locale will cause Locale.getLocale() to be called each time compare(left, right) is called.
- Fix method name type in FuzzyScoreTest.
- Remove tests that no longer fail because of a null Locale.  The algorithm is no longer public.  If the field is null, Locale.getLocale() is used.
- Fix "s" and "t" -> "left" and "right" variable in Levenshtein distance algorithms.
- Remove unused org.junit.BeforeClass imports from FuzzyScoreTest and LevenshteinDistancetest.
Copy link
Member

Choose a reason for hiding this comment

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

Better make this check in the constructor and always assign a value to the locale field. This way all instance will be in a valid state after construction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. What if Locale.setDefault(Locale) is called afterward? Shouldn't it switch to using the new Locale?

Please confirm. I would also remove the DEFAULT_INSTANCE in that case.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I providing a default for the locale field a good idea at all? I don't think so. I think the locale parameter has to be mandatory.

- Remove the Locale.getDefault() logic in FuzzyScore.  There is no longer a DEFAULT_INSTANCE and the Locale may not be null.
Copy link
Member

Choose a reason for hiding this comment

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

Can be moved to @Before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even simpler:

private static final ENGLISH_SCORE = new FuzzyScore(Locale.ENGLISH);

Is that OK, or are there reasons to use @BeforeClass (more JUnit-y) or @Before (not static)?

Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

👍 for the static field!

j--baker added 4 commits March 4, 2015 12:43
- Replace instances of FuzzyScore(Locale.ENGLISH) in FuzzyScoreTest with a static final ENGLISH_SCORE constant.
- Replace instances of LevenshteinDistance() in LevenshteinDistanceTest with a static final UNLIMITED_DISTANCE constant.
- Convert LevenshteinDistanceTest.testGetLevenshteinDistance_StringStringInt() into ParameterizedLevenshteinDistanceTest.
Add missing ".similarity" part of package path to @link's in the unit test classes.
Remove unused Map and TreeMap imports from ParameterizedLevenshteinDistanceTest.
@j--baker
Copy link
Contributor Author

j--baker commented Mar 8, 2015

Added a PR for SANDBOX-493 which I'd like to merge into this branch after/if 493 makes it into master.
(Please let me know if I'm thinking about this wrong. I assume I should only be pulling from master, not other branches. Thanks!)

@asfgit asfgit closed this in 75cdc00 Mar 20, 2015
@kinow
Copy link
Member

kinow commented Mar 20, 2015

Merged, thanks!!!

asfgit pushed a commit that referenced this pull request Dec 8, 2017
Resolve checkstyle errors.
Carmineh added a commit to Carmineh/commons-text that referenced this pull request Oct 16, 2024
Carmineh added a commit to Carmineh/commons-text that referenced this pull request Oct 16, 2024
Carmineh added a commit to Carmineh/commons-text that referenced this pull request Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants