BOW
Methods
cosine
Computes the cosine distance between the input bag of words (bow)
a
and b
and returns a value between 0 and 1.
Example
// bow for "the dog chased the cat"
var a = { the: 2, dog: 1, chased: 1, cat: 1 };
// bow for "the cat chased the mouse"
var b = { the: 2, cat: 1, chased: 1, mouse: 1 };
cosine( a, b );
// -> 0.14285714285714302
// Note the bow could have been created directly by
// using "tokens.bow()" from the "wink-nlp-utils".
Parameters
Name | Type | Description |
---|---|---|
a | object | the first set of bows i.e word (i.e. key) and it's frequency (i.e. value) pairs. |
b | object | the second set of bows. |
Returns
cosine distance between a
and b
.
- Type
- number