@@ -31,6 +31,11 @@ const ContentBasedRecommender = require('content-based-recommender')
3131
3232## What's New
3333
34+ #### 1.5.0
35+
36+ * Added ` trainBidirectional(collectionA, collectionB) ` to allow recommendations between
37+ two different datasets
38+
3439#### 1.4.0
3540
3641Upgrade dependencies to fix security alerts
@@ -49,6 +54,8 @@ Update to newer version of [vector-object](https://www.npmjs.com/package/vector-
4954
5055## Usage
5156
57+ ### Single collection
58+
5259``` js
5360const ContentBasedRecommender = require (' content-based-recommender' )
5461const recommender = new ContentBasedRecommender ({
@@ -87,6 +94,115 @@ console.log(similarDocuments);
8794 ]
8895*/
8996```
97+
98+ ### Multi collection
99+
100+ This example shows how to automatically match posts with related tags
101+
102+ ``` js
103+ const ContentBasedRecommender = require (' content-based-recommender' )
104+
105+ const posts = [
106+ {
107+ id: ' 1000001' ,
108+ content: ' Why studying javascript is fun?' ,
109+ },
110+ {
111+ id: ' 1000002' ,
112+ content: ' The trend for javascript in machine learning' ,
113+ },
114+ {
115+ id: ' 1000003' ,
116+ content: ' The most insightful stories about JavaScript' ,
117+ },
118+ {
119+ id: ' 1000004' ,
120+ content: ' Introduction to Machine Learning' ,
121+ },
122+ {
123+ id: ' 1000005' ,
124+ content: ' Machine learning and its application' ,
125+ },
126+ {
127+ id: ' 1000006' ,
128+ content: ' Python vs Javascript, which is better?' ,
129+ },
130+ {
131+ id: ' 1000007' ,
132+ content: ' How Python saved my life?' ,
133+ },
134+ {
135+ id: ' 1000008' ,
136+ content: ' The future of Bitcoin technology' ,
137+ },
138+ {
139+ id: ' 1000009' ,
140+ content: ' Is it possible to use javascript for machine learning?' ,
141+ },
142+ ];
143+
144+ const tags = [
145+ {
146+ id: ' 1' ,
147+ content: ' Javascript' ,
148+ },
149+ {
150+ id: ' 2' ,
151+ content: ' machine learning' ,
152+ },
153+ {
154+ id: ' 3' ,
155+ content: ' application' ,
156+ },
157+ {
158+ id: ' 4' ,
159+ content: ' introduction' ,
160+ },
161+ {
162+ id: ' 5' ,
163+ content: ' future' ,
164+ },
165+ {
166+ id: ' 6' ,
167+ content: ' Python' ,
168+ },
169+ {
170+ id: ' 7' ,
171+ content: ' Bitcoin' ,
172+ },
173+ ];
174+
175+ const tagMap = tags .reduce ((acc , tag ) => {
176+ acc[tag .id ] = tag;
177+ return acc;
178+ }, {});
179+
180+ const recommender = new ContentBasedRecommender ();
181+
182+ recommender .trainBidirectional (posts, tags);
183+
184+ for (let post of posts) {
185+ const relatedTags = recommender .getSimilarDocuments (post .id );
186+ const tags = relatedTags .map (t => tagMap[t .id ].content );
187+ console .log (post .content , ' related tags:' , tags);
188+ }
189+
190+
191+ /*
192+ Why studying javascript is fun? related tags: [ 'Javascript' ]
193+ The trend for javascript in machine learning related tags: [ 'machine learning', 'Javascript' ]
194+ The most insightful stories about JavaScript related tags: [ 'Javascript' ]
195+ Introduction to Machine Learning related tags: [ 'machine learning', 'introduction' ]
196+ Machine learning and its application related tags: [ 'machine learning', 'application' ]
197+ Python vs Javascript, which is better? related tags: [ 'Python', 'Javascript' ]
198+ How Python saved my life? related tags: [ 'Python' ]
199+ The future of Bitcoin technology related tags: [ 'future', 'Bitcoin' ]
200+ Is it possible to use javascript for machine learning? related tags: [ 'machine learning', 'Javascript' ]
201+ */
202+
203+ ```
204+
205+
90206## API
91207
92208### constructor([ options] )
@@ -108,6 +224,12 @@ To tell the recommender about your documents and then it will start training its
108224
109225* documents - an array of object, with fields ** id** and ** content**
110226
227+
228+ ### trainBidirectional(collectionA, collectionB)
229+
230+ Works like the normal train function, but it creates recommendations
231+ between two different collections instead of within one collection.
232+
111233### getSimilarDocuments(id, [ start] , [ size] )
112234
113235To get an array of similar items with document id
0 commit comments