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

No implementors of 'levenshteinDistanceTo:' #16

Open
stlutz opened this issue May 5, 2019 · 1 comment
Open

No implementors of 'levenshteinDistanceTo:' #16

stlutz opened this issue May 5, 2019 · 1 comment

Comments

@stlutz
Copy link

stlutz commented May 5, 2019

The method DomainObject class >> resolve:createBasedOn:automaticAccept: looks off to me. It sends the selector levenshteinDistanceTo: but there are no implementors for it.

@codeZeilen
Copy link
Member

Welp, it is part of my own standard library extensions. I will commit it tomorrow. Until then here it is:

String>>#levenshteinDistanceTo: aString 
	
	| sourceString targetString costs |
	
	sourceString := self asLowercase.
	targetString := aString asLowercase.
	
	costs := Matrix rows: sourceString size + 1 columns: targetString size + 1 element: 0.
	
	costs atColumn: 1 put: (0 to: sourceString size).
	costs atRow: 1 put: (0 to: targetString size).
	
	targetString withIndexDo: [:targetCharacter :targetIndex |
		sourceString withIndexDo: [:sourceCharacter :sourceIndex | | cost |
			cost := targetCharacter = sourceCharacter ifTrue: [0] ifFalse: [1].
			
			costs at: sourceIndex + 1 at: targetIndex + 1 put: ({
				(costs at: sourceIndex + 1 at: targetIndex) + 1 . "deletion" 
				(costs at: sourceIndex at: targetIndex + 1) + 1 . "insertion"
				(costs at: sourceIndex at: targetIndex) + cost . "potential substitution"
			} min) ]].
	
	^ costs at: costs rowCount at: costs columnCount 

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

2 participants