Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ AICosineSimilarityDistanceTest >> setUp [
{ #category : '*AI-EditDistances-Tests' }
AICosineSimilarityDistanceTest >> testCosineSimilarityDistanceTo [

self assert: (cosineDistance distanceBetween: #(3 45 7 2) and: #(2 54 13 15)) closeTo: 0.9722
self assert: (cosineDistance distanceBetween: #(3 45 7 2) and: #(2 54 13 15)) closeTo: 0.9722842517123499
]
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ AIDamerauLevenshteinDistanceTest >> testDistanceToUsingAIDamerauLevenshteinDista

{ #category : 'tests' }
AIDamerauLevenshteinDistanceTest >> testFillFirstTwoRowsAndColumns [

| max result |
damerauLevenshtein distanceMatrix: (Array2D rows: 5 columns: 5).
damerauLevenshtein distanceMatrix: (CTArray2D rows: 5 columns: 5).
max := 10.
result := Array2D new.
result rows: 5 columns: 5 contents:
result := CTArray2D rows: 5 columns: 5 contents:
{ { max . max . max . max . max } .
{ max . 0 . 1 . 2 . 3 } .
{ max . 1 . nil . nil . nil } .
Expand Down
4 changes: 2 additions & 2 deletions src/AI-EditDistances-Tests/AIEuclideanDistanceTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ AIEuclideanDistanceTest >> testEuclideanDistanceThreeDimensions [

self
assert: (metric distanceBetween: #( -5.1 4 -3.1 ) and: #( 4 5.9 -2.2 ))
closeTo: 9.3397
closeTo: 9.339700209321496
]

{ #category : '*AI-EditDistances-Tests' }
AIEuclideanDistanceTest >> testEuclideanDistanceTwoDimensions [

self
assert: (metric distanceBetween: #( -3.54 7 ) and: #( -11.64 9.9 ))
closeTo: 8.603488.
closeTo: 8.603487664894978.

self
assert: (metric distanceBetween: #( 0 1 ) and: #( 1 0))
Expand Down
4 changes: 2 additions & 2 deletions src/AI-EditDistances-Tests/AIMinkowskiDistanceTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AIMinkowskiDistanceTest >> testDistance2WithP3 [
metric p: 3.
self
assert: (metric distanceBetween: #( 0 2 3 4 ) and: #( 2 4 3 7 ))
closeTo: 3.5033
closeTo: 3.503398060386724
]

{ #category : 'tests' }
Expand All @@ -41,5 +41,5 @@ AIMinkowskiDistanceTest >> testDistanceWithP3 [
metric p: 3.
self
assert: (metric distanceBetween: #( 1 2 3 4 5 6 ) and: #( 7 8 9 10 11 12 ))
closeTo: 10.9027235
closeTo: 10.902723556992836
]
10 changes: 5 additions & 5 deletions src/AI-EditDistances/AIDamerauLevenshteinDistance.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ AIDamerauLevenshteinDistance >> fillFirstTwoRowsAndColumnsWith: firstString and:
{ #category : 'private' }
AIDamerauLevenshteinDistance >> initializeDistanceMatrixWith: firstString and: secondString [

distanceMatrix := Array2D
rows: firstString size + 2
distanceMatrix := CTArray2D
rows: firstString size + 2
columns: secondString size + 2.
self fillFirstTwoRowsAndColumnsWith: firstString and: secondString
]

self fillFirstTwoRowsAndColumnsWith: firstString and: secondString
]
2 changes: 1 addition & 1 deletion src/AI-EditDistances/AIEpisodeDistance.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ AIEpisodeDistance >> longestCommonSubsequenceLength: firstString and: secondStri
m := firstString size.
n := secondString size.

dp := Array2D rows: m + 1 columns: n + 1.
dp := CTArray2D rows: m + 1 columns: n + 1.
1 to: m + 1 do: [ :i | dp at: i at: 1 put: 0 ].
1 to: n + 1 do: [ :j | dp at: 1 at: j put: 0 ].

Expand Down
21 changes: 10 additions & 11 deletions src/AI-EditDistances/AILevenshteinDistance.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@ AILevenshteinDistance >> distanceBetween: firstString and: secondString [
{ #category : 'private' }
AILevenshteinDistance >> distanceMatrixBasedOn: firstString and: secondString [

| distanceMatrix |
"Changed from CTArray2D to Array2D to fix undeclared variable error"
distanceMatrix := Array2D
rows: secondString size + 1
| distanceMatrix |
distanceMatrix := CTArray2D
rows: secondString size + 1
columns: firstString size + 1.

self fillFirstRowAndColumn: distanceMatrix.
self fillStartingFromSecondRowAndColumn: distanceMatrix
basedOn: firstString
and: secondString.
^ distanceMatrix
self fillFirstRowAndColumn: distanceMatrix.

self fillStartingFromSecondRowAndColumn: distanceMatrix
basedOn: firstString
and: secondString.

^ distanceMatrix
]

{ #category : 'private' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@ AIRestrictedDamerauLevenshteinDistance >> distanceBetween: firstString and: seco
{ #category : 'private' }
AIRestrictedDamerauLevenshteinDistance >> distanceMatrixBasedOn: firstString and: secondString [

| distanceMatrix |
distanceMatrix := Array2D
rows: secondString size + 1
columns: firstString size + 1.
| distanceMatrix |
distanceMatrix := CTArray2D
extent: (firstString size + 1) @ (secondString size + 1).

self fillFirstRowAndColumn: distanceMatrix.
self fillStartingFromSecondRowAndColumn: distanceMatrix
basedOn: firstString
and: secondString.
^ distanceMatrix
self fillFirstRowAndColumn: distanceMatrix.

self fillStartingFromSecondRowAndColumn: distanceMatrix
basedOn: firstString
and: secondString.

^ distanceMatrix
]

{ #category : 'private' }
Expand All @@ -78,14 +77,12 @@ AIRestrictedDamerauLevenshteinDistance >> fillCellInMatrix: aMatrix at: i at: j
]

{ #category : 'private' }
AIRestrictedDamerauLevenshteinDistance >> fillFirstRowAndColumn: aMatrix [

"Fill the first row and column starting with 1"
1 to: aMatrix rowCount do: [ :i |
aMatrix at: i at: 1 put: i - 1 ].

2 to: aMatrix columnCount do: [ :j |
aMatrix at: 1 at: j put: j - 1 ].
AIRestrictedDamerauLevenshteinDistance >> fillFirstRowAndColumn: distanceMatrix[
"Initialize the first row and column of the distance matrix with incremental values."
1 to: distanceMatrix height do: [ :i |
distanceMatrix atColumn: 1 atRow: i put: i - 1 ].
1 to: distanceMatrix width do: [ :j |
distanceMatrix atColumn: j atRow: 1 put: j - 1 ].
]

{ #category : 'private' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ BaselineOfAIEditDistances >> baseline: spec [
spec
baseline: 'AIExternalVectorMatrix'
with: [ spec repository: 'github://pharo-ai/external-dependencies' ].
spec
baseline: 'ContainersArray2D'
with: [ spec repository: 'github://pharo-containers/Containers-Array2D/src' ].
"Packages"
spec
package: 'AI-EditDistances' with: [ spec requires: #( 'AIExternalVectorMatrix' ) ];
package: 'AI-EditDistances' with: [ spec requires: #( 'AIExternalVectorMatrix' 'ContainersArray2D' ) ];
package: 'AI-EditDistances-Tests' with: [ spec requires: #( 'AI-EditDistances' ) ].
"Groups"
spec
Expand Down