hermetrics
Advanced tools
Comparing version 1.0.10 to 1.1.10
@@ -6,7 +6,16 @@ import LevenshteinCostOptions from '../interfaces/levenshtein-opts.interface'; | ||
/** | ||
* distance | ||
*/ | ||
* distance | ||
*/ | ||
distance(source: string, target: string, { deletionCost, insertionCost, substitutionCost }?: LevenshteinCostOptions): number; | ||
maxDistance(source: string, target: string, { deletionCost, insertionCost, substitutionCost }?: LevenshteinCostOptions): number; | ||
/** | ||
* | ||
* @param source | ||
* @param target | ||
* @param cost | ||
*/ | ||
minDistance(source: string, target: string, { deletionCost, insertionCost, substitutionCost }?: LevenshteinCostOptions): number; | ||
normalize(x: number, low?: number, high?: number): number; | ||
normalizedDistance(source: string, target: string, { deletionCost, insertionCost, substitutionCost }?: LevenshteinCostOptions): number; | ||
} | ||
export default Metric; |
@@ -8,4 +8,4 @@ "use strict"; | ||
/** | ||
* distance | ||
*/ | ||
* distance | ||
*/ | ||
distance(source, target, { deletionCost, insertionCost, substitutionCost } = {}) { | ||
@@ -17,3 +17,31 @@ return source === target ? 0 : 1; | ||
} | ||
/** | ||
* | ||
* @param source | ||
* @param target | ||
* @param cost | ||
*/ | ||
minDistance(source, target, { deletionCost, insertionCost, substitutionCost } = {}) { | ||
return 0; | ||
} | ||
normalize(x, low = 0, high = 1) { | ||
//const norm : number = 0 | ||
if (high <= low) { | ||
return 0; | ||
} | ||
if (x >= high) { | ||
return 1; | ||
} | ||
if (x <= low) { | ||
return 0; | ||
} | ||
return (x - low) / (high - low); | ||
} | ||
normalizedDistance(source, target, { deletionCost, insertionCost, substitutionCost } = {}) { | ||
const x = this.distance(source, target, { deletionCost, insertionCost, substitutionCost }); | ||
const min = this.minDistance(source, target, { deletionCost, insertionCost, substitutionCost }); | ||
const max = this.maxDistance(source, target, { deletionCost, insertionCost, substitutionCost }); | ||
return this.normalize(x, min, max); | ||
} | ||
} | ||
exports.default = Metric; |
import Levenshtein from './hermetrics/levenshtein'; | ||
import Metric from './hermetrics/metric'; | ||
export { Levenshtein, Metric }; | ||
import Jaro from './hermetrics/jaro'; | ||
import JaroWinkler from './hermetrics/jaro_winkler'; | ||
export { Levenshtein, Metric, Jaro, JaroWinkler }; |
@@ -10,1 +10,5 @@ "use strict"; | ||
exports.Metric = metric_1.default; | ||
const jaro_1 = __importDefault(require("./hermetrics/jaro")); | ||
exports.Jaro = jaro_1.default; | ||
const jaro_winkler_1 = __importDefault(require("./hermetrics/jaro_winkler")); | ||
exports.JaroWinkler = jaro_winkler_1.default; |
{ | ||
"name": "hermetrics", | ||
"version": "1.0.10", | ||
"version": "1.1.10", | ||
"description": "Javascript version of hermetrics.py", | ||
@@ -33,2 +33,3 @@ "main": "dist/index.js", | ||
"chai": "^4.2.0", | ||
"env-cmd": "^10.1.0", | ||
"eslint": "^6.8.0", | ||
@@ -44,7 +45,13 @@ "eslint-config-airbnb": "^18.0.1", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"husky": "^4.2.3", | ||
"mocha": "^7.1.0", | ||
"semantic-release": "^17.0.4", | ||
"ts-node": "^8.6.2", | ||
"typescript": "^3.8.3", | ||
"semantic-release": "^17.0.4" | ||
} | ||
"typescript": "^3.8.3" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-push": "npm test" | ||
} | ||
} | ||
} |
@@ -10,2 +10,3 @@ import Metric from './metric' | ||
public distance (source: string, target: string, { deletionCost, insertionCost, substitutionCost }: LevenshteinCostOptions = {}): number { | ||
const sourceLength: number = source.length | ||
@@ -12,0 +13,0 @@ const targetLength: number = target.length |
@@ -6,3 +6,4 @@ import LevenshteinCostOptions from '../interfaces/levenshtein-opts.interface' | ||
constructor (name = 'Generic') { | ||
constructor (name = 'Generic') | ||
{ | ||
this._name = name | ||
@@ -12,13 +13,51 @@ } | ||
/** | ||
* distance | ||
*/ | ||
public distance (source: string, target: string, { deletionCost, insertionCost, substitutionCost }: LevenshteinCostOptions = {}): number { | ||
* distance | ||
*/ | ||
public distance (source: string, target: string, { deletionCost, insertionCost, substitutionCost }: LevenshteinCostOptions = {}): number | ||
{ | ||
return source === target ? 0 : 1 | ||
} | ||
public maxDistance (source: string, target: string, { deletionCost, insertionCost, substitutionCost }: LevenshteinCostOptions = {}): number { | ||
public maxDistance (source: string, target: string, { deletionCost, insertionCost, substitutionCost }: LevenshteinCostOptions = {}): number | ||
{ | ||
return (source.length === 0 && target.length === 0) ? 0 : 1 | ||
} | ||
/** | ||
* | ||
* @param source | ||
* @param target | ||
* @param cost | ||
*/ | ||
public minDistance (source: string, target: string, { deletionCost, insertionCost, substitutionCost }: LevenshteinCostOptions = {}) : number | ||
{ | ||
return 0 | ||
} | ||
public normalize(x: number, low: number = 0, high: number = 1): number | ||
{ | ||
//const norm : number = 0 | ||
if (high <= low) { | ||
return 0 | ||
} | ||
if (x >= high) { | ||
return 1 | ||
} | ||
if (x <= low) { | ||
return 0 | ||
} | ||
return (x - low) / (high - low) | ||
} | ||
public normalizedDistance (source: string, target: string, {deletionCost, insertionCost, substitutionCost} : LevenshteinCostOptions = {}) : number | ||
{ | ||
const x : number = this.distance(source, target, {deletionCost, insertionCost, substitutionCost}) | ||
const min: number= this.minDistance(source, target, {deletionCost, insertionCost, substitutionCost}) | ||
const max: number = this.maxDistance(source, target, {deletionCost, insertionCost, substitutionCost}) | ||
return this.normalize(x, min, max) | ||
} | ||
} | ||
export default Metric |
import Levenshtein from './hermetrics/levenshtein' | ||
import Metric from './hermetrics/metric' | ||
import Jaro from './hermetrics/jaro' | ||
import JaroWinkler from './hermetrics/jaro_winkler' | ||
export { | ||
Levenshtein, | ||
Metric | ||
Metric, | ||
Jaro, | ||
JaroWinkler | ||
} |
Sorry, the diff of this file is not supported yet
36080
29
791
21