Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,11 @@
node_modules/
bower_components/
config.cson
build/
data/
wiki/
npm-debug.log
*.sublime-workspace
spare-parts
.DS_Store
.idea/

View File

@@ -0,0 +1,57 @@
# Change Log
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/). This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
*nothing here yet*
## [1.0.4] - 2017-03-24
Fixed:
- Fails in strict mode #7 by @gilly3
## [1.0.3] - 2016-09-26
Fixed:
- A title of this document :P
Added:
- List of contributors
- Bugs URL
- Git repository URL
## [1.0.2] - 2016-09-26
Fixed:
- Similarity 0 returned for equal strings #4 by @lzrski
## [1.0.1] - 2016-09-12
Fixed:
- Wrong results for transposition #2 by @g-adolph
Added:
- First unit test by @g-adolph
- A Change Log :) by @lzrski
## [1.0.0] - 2016-02-23
Fixed:
- Update README to match the actual output by @gilly3
## [0.1.3] - 2013-09-02
Fixed:
- Clear matrix on each call @lzrski
- Always return an object @lzrski
## [0.1.2] - 2013-08-29
Added:
- ReadMe
## [0.1.1] - 2013-08-28
Added:
- Initial working release @lzrski

View File

@@ -0,0 +1,17 @@
[![NPM](https://nodei.co/npm/damerau-levenshtein.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/damerau-levenshtein/)
I use algorithm kindly provided by TheSpanishInquisition here: <http://jsperf.com/damerau-levenshtein-distance>.
All credits goes there. I have only packed it into Node module.
It provides a function that takes two string arguments and returns a hash like this:
```` javascript
{
steps: 5, // Levenstein demerau distance
relative: 0.7, // steps / length of the longer string
similarity: 0.3 // 1 - relative
}
````
Please see [tests](./test/test.js) for more insights.

View File

@@ -0,0 +1,72 @@
// TheSpanishInquisition
// Cache the matrix. Note that if you not pass a limit this implementation will use a dynamically calculate one.
module.exports = function(__this, that, limit) {
var thisLength = __this.length,
thatLength = that.length,
matrix = [];
// If the limit is not defined it will be calculate from this and that args.
limit = (limit || ((thatLength > thisLength ? thatLength : thisLength)))+1;
for (var i = 0; i < limit; i++) {
matrix[i] = [i];
matrix[i].length = limit;
}
for (i = 0; i < limit; i++) {
matrix[0][i] = i;
}
if (Math.abs(thisLength - thatLength) > (limit || 100)){
return prepare (limit || 100);
}
if (thisLength === 0){
return prepare (thatLength);
}
if (thatLength === 0){
return prepare (thisLength);
}
// Calculate matrix.
var j, this_i, that_j, cost, min, t;
for (i = 1; i <= thisLength; ++i) {
this_i = __this[i-1];
// Step 4
for (j = 1; j <= thatLength; ++j) {
// Check the jagged ld total so far
if (i === j && matrix[i][j] > 4) return prepare (thisLength);
that_j = that[j-1];
cost = (this_i === that_j) ? 0 : 1; // Step 5
// Calculate the minimum (much faster than Math.min(...)).
min = matrix[i - 1][j ] + 1; // Deletion.
if ((t = matrix[i ][j - 1] + 1 ) < min) min = t; // Insertion.
if ((t = matrix[i - 1][j - 1] + cost) < min) min = t; // Substitution.
// Update matrix.
matrix[i][j] = (i > 1 && j > 1 && this_i === that[j-2] && __this[i-2] === that_j && (t = matrix[i-2][j-2]+cost) < min) ? t : min; // Transposition.
}
}
return prepare (matrix[thisLength][thatLength]);
/**
*
*/
function prepare(steps) {
var length = Math.max(thisLength, thatLength)
var relative = length === 0
? 0
: (steps / length);
var similarity = 1 - relative
return {
steps: steps,
relative: relative,
similarity: similarity
};
}
};

View File

@@ -0,0 +1,74 @@
{
"_args": [
[
"damerau-levenshtein@1.0.4",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "damerau-levenshtein@1.0.4",
"_id": "damerau-levenshtein@1.0.4",
"_inBundle": false,
"_integrity": "sha1-AxkcQyy27qFou3fzpV/9zLiXhRQ=",
"_location": "/react-scripts/damerau-levenshtein",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "damerau-levenshtein@1.0.4",
"name": "damerau-levenshtein",
"escapedName": "damerau-levenshtein",
"rawSpec": "1.0.4",
"saveSpec": null,
"fetchSpec": "1.0.4"
},
"_requiredBy": [
"/react-scripts/eslint-plugin-jsx-a11y"
],
"_resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.4.tgz",
"_spec": "1.0.4",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "The Spanish Inquisition"
},
"bugs": {
"url": "https://github.com/lzrski/node-damerau-levenshtein/issues"
},
"contributors": [
{
"name": "Tadeusz Łazurski",
"url": "https://www.lazurski.pl/"
},
{
"name": "Gustavo Marques Adolph"
},
{
"name": "Ivan Gilchrist",
"email": "github@jumpingfishes.com",
"url": "http://jumpingfishes.com"
}
],
"description": "Damerau - Levenshtein distance by The Spanish Inquisition + relative distance",
"devDependencies": {
"mocha": "^3.0.2"
},
"homepage": "https://github.com/lzrski/node-damerau-levenshtein#readme",
"keywords": [
"Damerau-Levenshtein",
"Damerau",
"Levenshtein",
"distance",
"compare",
"relative"
],
"license": "BSD-2-Clause",
"main": "index.js",
"name": "damerau-levenshtein",
"repository": {
"type": "git",
"url": "git+https://github.com/lzrski/node-damerau-levenshtein.git"
},
"scripts": {
"test": "mocha --use_strict"
},
"version": "1.0.4"
}

View File

@@ -0,0 +1,168 @@
var levenshtien = require("./../index");
var assert = require("assert");
describe("Damerau - Levenshtein", function() {
describe("Equality", function() {
it("returns 0 steps for equal strings", function() {
assert.deepEqual(levenshtien("test", "test"), {
steps: 0,
relative: 0,
similarity: 1
});
});
});
describe("Additions", function() {
it("returns 1 step when appending one char", function() {
assert.deepEqual(levenshtien("test", "tests"), {
steps: 1,
relative: 1 / 5,
similarity: 1 - 1 / 5
});
});
it("returns 1 step when prepending one char", function() {
assert.deepEqual(levenshtien("test", "stest"), {
steps: 1,
relative: 1 / 5,
similarity: 1 - 1 / 5
});
});
it("returns 2 steps when appending two char", function() {
assert.deepEqual(levenshtien("test", "mytest"), {
steps: 2,
relative: 2 / 6,
similarity: 1 - 2 / 6
});
});
it("returns 7 steps when appending seven char", function() {
assert.deepEqual(levenshtien("test", "mycrazytest"), {
steps: 7,
relative: 7 / 11,
similarity: 1 - 7 / 11
});
});
it("returns 9 steps when prepend two chars and append seven chars", function() {
assert.deepEqual(levenshtien("test", "mytestiscrazy"), {
steps: 9,
relative: 9 / 13,
similarity: 1 - 9 / 13
});
});
});
describe("Addition of repeated chars", function() {
it("returns 1 step when repeating a character", function() {
assert.deepEqual(levenshtien("test", "teest"), {
steps: 1,
relative: 1 / 5,
similarity: 1 - 1 / 5
});
});
it("returns 2 step when repeating a character twice", function() {
assert.deepEqual(levenshtien("test", "teeest"), {
steps: 2,
relative: 2 / 6,
similarity: 1 - 2 / 6
});
});
});
describe("#Deletion", function() {
it("returns 1 step when removing one char", function() {
assert.deepEqual(levenshtien("test", "tst"), {
steps: 1,
relative: 1 / 4,
similarity: 1 - 1 / 4
});
});
});
describe("Transposition", function() {
it("returns 1 step when transposing one char", function() {
assert.deepEqual(levenshtien("test", "tset"), {
steps: 1,
relative: 1 / 4,
similarity: 1 - 1 / 4
});
});
});
describe("Addition with transposition", function() {
it("returns 2 step when transposing one char and append another", function() {
assert.deepEqual(levenshtien("test", "tsets"), {
steps: 2,
relative: 2 / 5,
similarity: 1 - 2 / 5
});
});
it("returns 2 step when transposing a char and repeating it", function() {
assert.deepEqual(levenshtien("test", "tsset"), {
steps: 2,
relative: 2 / 5,
similarity: 1 - 2 / 5
});
});
});
describe("Transposition of multiple chars", function() {
it("returns 1 step when transposing two neighbouring characters", function() {
assert.deepEqual(levenshtien("banana", "banaan"), {
steps: 1,
relative: 1 / 6,
similarity: 1 - 1 / 6
});
});
it("returns 2 step when transposing two neighbouring characters by two places", function() {
assert.deepEqual(levenshtien("banana", "nabana"), {
steps: 2,
relative: 2 / 6,
similarity: 1 - 2 / 6
});
});
it("returns 2 step when transposing two pairs of characters", function() {
assert.deepEqual(levenshtien("banana", "abnaan"), {
steps: 2,
relative: 2 / 6,
similarity: 1 - 2 / 6
});
});
});
describe("Empty strings", function() {
it("returns 0 step and 0 relative when both are empty", function() {
assert.deepEqual(levenshtien("", ""), {
steps: 0,
relative: 0,
similarity: 1
});
});
it("returns steps equal to first string lenght when second string is empty", function() {
assert.deepEqual(levenshtien("test", ""), {
steps: 4,
relative: 4 / 4,
similarity: 0
});
});
it("returns steps equal to second string lenght when first string is empty", function() {
assert.deepEqual(levenshtien("", "test"), {
steps: 4,
relative: 1,
similarity: 0
});
});
});
});