You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 1, 2023. It is now read-only.
Finds degree of similarity between two strings, based on [Dice's Coefficient](http://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient), which is mostly better than [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance).
5
4
@@ -8,17 +7,17 @@ Finds degree of similarity between two strings, based on [Dice's Coefficient](ht
var stringSimilarity =require('string-similarity');
42
+
var stringSimilarity =require("string-similarity");
45
43
46
-
var similarity =stringSimilarity.compareTwoStrings('healed', 'sealed');
44
+
var similarity =stringSimilarity.compareTwoStrings("healed", "sealed");
47
45
48
-
var matches =stringSimilarity.findBestMatch('healed', ['edward', 'sealed', 'theatre']);
46
+
var matches =stringSimilarity.findBestMatch("healed", [
47
+
"edward",
48
+
"sealed",
49
+
"theatre",
50
+
]);
49
51
```
50
52
51
53
#### For browser apps
@@ -73,32 +75,38 @@ The package contains two methods:
73
75
Returns a fraction between 0 and 1, which indicates the degree of similarity between the two strings. 0 indicates completely different strings, 1 indicates identical strings. The comparison is case-sensitive.
74
76
75
77
##### Arguments
76
-
78
+
77
79
1. string1 (string): The first string
78
80
2. string2 (string): The second string
79
-
81
+
80
82
Order does not make a difference.
81
-
83
+
82
84
##### Returns
83
-
85
+
84
86
(number): A fraction from 0 to 1, both inclusive. Higher number indicates more similarity.
stringSimilarity.compareTwoStrings('Olive-green table for sale, in extremely good condition.',
93
-
'For sale: table in very good condition, olive green in colour.');
94
+
stringSimilarity.compareTwoStrings(
95
+
"Olive-green table for sale, in extremely good condition.",
96
+
"For sale: table in very good condition, olive green in colour."
97
+
);
94
98
// → 0.6060606060606061
95
99
96
-
stringSimilarity.compareTwoStrings('Olive-green table for sale, in extremely good condition.',
97
-
'For sale: green Subaru Impreza, 210,000 miles');
100
+
stringSimilarity.compareTwoStrings(
101
+
"Olive-green table for sale, in extremely good condition.",
102
+
"For sale: green Subaru Impreza, 210,000 miles"
103
+
);
98
104
// → 0.2558139534883721
99
105
100
-
stringSimilarity.compareTwoStrings('Olive-green table for sale, in extremely good condition.',
101
-
'Wanted: mountain bike with at least 21 gears.');
106
+
stringSimilarity.compareTwoStrings(
107
+
"Olive-green table for sale, in extremely good condition.",
108
+
"Wanted: mountain bike with at least 21 gears."
109
+
);
102
110
// → 0.1411764705882353
103
111
```
104
112
@@ -112,16 +120,18 @@ Compares `mainString` against each string in `targetStrings`.
112
120
2. targetStrings (Array): Each string in this array will be matched against the main string.
113
121
114
122
##### Returns
123
+
115
124
(Object): An object with a `ratings` property, which gives a similarity rating for each target string, a `bestMatch` property, which specifies which target string was most similar to the main string, and a `bestMatchIndex` property, which specifies the index of the bestMatch in the targetStrings array.
116
125
117
126
##### Examples
127
+
118
128
```javascript
119
129
stringSimilarity.findBestMatch('Olive-green table for sale, in extremely good condition.', [
120
-
'For sale: green Subaru Impreza, 210,000 miles',
121
-
'For sale: table in very good condition, olive green in colour.',
130
+
'For sale: green Subaru Impreza, 210,000 miles',
131
+
'For sale: table in very good condition, olive green in colour.',
122
132
'Wanted: mountain bike with at least 21 gears.'
123
133
]);
124
-
// →
134
+
// →
125
135
{ ratings:
126
136
[ { target:'For sale: green Subaru Impreza, 210,000 miles',
127
137
rating:0.2558139534883721 },
@@ -132,34 +142,43 @@ stringSimilarity.findBestMatch('Olive-green table for sale, in extremely good co
132
142
bestMatch:
133
143
{ target:'For sale: table in very good condition, olive green in colour.',
134
144
rating:0.6060606060606061 },
135
-
bestMatchIndex:1
145
+
bestMatchIndex:1
136
146
}
137
147
```
138
148
139
149
## Release Notes
140
150
141
151
### 2.0.0
142
-
* Removed production dependencies
143
-
* Updated to ES6 (this breaks backward-compatibility for pre-ES6 apps)
152
+
153
+
- Removed production dependencies
154
+
- Updated to ES6 (this breaks backward-compatibility for pre-ES6 apps)
144
155
145
156
### 3.0.0
146
-
* Performance improvement for `compareTwoStrings(..)`: now O(n) instead of O(n^2)
147
-
* The algorithm has been tweaked slightly to disregard spaces and word boundaries. This will change the rating values slightly but not enough to make a significant difference
148
-
* Adding a `bestMatchIndex` to the results for `findBestMatch(..)` to point to the best match in the supplied `targetStrings` array
157
+
158
+
- Performance improvement for `compareTwoStrings(..)`: now O(n) instead of O(n^2)
159
+
- The algorithm has been tweaked slightly to disregard spaces and word boundaries. This will change the rating values slightly but not enough to make a significant difference
160
+
- Adding a `bestMatchIndex` to the results for `findBestMatch(..)` to point to the best match in the supplied `targetStrings` array
149
161
150
162
### 3.0.1
151
-
* Refactoring: removed unused functions; used `substring` instead of `substr`
152
-
* Updated dependencies
163
+
164
+
- Refactoring: removed unused functions; used `substring` instead of `substr`
165
+
- Updated dependencies
153
166
154
167
### 4.0.1
155
-
* Distributing as an UMD build to be used in browsers.
168
+
169
+
- Distributing as an UMD build to be used in browsers.
156
170
157
171
### 4.0.2
158
-
* Update dependencies to latest versions.
172
+
173
+
- Update dependencies to latest versions.
159
174
160
175
### 4.0.3
161
-
* Make compatible with IE and ES5. Also, update deps. (see [PR56](https://github.com/aceakash/string-similarity/pull/56))
162
176
177
+
- Make compatible with IE and ES5. Also, update deps. (see [PR56](https://github.com/aceakash/string-similarity/pull/56))
178
+
179
+
### 4.0.4
180
+
181
+
- Simplify some conditional statements. Also, update deps. (see [PR50](https://github.com/aceakash/string-similarity/pull/50))
0 commit comments