node-string-similarity
Version:
A TypeScript library for string similarity comparison
71 lines (70 loc) • 2.39 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const yargs_1 = __importDefault(require("yargs"));
const helpers_1 = require("yargs/helpers");
const index_1 = require("./index");
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
.command("compare <str1> <str2>", "Compare two strings using the default similarity algorithm", (yargs) => {
return yargs
.positional("str1", {
describe: "First string",
type: "string",
})
.positional("str2", {
describe: "Second string",
type: "string",
});
}, (args) => {
const result = (0, index_1.compareStrings)(args.str1, args.str2);
console.log(`Similarity (default): ${result}`);
})
.command("jaro-winkler <str1> <str2>", "Compare two strings using the Jaro-Winkler algorithm", (yargs) => {
return yargs
.positional("str1", {
describe: "First string",
type: "string",
})
.positional("str2", {
describe: "Second string",
type: "string",
});
}, (args) => {
const result = (0, index_1.jaroWinklerDistance)(args.str1, args.str2);
console.log(`Similarity (Jaro-Winkler): ${result}`);
})
.command("cosine <str1> <str2>", "Compare two strings using the Cosine Similarity algorithm", (yargs) => {
return yargs
.positional("str1", {
describe: "First string",
type: "string",
})
.positional("str2", {
describe: "Second string",
type: "string",
});
}, (args) => {
const result = (0, index_1.cosineSimilarity)(args.str1, args.str2);
console.log(`Similarity (Cosine): ${result}`);
})
.command("dice <str1> <str2>", "Compare two strings using the Dice Coefficient algorithm", (yargs) => {
yargs.positional("str1", {
describe: "First string",
type: "string",
});
yargs.positional("str2", {
describe: "Second string",
type: "string",
});
}, (args) => {
const result = (0, index_1.diceCoefficient)(args.str1, args.str2);
console.log(`Similarity (Dice Coefficient): ${result}`);
})
.demandCommand(1, "You need to specify a command")
.help()
.alias("help", "h")
.strict()
.parse();