···51515252The average of the scores from all passed strategies is returned as `highScore` (and `highScoreWeighted`) from `stringSameness()`
53535454-When no strategies are explicitly passed a default set of strategies is used, found in `@foxxmd/string-sameness/strategies`:
5454+When no strategies are explicitly passed a default set of strategies is used, found in `import {defaultStrategies} from @foxxmd/string-sameness;`:
55555656* [Dice's Coefficient](https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient) in [`diceSimilarities.ts`](/src/matchingStrategies/diceSimilarity.ts)
5757* [Cosine Similarity](https://en.wikipedia.org/wiki/Cosine_similarity) in [`cosineSimilarities.ts`](/src/matchingStrategies/cosineSimilarity.ts)
5858* [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance) in [`levenSimilarities.ts`](/src/matchingStrategies/levenSimilarity.ts)
5959+6060+Strategies can be accessed individually using `import {strategies} from @foxxmd/string-sameness`
59616062### Bring Your Own Strategy
6163···107109108110Pass a list of functions using `{transforms: []}` to transform the strings before comparison. When not explicitly provided a default set of functions is applied to normalize the strings (to remove trivial differences):
109111112112+* normalize unicode EX convert Ö => O
110113* convert to lowercase
111114* trim (remove whitespace at beginning/end)
112115* remove non-alphanumeric characters (punctuation and newlines)
113116* replace any instances of 2 or more consecutive whitespace with 1 whitespace
114117115115-This default set of functions is exported as `defaultStrCompareTransformFuncs`.
118118+* The default set of transformer functions is exported as `import {strDefaultTransforms} from @foxxmd/string-sameness;`
119119+* All built-in transformers can be found at `import {transforms} from @foxxmd/string-sameness;`
116120117121Example of supplying your own transform functions:
118122···128132const result = stringSameness('This is one sentence', 'This is another sentence', {transforms: myFuncs});
129133```
130134135135+## Token Re-ordering
136136+137137+If tokens (word) ordering in the strings is not important you can choose to have string-sameness attempt to re-order all words before comparing sameness. This makes comparison scores much closer to "absolute sameness in all characters within string". EX:
138138+139139+* `this is correct order`
140140+* `order correct this is`
141141+142142+Scores 60 **without** reordering
143143+144144+Scores 100 **with** reordering
145145+146146+Behavior caveats:
147147+148148+* The **second** string argument is reordered to match the **first** string argument
149149+* If the second string is longer than the first than any non-matched words are concatenated to the end of the re-ordered string in the same order they were found
150150+151151+To use:
152152+153153+```js
154154+import {stringSameness} from '@foxxmd/string-sameness';
155155+156156+const res = stringSameness(strA, strB, {reorder: true});
157157+```
158158+131159## Factory
132160133161For convenience, a factory function is also provided:
134162135163```ts
136136-import {createStringSameness} from "@foxxmd/string-sameness";
137137-import {levenStrategy} from "@foxxmd/string-sameness/strategies";
164164+import {createStringSameness, strategies} from "@foxxmd/string-sameness";
138165import {myTransforms, myStrats} from './util';
139166167167+const {levenStrategy} = strategies;
168168+140169// sets the default object to used with the third argument for `stringSameness`
141141-const myCompare = createStringSameness({transforms: myTransforms, strategies: myStrats});
170170+const myCompare = createStringSameness({transforms: myTransforms, strategies: [levenStrategy, ...myStrats]});
142171143172// uses myTransforms and myStrats
144173const plainResult = myCompare('This is one sentence', 'This is another sentence');
+12
dist/commonjs/atomic.d.ts
···11export interface StringComparisonOptions {
22+ /**
33+ * An array of transformations to apply to each string before comparing similarity
44+ * */
25 transforms?: StringTransformFunc[];
66+ /**
77+ * An array of strategies used to score similarity. All strategies scores are combined for an average high score.
88+ * */
39 strategies?: ComparisonStrategy<ComparisonStrategyResultValue>[];
1010+ /**
1111+ * Reorder second string so its token match order of first string as closely as possible
1212+ *
1313+ * Useful when only the differences in content are important, but not the order of the content
1414+ * */
1515+ reorder?: boolean;
416}
517export interface StringSamenessResult {
618 strategies: {
···11export interface StringComparisonOptions {
22+ /**
33+ * An array of transformations to apply to each string before comparing similarity
44+ * */
25 transforms?: StringTransformFunc[];
66+ /**
77+ * An array of strategies used to score similarity. All strategies scores are combined for an average high score.
88+ * */
39 strategies?: ComparisonStrategy<ComparisonStrategyResultValue>[];
1010+ /**
1111+ * Reorder second string so its token match order of first string as closely as possible
1212+ *
1313+ * Useful when only the differences in content are important, but not the order of the content
1414+ * */
1515+ reorder?: boolean;
416}
517export interface StringSamenessResult {
618 strategies: {