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

Single-character words in inputs get ignored with White Similarity #23

Open
ranierorusso opened this issue Oct 29, 2019 · 0 comments
Open

Comments

@ranierorusso
Copy link

The following returns an exact match:

irb(main):164:0> Text::WhiteSimilarity.new.similarity("John F Kennedy", "John A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Kennedy")
1.0

I would not expect it to match exactly.

This returns NaN:

irb(main):165:0> Text::WhiteSimilarity.new.similarity("C J", "C J")
NaN

I am expecting this to return a 1.0.

The issue is in module Text, in class WhiteSimilarity, in private method word_letter_pairs which always expects the words that are parsed from input string argument to be at least two characters long.

An example of a refactor for this method would be to check for single-character length words and handle them differently:

  def word_letter_pairs(str)
    @word_letter_pairs[str] ||=
      str.upcase.split(/\s+/).map{ |word|
        if word.length == 1
          [word]
        else
          (0 ... (word.length - 1)).map { |i| word[i, 2] }
        end
      }.flatten.freeze
  end

I am using version 1.3.1

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

No branches or pull requests

1 participant