@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sc-voice/tools",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "Utilities for SC-Voice",
5
5
  "main": "index.mjs",
6
6
  "files": [
@@ -93,20 +93,32 @@ export class TfidfSpace {
93
93
  return this.idfFunction(this, word, idfWeight);
94
94
  }
95
95
 
96
- addDocument(id, doc) {
96
+ addCorpusDocument(id, bow, nWords) {
97
+ const msg = 't8w.addCorpusDocument:';
97
98
  let { corpus } = this;
98
- let { bow, words } = this.countWords(doc);
99
- corpus.wordDocCount.increment(bow.oneHot());
100
-
101
- let docInfo = {
102
- bow,
103
- nWords: words.length,
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
  }