@sc-voice/tools 2.10.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 +4 -5
package/package.json
CHANGED
package/src/text/tfidf-space.mjs
CHANGED
|
@@ -93,19 +93,19 @@ 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 };
|
|
108
|
+
corpus.wordDocCount.increment(bow.oneHot());
|
|
109
109
|
corpus.addDocument(id, docInfo);
|
|
110
110
|
|
|
111
111
|
return docInfo;
|
|
@@ -114,7 +114,6 @@ export class TfidfSpace {
|
|
|
114
114
|
addDocument(id, doc) {
|
|
115
115
|
let { corpus } = this;
|
|
116
116
|
let { bow, words } = this.countWords(doc);
|
|
117
|
-
corpus.wordDocCount.increment(bow.oneHot());
|
|
118
117
|
|
|
119
118
|
return this.addCorpusDocument(id, bow, words.length);
|
|
120
119
|
}
|