Module: Vladlev
- Extended by:
- FFI::Library
- Defined in:
- lib/vladlev.rb,
lib/vladlev/version.rb,
lib/vladlev/levenshtein.rb
Defined Under Namespace
Classes: Levenshtein
Constant Summary collapse
- JRUBY_NATIVE =
RUBY_PLATFORM =~ /java/ && file_fallback_path('levenshtein.jar')
- C_EXT_NATIVE =
!JRUBY_NATIVE && file_fallback_path('levenshtein.so', 'levenshtein.bundle')
- VERSION =
'1.2.0'
Class Method Summary collapse
-
._internal_distance(str1, str2, max) ⇒ Integer
Calculate the levenshtein distance between two strings.
- ._normalized_distance(str1, str2, max) ⇒ Object
- .distance(str1, str2, max = 9999) ⇒ Object
- .file_fallback_path(*files) ⇒ Object
- .get_normalized_distance(str1, str2, max = 9999) ⇒ Object
Class Method Details
._internal_distance(str1, str2, max) ⇒ Integer
Calculate the levenshtein distance between two strings
18 19 20 |
# File 'lib/vladlev.rb', line 18 def self._internal_distance(str1, str2, max) Java::LevenshteinDistance.distance(str1, str2, max) end |
._normalized_distance(str1, str2, max) ⇒ Object
22 23 24 |
# File 'lib/vladlev.rb', line 22 def self._normalized_distance(str1, str2, max) Java::LevenshteinDistance.normalized_distance(str1, str2, max) end |
.distance(str1, str2, max = 9999) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/vladlev.rb', line 63 def self.distance(str1, str2, max = 9999) return 0 if str1.nil? && str2.nil? return str2.size if str1.nil? return str1.size if str2.nil? self._internal_distance(str1, str2, max) end |
.file_fallback_path(*files) ⇒ Object
2 3 4 |
# File 'lib/vladlev.rb', line 2 def self.file_fallback_path(*files) files.map { |file| File.join(File.dirname(__FILE__), file) }.detect { |file| File.exist?(file) } end |
.get_normalized_distance(str1, str2, max = 9999) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/vladlev.rb', line 71 def self.get_normalized_distance(str1, str2, max = 9999) return 0 if str1.nil? && str2.nil? return 1.0 if str1.nil? return 1.0 if str2.nil? self._normalized_distance(str1, str2, max) end |