mol_text_distance 0.0.23 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -9
- package/node.d.ts +2 -2
- package/node.deps.json +1 -1
- package/node.esm.js +8 -8
- package/node.esm.js.map +1 -1
- package/node.js +8 -8
- package/node.js.map +1 -1
- package/node.test.js +17 -8
- package/node.test.js.map +1 -1
- package/package.json +3 -3
- package/web.d.ts +2 -2
- package/web.deps.json +1 -1
- package/web.esm.js +8 -8
- package/web.esm.js.map +1 -1
- package/web.js +8 -8
- package/web.js.map +1 -1
- package/web.test.js +9 -0
- package/web.test.js.map +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Calculates the lexicographical distance between two texts.
|
|
4
4
|
|
|
5
|
+
## Algorithm
|
|
6
|
+
|
|
7
|
+
- A simple and fast.
|
|
8
|
+
- Text profile based.
|
|
9
|
+
- Normalized from 0 (equal) to 1 (different).
|
|
10
|
+
- Rearrangement of words gives short distance.
|
|
11
|
+
- Different texts length support.
|
|
12
|
+
- Independent of changes position.
|
|
13
|
+
- Complexity O(n).
|
|
14
|
+
- Memory usage O(log n).
|
|
15
|
+
- For equal length texts it's a [metric](https://en.wikipedia.org/wiki/Metric_(mathematics)).
|
|
16
|
+
|
|
5
17
|
## Usage
|
|
6
18
|
|
|
7
19
|
```ts
|
|
@@ -18,15 +30,11 @@ $mol_text_distance(
|
|
|
18
30
|
)
|
|
19
31
|
```
|
|
20
32
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- Independent of texts length.
|
|
27
|
-
- Independent of changes position.
|
|
28
|
-
- Complexity O(n).
|
|
29
|
-
- Memory usage O(log n).
|
|
33
|
+
```ts
|
|
34
|
+
const profile1 = $mol_text_profile( `profile` )
|
|
35
|
+
const profile2 = $mol_text_profile( `prodir` )
|
|
36
|
+
const distance = $mol_text_profile_distance( profile1, profile2 ) // 0.54
|
|
37
|
+
```
|
|
30
38
|
|
|
31
39
|
## NPM Bundle
|
|
32
40
|
|
package/node.d.ts
CHANGED
|
@@ -14,11 +14,11 @@ declare namespace $ {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
declare namespace $ {
|
|
17
|
-
function $
|
|
17
|
+
function $mol_text_profile(text: string): Map<string, number>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
declare namespace $ {
|
|
21
|
-
function $
|
|
21
|
+
function $mol_text_profile_distance(left: Map<string, number>, right: Map<string, number>): number;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
declare namespace $ {
|
package/node.deps.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"files":["LICENSE","README.md","lang.lang.tree","mam.jam.js","mam.ts","package.json","sandbox.config.json","tsconfig.json","tsfmt.json","yarn.lock","mol/CNAME","mol/CODE_OF_CONDUCT.md","mol/CONTRIBUTING.md","mol/LICENSE","mol/index.html","mol/mol.meta.tree","mol/readme.md","mol/text/
|
|
1
|
+
{"files":["LICENSE","README.md","lang.lang.tree","mam.jam.js","mam.ts","package.json","sandbox.config.json","tsconfig.json","tsfmt.json","yarn.lock","mol/CNAME","mol/CODE_OF_CONDUCT.md","mol/CONTRIBUTING.md","mol/LICENSE","mol/index.html","mol/mol.meta.tree","mol/readme.md","mol/text/profile/profile.ts","mol/text/profile/distance/distance.ts","mol/text/distance/distance.ts","mol/text/distance/readme.md"],"mods":{},"deps_in":{"mol/text":{"mol/text/distance":-9007199254740991,"mol/text/profile":-9007199254740991},"mol":{"mol/text":-9007199254740991},"":{"mol":-9007199254740991},"mol/text/profile/distance":{"mol/text/distance":-2},"mol/text/profile":{"mol/text/profile/distance":-9007199254740991,"mol/text/distance":-3}},"deps_out":{"mol/text/distance":{"mol/text":-9007199254740991,"mol/text/profile/distance":-2,"mol/text/profile":-3},"mol/text":{"mol":-9007199254740991},"mol":{"":-9007199254740991},"mol/text/profile/distance":{"mol/text/profile":-9007199254740991},"mol/text/profile":{"mol/text":-9007199254740991}},"sloc":{"LICENSE":113,"md":503,"tree":31,"js":9,"ts":55,"json":85,"lock":994,"CNAME":1,"html":1},"deps":{"mol/text/distance":{"..":-9007199254740991,"/mol/text/distance":-1,"/mol/text/profile/distance":-2,"/mol/text/profile":-3},"mol/text":{"..":-9007199254740991},"mol":{"..":-9007199254740991},"":{},"mol/text/profile/distance":{"..":-9007199254740991,"/mol/text/profile/distance":-1},"mol/text/profile":{"..":-9007199254740991,"/mol/text/profile":-1}}}
|
package/node.esm.js
CHANGED
|
@@ -31,8 +31,8 @@ $node[ "../mam.ts" ] = $node[ "../mam.ts" ] = module.exports }.call( {} , {} )
|
|
|
31
31
|
"use strict";
|
|
32
32
|
var $;
|
|
33
33
|
(function ($) {
|
|
34
|
-
function $
|
|
35
|
-
text = '\n\n' + text + '\
|
|
34
|
+
function $mol_text_profile(text) {
|
|
35
|
+
text = '\n\n' + text + '\n\n';
|
|
36
36
|
const key = new Map();
|
|
37
37
|
for (let i = 0; i < text.length - 2; ++i) {
|
|
38
38
|
const trigram = text.slice(i, i + 3);
|
|
@@ -41,14 +41,14 @@ var $;
|
|
|
41
41
|
}
|
|
42
42
|
return key;
|
|
43
43
|
}
|
|
44
|
-
$.$
|
|
44
|
+
$.$mol_text_profile = $mol_text_profile;
|
|
45
45
|
})($ || ($ = {}));
|
|
46
|
-
//mol/text/
|
|
46
|
+
//mol/text/profile/profile.ts
|
|
47
47
|
;
|
|
48
48
|
"use strict";
|
|
49
49
|
var $;
|
|
50
50
|
(function ($) {
|
|
51
|
-
function $
|
|
51
|
+
function $mol_text_profile_distance(left, right) {
|
|
52
52
|
let dist = -4;
|
|
53
53
|
let total = -4;
|
|
54
54
|
for (const [trigram, left_count] of left) {
|
|
@@ -65,15 +65,15 @@ var $;
|
|
|
65
65
|
return 0;
|
|
66
66
|
return dist / total;
|
|
67
67
|
}
|
|
68
|
-
$.$
|
|
68
|
+
$.$mol_text_profile_distance = $mol_text_profile_distance;
|
|
69
69
|
})($ || ($ = {}));
|
|
70
|
-
//mol/text/
|
|
70
|
+
//mol/text/profile/distance/distance.ts
|
|
71
71
|
;
|
|
72
72
|
"use strict";
|
|
73
73
|
var $;
|
|
74
74
|
(function ($) {
|
|
75
75
|
function $mol_text_distance(left, right) {
|
|
76
|
-
return $
|
|
76
|
+
return $mol_text_profile_distance($mol_text_profile(left), $mol_text_profile(right));
|
|
77
77
|
}
|
|
78
78
|
$.$mol_text_distance = $mol_text_distance;
|
|
79
79
|
})($ || ($ = {}));
|
package/node.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../mam.jam.js","-","../../../../mam.ts","../../
|
|
1
|
+
{"version":3,"sources":["../../../../mam.jam.js","-","../../../../mam.ts","../../profile/mol/text/profile/profile.ts","../../profile/distance/mol/text/profile/distance/distance.ts","../mol/text/distance/distance.ts"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACZA;AACA;AACA;AACA;;ACHA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAMV;AAND,WAAU,CAAC;AAMX,CAAC,EANS,CAAC,KAAD,CAAC,QAMV;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;;;ADblB;AACA;AACA;;AEFA,IAAU,CAAC,CAaV;AAbD,WAAU,CAAC;IAEV,SAAgB,iBAAiB,CAAE,IAAY;QAC9C,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;QAC7B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAoB,CAAA;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,EAAG,CAAC,EAAG;YAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAE,CAAA;YACtC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAE,OAAO,CAAE,IAAI,CAAC,CAAA;YACrC,GAAG,CAAC,GAAG,CAAE,OAAO,EAAE,KAAK,GAAG,CAAC,CAAE,CAAA;SAC7B;QACD,OAAO,GAAG,CAAA;IACX,CAAC;IATe,mBAAiB,oBAShC,CAAA;AAEF,CAAC,EAbS,CAAC,KAAD,CAAC,QAaV;;;;ACbD,IAAU,CAAC,CA2BV;AA3BD,WAAU,CAAC;IAEV,SAAgB,0BAA0B,CACzC,IAA2B,EAC3B,KAA4B;QAG5B,IAAI,IAAI,GAAG,CAAC,CAAC,CAAA;QACb,IAAI,KAAK,GAAG,CAAC,CAAC,CAAA;QAEd,KAAK,MAAM,CAAE,OAAO,EAAE,UAAU,CAAE,IAAI,IAAI,EAAG;YAC5C,KAAK,IAAI,UAAU,CAAA;YACnB,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAE,OAAO,CAAE,IAAI,CAAC,CAAA;YAC7C,IAAI,IAAI,IAAI,CAAC,GAAG,CAAE,UAAU,GAAG,WAAW,CAAE,CAAA;SAC5C;QAED,KAAK,MAAM,CAAE,OAAO,EAAE,WAAW,CAAE,IAAI,KAAK,EAAG;YAC9C,KAAK,IAAI,WAAW,CAAA;YACpB,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAE,OAAO,CAAE,IAAI,CAAC,CAAA;YAC3C,IAAI,IAAI,IAAI,CAAC,GAAG,CAAE,UAAU,GAAG,WAAW,CAAE,CAAA;SAC5C;QAED,IAAI,IAAI,GAAG,CAAC;YAAG,OAAO,CAAC,CAAA;QAEvB,OAAO,IAAI,GAAG,KAAK,CAAA;IACpB,CAAC;IAvBe,4BAA0B,6BAuBzC,CAAA;AAEF,CAAC,EA3BS,CAAC,KAAD,CAAC,QA2BV;;;;AC3BD,IAAU,CAAC,CAYV;AAZD,WAAU,CAAC;IAEV,SAAgB,kBAAkB,CACjC,IAAY,EACZ,KAAa;QAEb,OAAO,0BAA0B,CAChC,iBAAiB,CAAE,IAAI,CAAE,EACzB,iBAAiB,CAAE,KAAK,CAAE,CAC1B,CAAA;IACF,CAAC;IARe,oBAAkB,qBAQjC,CAAA;AAEF,CAAC,EAZS,CAAC,KAAD,CAAC,QAYV;;;AJZD","file":"node.esm.js","sourcesContent":[null,null,"Error.stackTraceLimit = 50;\n\ndeclare let _$_: { new(): {} } & typeof globalThis\ndeclare class $ extends _$_ {}\n\nnamespace $ {\n\texport type $ = typeof $$\n\texport declare class $$ extends $ {}\n\tnamespace $$ {\n\t\texport type $$ = $\n\t}\n}\n\nmodule.exports = $\n","namespace $ {\n\t\n\texport function $mol_text_profile( text: string ) {\n\t\ttext = '\\n\\n' + text + '\\n\\n'\n\t\tconst key = new Map< string, number >()\n\t\tfor( let i = 0; i < text.length - 2; ++ i ) {\n\t\t\tconst trigram = text.slice( i, i + 3 )\n\t\t\tconst count = key.get( trigram ) ?? 0\n\t\t\tkey.set( trigram, count + 1 )\n\t\t}\n\t\treturn key\n\t}\n\t\n}\n","namespace $ {\n\t\n\texport function $mol_text_profile_distance(\n\t\tleft: Map< string, number >,\n\t\tright: Map< string, number >,\n\t) {\n\t\t\n\t\tlet dist = -4\n\t\tlet total = -4\n\t\t\n\t\tfor( const [ trigram, left_count ] of left ) {\n\t\t\ttotal += left_count\n\t\t\tconst right_count = right.get( trigram ) ?? 0\n\t\t\tdist += Math.abs( left_count - right_count )\n\t\t}\n\t\t\n\t\tfor( const [ trigram, right_count ] of right ) {\n\t\t\ttotal += right_count\n\t\t\tconst left_count = left.get( trigram ) ?? 0\n\t\t\tdist += Math.abs( left_count - right_count )\n\t\t}\n\t\t\n\t\tif( dist < 0 ) return 0\n\t\t\n\t\treturn dist / total\n\t}\n\t\n}\n","namespace $ {\n\t\n\texport function $mol_text_distance(\n\t\tleft: string,\n\t\tright: string,\n\t) {\n\t\treturn $mol_text_profile_distance(\n\t\t\t$mol_text_profile( left ),\n\t\t\t$mol_text_profile( right ),\n\t\t)\n\t}\n\t\n}\n"]}
|
package/node.js
CHANGED
|
@@ -31,8 +31,8 @@ $node[ "../mam.ts" ] = $node[ "../mam.ts" ] = module.exports }.call( {} , {} )
|
|
|
31
31
|
"use strict";
|
|
32
32
|
var $;
|
|
33
33
|
(function ($) {
|
|
34
|
-
function $
|
|
35
|
-
text = '\n\n' + text + '\
|
|
34
|
+
function $mol_text_profile(text) {
|
|
35
|
+
text = '\n\n' + text + '\n\n';
|
|
36
36
|
const key = new Map();
|
|
37
37
|
for (let i = 0; i < text.length - 2; ++i) {
|
|
38
38
|
const trigram = text.slice(i, i + 3);
|
|
@@ -41,14 +41,14 @@ var $;
|
|
|
41
41
|
}
|
|
42
42
|
return key;
|
|
43
43
|
}
|
|
44
|
-
$.$
|
|
44
|
+
$.$mol_text_profile = $mol_text_profile;
|
|
45
45
|
})($ || ($ = {}));
|
|
46
|
-
//mol/text/
|
|
46
|
+
//mol/text/profile/profile.ts
|
|
47
47
|
;
|
|
48
48
|
"use strict";
|
|
49
49
|
var $;
|
|
50
50
|
(function ($) {
|
|
51
|
-
function $
|
|
51
|
+
function $mol_text_profile_distance(left, right) {
|
|
52
52
|
let dist = -4;
|
|
53
53
|
let total = -4;
|
|
54
54
|
for (const [trigram, left_count] of left) {
|
|
@@ -65,15 +65,15 @@ var $;
|
|
|
65
65
|
return 0;
|
|
66
66
|
return dist / total;
|
|
67
67
|
}
|
|
68
|
-
$.$
|
|
68
|
+
$.$mol_text_profile_distance = $mol_text_profile_distance;
|
|
69
69
|
})($ || ($ = {}));
|
|
70
|
-
//mol/text/
|
|
70
|
+
//mol/text/profile/distance/distance.ts
|
|
71
71
|
;
|
|
72
72
|
"use strict";
|
|
73
73
|
var $;
|
|
74
74
|
(function ($) {
|
|
75
75
|
function $mol_text_distance(left, right) {
|
|
76
|
-
return $
|
|
76
|
+
return $mol_text_profile_distance($mol_text_profile(left), $mol_text_profile(right));
|
|
77
77
|
}
|
|
78
78
|
$.$mol_text_distance = $mol_text_distance;
|
|
79
79
|
})($ || ($ = {}));
|
package/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../mam.jam.js","-","../../../../mam.ts","../../
|
|
1
|
+
{"version":3,"sources":["../../../../mam.jam.js","-","../../../../mam.ts","../../profile/mol/text/profile/profile.ts","../../profile/distance/mol/text/profile/distance/distance.ts","../mol/text/distance/distance.ts"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACZA;AACA;AACA;AACA;;ACHA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAMV;AAND,WAAU,CAAC;AAMX,CAAC,EANS,CAAC,KAAD,CAAC,QAMV;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;;;ADblB;AACA;AACA;;AEFA,IAAU,CAAC,CAaV;AAbD,WAAU,CAAC;IAEV,SAAgB,iBAAiB,CAAE,IAAY;QAC9C,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;QAC7B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAoB,CAAA;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,EAAG,CAAC,EAAG;YAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAE,CAAA;YACtC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAE,OAAO,CAAE,IAAI,CAAC,CAAA;YACrC,GAAG,CAAC,GAAG,CAAE,OAAO,EAAE,KAAK,GAAG,CAAC,CAAE,CAAA;SAC7B;QACD,OAAO,GAAG,CAAA;IACX,CAAC;IATe,mBAAiB,oBAShC,CAAA;AAEF,CAAC,EAbS,CAAC,KAAD,CAAC,QAaV;;;;ACbD,IAAU,CAAC,CA2BV;AA3BD,WAAU,CAAC;IAEV,SAAgB,0BAA0B,CACzC,IAA2B,EAC3B,KAA4B;QAG5B,IAAI,IAAI,GAAG,CAAC,CAAC,CAAA;QACb,IAAI,KAAK,GAAG,CAAC,CAAC,CAAA;QAEd,KAAK,MAAM,CAAE,OAAO,EAAE,UAAU,CAAE,IAAI,IAAI,EAAG;YAC5C,KAAK,IAAI,UAAU,CAAA;YACnB,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAE,OAAO,CAAE,IAAI,CAAC,CAAA;YAC7C,IAAI,IAAI,IAAI,CAAC,GAAG,CAAE,UAAU,GAAG,WAAW,CAAE,CAAA;SAC5C;QAED,KAAK,MAAM,CAAE,OAAO,EAAE,WAAW,CAAE,IAAI,KAAK,EAAG;YAC9C,KAAK,IAAI,WAAW,CAAA;YACpB,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAE,OAAO,CAAE,IAAI,CAAC,CAAA;YAC3C,IAAI,IAAI,IAAI,CAAC,GAAG,CAAE,UAAU,GAAG,WAAW,CAAE,CAAA;SAC5C;QAED,IAAI,IAAI,GAAG,CAAC;YAAG,OAAO,CAAC,CAAA;QAEvB,OAAO,IAAI,GAAG,KAAK,CAAA;IACpB,CAAC;IAvBe,4BAA0B,6BAuBzC,CAAA;AAEF,CAAC,EA3BS,CAAC,KAAD,CAAC,QA2BV;;;;AC3BD,IAAU,CAAC,CAYV;AAZD,WAAU,CAAC;IAEV,SAAgB,kBAAkB,CACjC,IAAY,EACZ,KAAa;QAEb,OAAO,0BAA0B,CAChC,iBAAiB,CAAE,IAAI,CAAE,EACzB,iBAAiB,CAAE,KAAK,CAAE,CAC1B,CAAA;IACF,CAAC;IARe,oBAAkB,qBAQjC,CAAA;AAEF,CAAC,EAZS,CAAC,KAAD,CAAC,QAYV;;","file":"node.js","sourcesContent":[null,null,"Error.stackTraceLimit = 50;\n\ndeclare let _$_: { new(): {} } & typeof globalThis\ndeclare class $ extends _$_ {}\n\nnamespace $ {\n\texport type $ = typeof $$\n\texport declare class $$ extends $ {}\n\tnamespace $$ {\n\t\texport type $$ = $\n\t}\n}\n\nmodule.exports = $\n","namespace $ {\n\t\n\texport function $mol_text_profile( text: string ) {\n\t\ttext = '\\n\\n' + text + '\\n\\n'\n\t\tconst key = new Map< string, number >()\n\t\tfor( let i = 0; i < text.length - 2; ++ i ) {\n\t\t\tconst trigram = text.slice( i, i + 3 )\n\t\t\tconst count = key.get( trigram ) ?? 0\n\t\t\tkey.set( trigram, count + 1 )\n\t\t}\n\t\treturn key\n\t}\n\t\n}\n","namespace $ {\n\t\n\texport function $mol_text_profile_distance(\n\t\tleft: Map< string, number >,\n\t\tright: Map< string, number >,\n\t) {\n\t\t\n\t\tlet dist = -4\n\t\tlet total = -4\n\t\t\n\t\tfor( const [ trigram, left_count ] of left ) {\n\t\t\ttotal += left_count\n\t\t\tconst right_count = right.get( trigram ) ?? 0\n\t\t\tdist += Math.abs( left_count - right_count )\n\t\t}\n\t\t\n\t\tfor( const [ trigram, right_count ] of right ) {\n\t\t\ttotal += right_count\n\t\t\tconst left_count = left.get( trigram ) ?? 0\n\t\t\tdist += Math.abs( left_count - right_count )\n\t\t}\n\t\t\n\t\tif( dist < 0 ) return 0\n\t\t\n\t\treturn dist / total\n\t}\n\t\n}\n","namespace $ {\n\t\n\texport function $mol_text_distance(\n\t\tleft: string,\n\t\tright: string,\n\t) {\n\t\treturn $mol_text_profile_distance(\n\t\t\t$mol_text_profile( left ),\n\t\t\t$mol_text_profile( right ),\n\t\t)\n\t}\n\t\n}\n"]}
|
package/node.test.js
CHANGED
|
@@ -23,8 +23,8 @@ module.exports = $;
|
|
|
23
23
|
"use strict";
|
|
24
24
|
var $;
|
|
25
25
|
(function ($) {
|
|
26
|
-
function $
|
|
27
|
-
text = '\n\n' + text + '\
|
|
26
|
+
function $mol_text_profile(text) {
|
|
27
|
+
text = '\n\n' + text + '\n\n';
|
|
28
28
|
const key = new Map();
|
|
29
29
|
for (let i = 0; i < text.length - 2; ++i) {
|
|
30
30
|
const trigram = text.slice(i, i + 3);
|
|
@@ -33,14 +33,14 @@ var $;
|
|
|
33
33
|
}
|
|
34
34
|
return key;
|
|
35
35
|
}
|
|
36
|
-
$.$
|
|
36
|
+
$.$mol_text_profile = $mol_text_profile;
|
|
37
37
|
})($ || ($ = {}));
|
|
38
|
-
//mol/text/
|
|
38
|
+
//mol/text/profile/profile.ts
|
|
39
39
|
;
|
|
40
40
|
"use strict";
|
|
41
41
|
var $;
|
|
42
42
|
(function ($) {
|
|
43
|
-
function $
|
|
43
|
+
function $mol_text_profile_distance(left, right) {
|
|
44
44
|
let dist = -4;
|
|
45
45
|
let total = -4;
|
|
46
46
|
for (const [trigram, left_count] of left) {
|
|
@@ -57,15 +57,15 @@ var $;
|
|
|
57
57
|
return 0;
|
|
58
58
|
return dist / total;
|
|
59
59
|
}
|
|
60
|
-
$.$
|
|
60
|
+
$.$mol_text_profile_distance = $mol_text_profile_distance;
|
|
61
61
|
})($ || ($ = {}));
|
|
62
|
-
//mol/text/
|
|
62
|
+
//mol/text/profile/distance/distance.ts
|
|
63
63
|
;
|
|
64
64
|
"use strict";
|
|
65
65
|
var $;
|
|
66
66
|
(function ($) {
|
|
67
67
|
function $mol_text_distance(left, right) {
|
|
68
|
-
return $
|
|
68
|
+
return $mol_text_profile_distance($mol_text_profile(left), $mol_text_profile(right));
|
|
69
69
|
}
|
|
70
70
|
$.$mol_text_distance = $mol_text_distance;
|
|
71
71
|
})($ || ($ = {}));
|
|
@@ -1729,6 +1729,15 @@ var $;
|
|
|
1729
1729
|
'Real different text'() {
|
|
1730
1730
|
$mol_assert_equal($mol_text_distance(`A structural comparison of arbitrary objects is discussed.`, `Application of caching for correct comparison of cyclic references is disclosed.`), .6594202898550725);
|
|
1731
1731
|
},
|
|
1732
|
+
'Simmetry'() {
|
|
1733
|
+
$mol_assert_equal($mol_text_distance(`booklet`, `handbook`), $mol_text_distance(`handbook`, `booklet`));
|
|
1734
|
+
},
|
|
1735
|
+
'Triangle inequality'() {
|
|
1736
|
+
const A = $mol_text_distance(`metric`, `123ric`);
|
|
1737
|
+
const B = $mol_text_distance(`123ric`, `123456`);
|
|
1738
|
+
const C = $mol_text_distance(`metric`, `123456`);
|
|
1739
|
+
$mol_assert_ok(A + B >= C);
|
|
1740
|
+
},
|
|
1732
1741
|
});
|
|
1733
1742
|
})($ || ($ = {}));
|
|
1734
1743
|
//mol/text/distance/distance.test.ts
|