@shaxpir/duiduidui-models 1.4.29 → 1.5.1
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.
|
@@ -15,7 +15,7 @@ export declare class BayesianScoreModel {
|
|
|
15
15
|
* Calculate uncertainty for a given Bayesian score.
|
|
16
16
|
* Higher values indicate less confidence in the theta estimate.
|
|
17
17
|
*/
|
|
18
|
-
static
|
|
18
|
+
static calculateUncertainty(alpha: number, beta: number): number;
|
|
19
19
|
/**
|
|
20
20
|
* Calculate confidence interval for theta estimate.
|
|
21
21
|
* Uses properties of the Beta distribution to estimate bounds.
|
|
@@ -21,15 +21,15 @@ class BayesianScoreModel {
|
|
|
21
21
|
nextScore.beta += (weight * 1.0);
|
|
22
22
|
}
|
|
23
23
|
nextScore.theta = nextScore.alpha / (nextScore.alpha + nextScore.beta);
|
|
24
|
-
nextScore.uncertainty = BayesianScoreModel.
|
|
24
|
+
nextScore.uncertainty = BayesianScoreModel.calculateUncertainty(nextScore.alpha, nextScore.beta);
|
|
25
25
|
return nextScore;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Calculate uncertainty for a given Bayesian score.
|
|
29
29
|
* Higher values indicate less confidence in the theta estimate.
|
|
30
30
|
*/
|
|
31
|
-
static
|
|
32
|
-
return 1 / (
|
|
31
|
+
static calculateUncertainty(alpha, beta) {
|
|
32
|
+
return 1 / (alpha + beta + 1);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Calculate confidence interval for theta estimate.
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
2
|
-
import { CompactDateTime } from "@shaxpir/shaxpir-common";
|
|
3
2
|
import { ShareSync } from '../repo';
|
|
4
|
-
import {
|
|
3
|
+
import { Bounds } from './BayesianScore';
|
|
5
4
|
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
6
|
-
export interface PhraseProgress extends BayesianScore {
|
|
7
|
-
text: string;
|
|
8
|
-
sense_rank: number;
|
|
9
|
-
difficulty: number;
|
|
10
|
-
last_review_utc?: CompactDateTime;
|
|
11
|
-
}
|
|
12
5
|
export interface UncertainValue {
|
|
13
6
|
value: number;
|
|
14
7
|
uncertainty: number;
|
|
@@ -16,7 +9,6 @@ export interface UncertainValue {
|
|
|
16
9
|
}
|
|
17
10
|
export interface ProgressPayload {
|
|
18
11
|
skill_level: UncertainValue;
|
|
19
|
-
phrases: Record<string, PhraseProgress>;
|
|
20
12
|
cognitive_load: number;
|
|
21
13
|
}
|
|
22
14
|
export interface ProgressBody extends ContentBody {
|
|
@@ -35,13 +27,10 @@ export declare class Progress extends Content {
|
|
|
35
27
|
getSkillLevelUpperBound(): number;
|
|
36
28
|
needsCalibration(): boolean;
|
|
37
29
|
getCognitiveLoad(): number;
|
|
38
|
-
getPhrases(): Record<string, PhraseProgress>;
|
|
39
30
|
setSkillLevel(uncertainValue: UncertainValue): void;
|
|
40
31
|
setSkillLevelValue(value: number): void;
|
|
41
32
|
setSkillLevelUncertainty(uncertainty: number): void;
|
|
42
33
|
setSkillLevelLowerBound(lowerBound: number): void;
|
|
43
34
|
setSkillLevelUpperBound(upperBound: number): void;
|
|
44
35
|
setCognitiveLoad(value: number): void;
|
|
45
|
-
updatePhraseProgress(phraseId: string, progress: PhraseProgress): void;
|
|
46
|
-
updateMultiplePhrases(updates: Record<string, PhraseProgress>): void;
|
|
47
36
|
}
|
package/dist/models/Progress.js
CHANGED
|
@@ -31,7 +31,6 @@ class Progress extends Content_1.Content {
|
|
|
31
31
|
upper: 1000 // Could potentially be advanced
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
-
phrases: {},
|
|
35
34
|
cognitive_load: 0
|
|
36
35
|
}
|
|
37
36
|
});
|
|
@@ -72,10 +71,6 @@ class Progress extends Content_1.Content {
|
|
|
72
71
|
this.checkDisposed("Progress.getCognitiveLoad");
|
|
73
72
|
return this.payload.cognitive_load;
|
|
74
73
|
}
|
|
75
|
-
getPhrases() {
|
|
76
|
-
this.checkDisposed("Progress.getPhrases");
|
|
77
|
-
return this.payload.phrases;
|
|
78
|
-
}
|
|
79
74
|
setSkillLevel(uncertainValue) {
|
|
80
75
|
this.checkDisposed("Progress.setSkillLevel");
|
|
81
76
|
if (!shaxpir_common_1.Struct.equals(this.payload.skill_level, uncertainValue)) {
|
|
@@ -127,19 +122,5 @@ class Progress extends Content_1.Content {
|
|
|
127
122
|
batch.commit();
|
|
128
123
|
}
|
|
129
124
|
}
|
|
130
|
-
updatePhraseProgress(phraseId, progress) {
|
|
131
|
-
this.checkDisposed("Progress.updatePhraseProgress");
|
|
132
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
133
|
-
batch.setPathValue(['payload', 'phrases', phraseId], progress);
|
|
134
|
-
batch.commit();
|
|
135
|
-
}
|
|
136
|
-
updateMultiplePhrases(updates) {
|
|
137
|
-
this.checkDisposed("Progress.updateMultiplePhrases");
|
|
138
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
139
|
-
for (const [phraseId, progress] of Object.entries(updates)) {
|
|
140
|
-
batch.setPathValue(['payload', 'phrases', phraseId], progress);
|
|
141
|
-
}
|
|
142
|
-
batch.commit();
|
|
143
|
-
}
|
|
144
125
|
}
|
|
145
126
|
exports.Progress = Progress;
|
package/dist/models/Term.d.ts
CHANGED
|
@@ -5,12 +5,33 @@ import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
|
5
5
|
import { BuiltInPhrase, Phrase, PhraseExample } from './Phrase';
|
|
6
6
|
import { ReviewLike } from "./Review";
|
|
7
7
|
import { ShareSync } from '../repo';
|
|
8
|
+
export interface TermSummary {
|
|
9
|
+
text: string;
|
|
10
|
+
sense_rank: number;
|
|
11
|
+
difficulty: number;
|
|
12
|
+
phrase_id: number | null;
|
|
13
|
+
starred_at: CompactDateTime | null;
|
|
14
|
+
alpha: number;
|
|
15
|
+
beta: number;
|
|
16
|
+
theta: number;
|
|
17
|
+
uncertainty: number;
|
|
18
|
+
review_count: number;
|
|
19
|
+
last_review_utc: CompactDateTime;
|
|
20
|
+
}
|
|
8
21
|
export interface TermPayload extends BayesianScore {
|
|
9
22
|
text: string;
|
|
10
23
|
sense_rank: number;
|
|
11
24
|
difficulty: number;
|
|
12
25
|
phrase_id: number | null;
|
|
13
26
|
starred_at: CompactDateTime | null;
|
|
27
|
+
alpha: number;
|
|
28
|
+
beta: number;
|
|
29
|
+
theta: number;
|
|
30
|
+
uncertainty: number;
|
|
31
|
+
tags: string[];
|
|
32
|
+
reviews: ReviewLike[];
|
|
33
|
+
review_count: number;
|
|
34
|
+
last_review_utc: CompactDateTime;
|
|
14
35
|
hanzi_count?: number;
|
|
15
36
|
pinyin?: string;
|
|
16
37
|
pinyin_tokenized?: string;
|
|
@@ -20,8 +41,6 @@ export interface TermPayload extends BayesianScore {
|
|
|
20
41
|
components?: PhraseExample[];
|
|
21
42
|
examples?: PhraseExample[];
|
|
22
43
|
keywords?: string[];
|
|
23
|
-
tags: string[];
|
|
24
|
-
reviews: ReviewLike[];
|
|
25
44
|
}
|
|
26
45
|
export interface TermBody extends ContentBody {
|
|
27
46
|
meta: ContentMeta;
|
|
@@ -47,4 +66,6 @@ export declare class Term extends Content {
|
|
|
47
66
|
setStarredAt(value: CompactDateTime | null): void;
|
|
48
67
|
updateBayesianScore(alpha: number, beta: number, theta: number): void;
|
|
49
68
|
addReview(review: ReviewLike): void;
|
|
69
|
+
getReviewCount(): number;
|
|
70
|
+
getLastReviewUtc(): CompactDateTime | null;
|
|
50
71
|
}
|
package/dist/models/Term.js
CHANGED
|
@@ -68,8 +68,10 @@ class Term extends Content_1.Content {
|
|
|
68
68
|
alpha: 0.5,
|
|
69
69
|
beta: 0.5,
|
|
70
70
|
theta: 0.5,
|
|
71
|
-
uncertainty: BayesianScore_1.BayesianScoreModel.
|
|
72
|
-
reviews: []
|
|
71
|
+
uncertainty: BayesianScore_1.BayesianScoreModel.calculateUncertainty(0.5, 0.5),
|
|
72
|
+
reviews: [],
|
|
73
|
+
review_count: 0,
|
|
74
|
+
last_review_utc: null
|
|
73
75
|
}
|
|
74
76
|
});
|
|
75
77
|
}
|
|
@@ -95,8 +97,10 @@ class Term extends Content_1.Content {
|
|
|
95
97
|
alpha: 0.5,
|
|
96
98
|
beta: 0.5,
|
|
97
99
|
theta: 0.5,
|
|
98
|
-
uncertainty: BayesianScore_1.BayesianScoreModel.
|
|
99
|
-
reviews: []
|
|
100
|
+
uncertainty: BayesianScore_1.BayesianScoreModel.calculateUncertainty(0.5, 0.5),
|
|
101
|
+
reviews: [],
|
|
102
|
+
review_count: 0,
|
|
103
|
+
last_review_utc: null
|
|
100
104
|
}
|
|
101
105
|
});
|
|
102
106
|
}
|
|
@@ -154,12 +158,37 @@ class Term extends Content_1.Content {
|
|
|
154
158
|
batch.setPathValue(['payload', 'alpha'], alpha);
|
|
155
159
|
batch.setPathValue(['payload', 'beta'], beta);
|
|
156
160
|
batch.setPathValue(['payload', 'theta'], theta);
|
|
157
|
-
batch.setPathValue(['payload', 'uncertainty'], BayesianScore_1.BayesianScoreModel.
|
|
161
|
+
batch.setPathValue(['payload', 'uncertainty'], BayesianScore_1.BayesianScoreModel.calculateUncertainty(alpha, beta));
|
|
158
162
|
batch.commit();
|
|
159
163
|
}
|
|
160
164
|
addReview(review) {
|
|
161
165
|
this.checkDisposed("Term.addReview");
|
|
162
166
|
this._reviewsView.push(review);
|
|
167
|
+
// Count reviews again.
|
|
168
|
+
let reviewCount = 0;
|
|
169
|
+
let lastReviewUtc = null;
|
|
170
|
+
this._reviewsView.forEach((idx, r) => {
|
|
171
|
+
// We only count *actual* reviews, not implied reviews...
|
|
172
|
+
if (!r.hasOwnProperty('context') && !r.hasOwnProperty('weight')) {
|
|
173
|
+
const reviewUtc = r.at.utc_time;
|
|
174
|
+
if (!lastReviewUtc || shaxpir_common_1.Time.isDateTimeAfter(reviewUtc, lastReviewUtc)) {
|
|
175
|
+
lastReviewUtc = reviewUtc;
|
|
176
|
+
}
|
|
177
|
+
reviewCount++;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
181
|
+
batch.setPathValue(['payload', 'review_count'], reviewCount);
|
|
182
|
+
batch.setPathValue(['payload', 'last_review_utc'], lastReviewUtc);
|
|
183
|
+
batch.commit();
|
|
184
|
+
}
|
|
185
|
+
getReviewCount() {
|
|
186
|
+
this.checkDisposed("Term.getReviewCount");
|
|
187
|
+
return this.payload.review_count;
|
|
188
|
+
}
|
|
189
|
+
getLastReviewUtc() {
|
|
190
|
+
this.checkDisposed("Term.getLastReviewUtc");
|
|
191
|
+
return this.payload.last_review_utc;
|
|
163
192
|
}
|
|
164
193
|
}
|
|
165
194
|
exports.Term = Term;
|