@sc-voice/tools 2.9.0 → 2.10.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 +20 -8
package/package.json
CHANGED
package/src/text/tfidf-space.mjs
CHANGED
|
@@ -93,20 +93,32 @@ export class TfidfSpace {
|
|
|
93
93
|
return this.idfFunction(this, word, idfWeight);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
addCorpusDocument(id, bow, nWords) {
|
|
97
|
+
const msg = 't8w.addCorpusDocument:';
|
|
97
98
|
let { corpus } = this;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
bow
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
if (id == null) {
|
|
100
|
+
throw new Error(`${msg} id?`);
|
|
101
|
+
}
|
|
102
|
+
if (bow == null) {
|
|
103
|
+
throw new Error(`${msg} bow?`);
|
|
104
|
+
}
|
|
105
|
+
if (nWords == null) {
|
|
106
|
+
throw new Error(`${msg} nWords?`);
|
|
107
|
+
}
|
|
108
|
+
let docInfo = { id, bow, nWords };
|
|
105
109
|
corpus.addDocument(id, docInfo);
|
|
106
110
|
|
|
107
111
|
return docInfo;
|
|
108
112
|
}
|
|
109
113
|
|
|
114
|
+
addDocument(id, doc) {
|
|
115
|
+
let { corpus } = this;
|
|
116
|
+
let { bow, words } = this.countWords(doc);
|
|
117
|
+
corpus.wordDocCount.increment(bow.oneHot());
|
|
118
|
+
|
|
119
|
+
return this.addCorpusDocument(id, bow, words.length);
|
|
120
|
+
}
|
|
121
|
+
|
|
110
122
|
termFrequency(word, document) {
|
|
111
123
|
return this.tf(word, document);
|
|
112
124
|
}
|