@sc-voice/tools 2.11.0 → 2.12.0
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/package.json +1 -1
- package/src/text/tfidf-space.mjs +3 -4
package/package.json
CHANGED
package/src/text/tfidf-space.mjs
CHANGED
|
@@ -93,18 +93,17 @@ export class TfidfSpace {
|
|
|
93
93
|
return this.idfFunction(this, word, idfWeight);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
addCorpusDocument(id, bow
|
|
96
|
+
addCorpusDocument(id, bow) {
|
|
97
97
|
const msg = 't8w.addCorpusDocument:';
|
|
98
98
|
let { corpus } = this;
|
|
99
99
|
if (id == null) {
|
|
100
100
|
throw new Error(`${msg} id?`);
|
|
101
101
|
}
|
|
102
102
|
if (bow == null) {
|
|
103
|
+
// Bag-of-words maps word to wordCount(word,doc)
|
|
103
104
|
throw new Error(`${msg} bow?`);
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
-
throw new Error(`${msg} nWords?`);
|
|
107
|
-
}
|
|
106
|
+
let nWords = Object.values(bow).reduce((a,v)=>a+v);
|
|
108
107
|
let docInfo = { id, bow, nWords };
|
|
109
108
|
corpus.wordDocCount.increment(bow.oneHot());
|
|
110
109
|
corpus.addDocument(id, docInfo);
|