@bendyline/gilde 0.3.16 → 0.3.17
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/authoring/chat-models/inkling2-mini-26b-nvfp4.json +26 -0
- package/authoring/chat-models/spark-x2.6-4b-q4.json +26 -0
- package/data/chat-models/in/inkling2-mini-26b-nvfp4/manifest.json +26 -0
- package/data/chat-models/index.json +1 -1
- package/data/chat-models/raw-index.json +1 -1
- package/data/chat-models/sp/spark-x2.6-4b-q4/manifest.json +26 -0
- package/data/project-types/fl/flashcards/versions/1.3.1/about.md +8 -0
- package/data/project-types/fl/flashcards/versions/1.3.1/deck.json +7 -0
- package/data/project-types/fl/flashcards/versions/1.3.1/manifest.json +243 -0
- package/data/project-types/fl/flashcards/versions/1.3.1/mission.md +6 -0
- package/data/project-types/fl/flashcards/versions/1.3.1/pages/review/application.js +147 -0
- package/data/project-types/fl/flashcards/versions/1.3.1/pages/review/demo-chat.js +331 -0
- package/data/project-types/fl/flashcards/versions/1.3.1/pages/review/index.html +665 -0
- package/data/project-types/index.json +1 -1
- package/data/project-types/qu/quotes-and-bids/versions/1.1.1/about.md +15 -0
- package/data/project-types/qu/quotes-and-bids/versions/1.1.1/manifest.json +639 -0
- package/data/project-types/qu/quotes-and-bids/versions/1.1.1/mission.md +3 -0
- package/data/project-types/qu/quotes-and-bids/versions/1.1.1/pages/quotes/application.js +386 -0
- package/data/project-types/qu/quotes-and-bids/versions/1.1.1/pages/quotes/demo-chat.js +263 -0
- package/data/project-types/qu/quotes-and-bids/versions/1.1.1/pages/quotes/index.html +998 -0
- package/data/project-types/qu/quotes-and-bids/versions/1.1.1/quotes.json +10 -0
- package/data/project-types/qu/quotes-and-bids/versions/1.1.1/rates.json +8 -0
- package/data/project-types/raw-index.json +1 -1
- package/package.json +1 -1
- package/schemas/craftbook-doc.schema.json +21 -0
- package/schemas/craftbook-template-version.schema.json +21 -0
- package/schemas/craftbook-test.schema.json +1 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// The standalone demo's sample conversation. In Gezel, the study partner's
|
|
2
|
+
// replies come from the model the person chooses; here they are scripted, and
|
|
3
|
+
// every new card goes through the same add_cards tool the live crew member calls.
|
|
4
|
+
window.demoChat = (function () {
|
|
5
|
+
'use strict';
|
|
6
|
+
var SESSION_MS = 15 * 60 * 1000;
|
|
7
|
+
var POOLS = {
|
|
8
|
+
market: [
|
|
9
|
+
['Ik wil graag een kilo appels.', 'I would like a kilo of apples.'],
|
|
10
|
+
['Heeft u ook aardbeien?', 'Do you also have strawberries?'],
|
|
11
|
+
['Wat is de prijs per stuk?', 'What is the price per piece?'],
|
|
12
|
+
['Twee zakjes, alstublieft.', 'Two bags, please.'],
|
|
13
|
+
['Mag ik even proeven?', 'May I have a taste?'],
|
|
14
|
+
['Is dit vers?', 'Is this fresh?'],
|
|
15
|
+
['Ik kijk alleen even.', 'I am just looking.'],
|
|
16
|
+
],
|
|
17
|
+
numbers: [
|
|
18
|
+
['twee euro vijftig', 'two euros fifty (2.50 euros)'],
|
|
19
|
+
['een tientje', 'a ten-euro note'],
|
|
20
|
+
['de helft', 'half'],
|
|
21
|
+
['een pond', 'half a kilo (500 grams)'],
|
|
22
|
+
['goedkoop', 'cheap'],
|
|
23
|
+
['duur', 'expensive'],
|
|
24
|
+
],
|
|
25
|
+
produce: [
|
|
26
|
+
['de aardbei', 'the strawberry'],
|
|
27
|
+
['de peer', 'the pear'],
|
|
28
|
+
['de prei', 'the leek'],
|
|
29
|
+
['de ui', 'the onion'],
|
|
30
|
+
['de kaas', 'the cheese'],
|
|
31
|
+
['het brood', 'the bread'],
|
|
32
|
+
],
|
|
33
|
+
greetings: [
|
|
34
|
+
['Fijne dag nog!', 'Have a nice day!'],
|
|
35
|
+
['Tot ziens!', 'Goodbye!'],
|
|
36
|
+
['Alstublieft', 'Please, or here you go'],
|
|
37
|
+
['Graag gedaan', 'You are welcome'],
|
|
38
|
+
['Goedemiddag!', 'Good afternoon!'],
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
var TOPIC_NAMES = { market: 'market phrases', numbers: 'price and number words', produce: 'produce words', greetings: 'greetings' };
|
|
42
|
+
var NOTES = {
|
|
43
|
+
'een bos bloemen': '**Een bos bloemen** is “a bunch of flowers.” **Bos** means a bunch or bundle (it also means a forest), and **bloemen** is the plural of **bloem**, flower. You’ll hear it at every flower stall: “Een bos tulpen, alstublieft.”',
|
|
44
|
+
'mag ik pinnen?': '**Mag ik pinnen?** is “Can I pay by card?” **Pinnen** comes from the PIN you type, so it’s the everyday verb for paying by debit card. If the seller says “alleen contant,” it’s cash only.',
|
|
45
|
+
'hoeveel kost dit?': '**Hoeveel kost dit?** is “How much does this cost?” **Hoeveel** is “how much,” **kost** is “costs,” and **dit** is “this.” Point at the thing and you’re set.',
|
|
46
|
+
'dat is alles, dank u.': '**Dat is alles, dank u.** is “That is all, thank you.” **Dank u** is the polite thank-you; with friends it’s **dank je**.',
|
|
47
|
+
'contant': '**Contant** means cash. Ask “Kan ik contant betalen?” to check whether a stall takes it.',
|
|
48
|
+
'een halve kilo': '**Een halve kilo** is half a kilo. **Halve** takes an -e because it sits before a noun, and many stalls simply call it **een pond**.',
|
|
49
|
+
'de markt': '**De markt** is the market. Most towns hold one each week, often on a square that is itself called the Markt.',
|
|
50
|
+
'goedemorgen!': '**Goedemorgen!** is “Good morning!” Use it until about noon; after that it’s **goedemiddag**.',
|
|
51
|
+
};
|
|
52
|
+
var BASE = ['How am I doing?', 'Add five more market phrases', 'Explain the one I keep missing', 'Quiz me on one'];
|
|
53
|
+
var quiz = null;
|
|
54
|
+
var quizzes = 0;
|
|
55
|
+
var lastQuiz = null;
|
|
56
|
+
var offer = null;
|
|
57
|
+
|
|
58
|
+
// The suggestion keys: the standing ones, an open offer, and what fits this moment.
|
|
59
|
+
function keys(extra) { return BASE.concat(offer ? [offer] : [], extra || []); }
|
|
60
|
+
|
|
61
|
+
function deck(ctx) { return ctx.read('deck.json'); }
|
|
62
|
+
function plural(n, word) { return n + ' ' + word + (n === 1 ? '' : 's'); }
|
|
63
|
+
// A card's answer in bold, ending the sentence without doubling its own punctuation.
|
|
64
|
+
function said(text) { return '**' + text + '**' + (/[.!?]$/.test(text) ? '' : '.'); }
|
|
65
|
+
function norm(text) { return String(text || '').toLowerCase().replace(/[“”"'’.,!?¿¡()]/g, ' ').replace(/\s+/g, ' ').trim(); }
|
|
66
|
+
function byId(d, id) { return d.cards.find(function (c) { return c.id === id; }) || null; }
|
|
67
|
+
function language(d) {
|
|
68
|
+
var match = /\b(Dutch|Spanish|French|German|Italian|Portuguese|Japanese)\b/i.exec(d.subject || '');
|
|
69
|
+
return match ? match[1].charAt(0).toUpperCase() + match[1].slice(1).toLowerCase() : '';
|
|
70
|
+
}
|
|
71
|
+
function hardest(d) {
|
|
72
|
+
return d.cards
|
|
73
|
+
.filter(function (c) { return c.stats && c.stats.missed > 0; })
|
|
74
|
+
.sort(function (a, b) { return b.stats.missed - a.stats.missed || a.box - b.box; });
|
|
75
|
+
}
|
|
76
|
+
function reviewedLately(d) {
|
|
77
|
+
var since = Date.now() - SESSION_MS;
|
|
78
|
+
return d.cards.filter(function (c) { return c.lastReviewedAt && Date.parse(c.lastReviewedAt) >= since; });
|
|
79
|
+
}
|
|
80
|
+
function named(d, text) {
|
|
81
|
+
var lower = norm(text);
|
|
82
|
+
return d.cards.find(function (c) { return norm(c.front).length > 2 && lower.indexOf(norm(c.front)) >= 0; }) ||
|
|
83
|
+
d.cards.find(function (c) { return norm(c.back).length > 3 && lower.indexOf(norm(c.back)) >= 0; }) || null;
|
|
84
|
+
}
|
|
85
|
+
function ask(card) {
|
|
86
|
+
return /^(what|who|when|where|why|how|which|fill in)\b/i.test(card.front)
|
|
87
|
+
? '**' + card.front + '**'
|
|
88
|
+
: 'what does **' + card.front + '** mean?';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function progress(ctx) {
|
|
92
|
+
return ctx.invoke('deck_status', {}, 'Boxes and due cards').then(function () { return deck(ctx); }).then(function (d) {
|
|
93
|
+
if (!d.cards.length) return 'The deck is empty. Ask me for a few cards and we’ll start there.';
|
|
94
|
+
var boxes = [0, 0, 0, 0];
|
|
95
|
+
d.cards.forEach(function (c) { boxes[c.box] += 1; });
|
|
96
|
+
var lines = [
|
|
97
|
+
'**' + plural(d.cards.length, 'card') + '** on ' + d.subject + ', and ' + d.dueCardIds.length + ' due now. ' +
|
|
98
|
+
boxes[3] + ' sit on the weekly shelf, ' + boxes[2] + ' come back every three days, and ' + boxes[1] + ' come back daily.',
|
|
99
|
+
];
|
|
100
|
+
var tough = hardest(d)[0];
|
|
101
|
+
if (tough) {
|
|
102
|
+
lines.push('The one that keeps slipping is **' + tough.front + '** (missed ' + plural(tough.stats.missed, 'time') + '). ' +
|
|
103
|
+
(d.dueCardIds.indexOf(tough.id) >= 0 ? 'It’s due today, which is exactly right.' : 'It isn’t due yet; it comes back on schedule.'));
|
|
104
|
+
}
|
|
105
|
+
var lately = reviewedLately(d);
|
|
106
|
+
if (lately.length) {
|
|
107
|
+
var up = lately.filter(function (c) { return c.box > 1; }).length;
|
|
108
|
+
lines.push('Today you reviewed ' + plural(lately.length, 'card') + ', and ' + up + ' of them moved up a box.');
|
|
109
|
+
}
|
|
110
|
+
return lines;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function addTopic(ctx, text) {
|
|
115
|
+
var lower = text.toLowerCase();
|
|
116
|
+
var topic = /\b(number|numbers|price|prices|money|euro|euros|cost)\b/.test(lower) ? 'numbers'
|
|
117
|
+
: /\b(fruit|vegetables?|produce|food|cheese|bread)\b/.test(lower) ? 'produce'
|
|
118
|
+
: /\b(greet\w*|polite|hello|goodbye|please|thanks?|manners)\b/.test(lower) ? 'greetings' : 'market';
|
|
119
|
+
var words = { one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8 };
|
|
120
|
+
var asked = /\b(\d+|one|two|three|four|five|six|seven|eight)\b/.exec(lower);
|
|
121
|
+
var count = Math.min(8, Math.max(1, asked ? Number(words[asked[1]] || asked[1]) : 5));
|
|
122
|
+
return deck(ctx).then(function (d) {
|
|
123
|
+
var have = d.cards.map(function (c) { return norm(c.front); });
|
|
124
|
+
var fresh = POOLS[topic].filter(function (pair) { return have.indexOf(norm(pair[0])) < 0; }).slice(0, count);
|
|
125
|
+
if (!fresh.length) {
|
|
126
|
+
return 'Every one of my ' + TOPIC_NAMES[topic] + ' is already in your deck. Try asking for greetings, produce, or price words.';
|
|
127
|
+
}
|
|
128
|
+
var cards = fresh.map(function (pair) { return { front: pair[0], back: pair[1] }; });
|
|
129
|
+
return ctx.invoke('add_cards', { cards: cards }, plural(cards.length, TOPIC_NAMES[topic].replace(/s$/, ''))).then(function (out) {
|
|
130
|
+
return out.summary;
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function explain(ctx, text) {
|
|
136
|
+
return deck(ctx).then(function (d) {
|
|
137
|
+
if (!d.cards.length) return 'There’s nothing in the deck to explain yet. Ask me for a few cards first.';
|
|
138
|
+
var card = named(d, text) || hardest(d)[0] || byId(d, d.dueCardIds[0]) || d.cards[0];
|
|
139
|
+
var note = NOTES[card.front.toLowerCase()];
|
|
140
|
+
var missed = card.stats && card.stats.missed;
|
|
141
|
+
var lead = !named(d, text) && missed ? 'That’s **' + card.front + '**, missed ' + plural(missed, 'time') + ' so far. ' : '';
|
|
142
|
+
return lead + (note || '**' + card.front + '** goes with ' + said(card.back) + ' I don’t have more notes on that one in this sample.') +
|
|
143
|
+
(missed && !named(d, text) ? ' Want a couple of practice cards on it from a new angle?' : '');
|
|
144
|
+
}).then(function (reply) {
|
|
145
|
+
if (/practice cards/.test(reply)) offer = 'Yes, add practice cards for it';
|
|
146
|
+
return { reply: reply, suggestions: keys() };
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function angleCards(ctx) {
|
|
151
|
+
offer = null;
|
|
152
|
+
return deck(ctx).then(function (d) {
|
|
153
|
+
var lately = reviewedLately(d).filter(function (c) { return c.box === 1 && c.stats.missed > 0; });
|
|
154
|
+
var targets = (lately.length ? lately : hardest(d).slice(0, 1)).slice(0, 2);
|
|
155
|
+
if (!targets.length) return 'Nothing has slipped yet, so there’s nothing to come at from a new angle. Ask me for new cards instead.';
|
|
156
|
+
var lang = language(d);
|
|
157
|
+
var have = d.cards.map(function (c) { return norm(c.front); });
|
|
158
|
+
var cards = [];
|
|
159
|
+
targets.forEach(function (card) {
|
|
160
|
+
cards.push({
|
|
161
|
+
front: lang ? 'How do you say “' + card.back + '” in ' + lang + '?' : 'What goes with “' + card.back + '”?',
|
|
162
|
+
back: card.front,
|
|
163
|
+
});
|
|
164
|
+
var words = card.front.replace(/[.!?]+$/, '').split(/\s+/);
|
|
165
|
+
if (words.length > 1) {
|
|
166
|
+
var pick = words
|
|
167
|
+
.map(function (w) { return w.replace(/[^\p{L}’'-]/gu, ''); })
|
|
168
|
+
.reduce(function (best, w) { return w.length > best.length ? w : best; }, '');
|
|
169
|
+
cards.push({ front: 'Fill in the blank: ' + card.front.replace(pick, '___'), back: pick });
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
cards = cards.filter(function (c) { return have.indexOf(norm(c.front)) < 0; });
|
|
173
|
+
if (!cards.length) return 'Those practice cards are already in your deck. They’ll come up in your next review.';
|
|
174
|
+
var names = targets.map(function (c) { return c.front; }).join(' and ');
|
|
175
|
+
return ctx.invoke('add_cards', { cards: cards }, plural(cards.length, 'practice card') + ' for ' + names).then(function (out) {
|
|
176
|
+
return out.summary;
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function startQuiz(ctx) {
|
|
182
|
+
return deck(ctx).then(function (d) {
|
|
183
|
+
if (!d.cards.length) return 'The deck is empty, so there’s nothing to quiz yet. Ask me for a few cards first.';
|
|
184
|
+
var pool = d.dueCardIds.map(function (id) { return byId(d, id); }).filter(Boolean);
|
|
185
|
+
if (!pool.length) pool = d.cards.slice();
|
|
186
|
+
var card = pool.find(function (c) { return c.id !== lastQuiz; }) || pool[0];
|
|
187
|
+
quiz = { id: card.id, front: card.front, back: card.back };
|
|
188
|
+
lastQuiz = card.id;
|
|
189
|
+
quizzes += 1;
|
|
190
|
+
return {
|
|
191
|
+
reply: 'Quick one, just for practice: ' + ask(card) + ' Answer here when you’re ready.',
|
|
192
|
+
suggestions: keys([quizzes % 2 ? 'I’m not sure, tell me' : 'No idea, what is it?']),
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function keywords(text) {
|
|
198
|
+
var stop = ['the', 'and', 'for', 'you', 'your', 'this', 'that', 'does', 'are', 'was', 'with', 'how', 'what'];
|
|
199
|
+
return norm(text).split(' ').filter(function (w) { return w.length >= 3 && stop.indexOf(w) < 0; });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function grade(answer) {
|
|
203
|
+
var card = quiz;
|
|
204
|
+
quiz = null;
|
|
205
|
+
var want = keywords(card.back), said = norm(answer);
|
|
206
|
+
var hits = want.filter(function (w) { return said.indexOf(w.slice(0, 4)) >= 0; }).length;
|
|
207
|
+
var after = { reply: '', suggestions: keys([quizzes % 2 ? 'Quiz me on another' : 'One more quiz']) };
|
|
208
|
+
if (said === norm(card.back) || (want.length && hits / want.length >= 0.6)) {
|
|
209
|
+
after.reply = 'That’s it: ' + said(card.back) + ' That one’s sticking.';
|
|
210
|
+
} else if (hits) {
|
|
211
|
+
after.reply = 'Close. It’s ' + said(card.back) + ' You had the gist; marking it on the deck is what moves it up a box.';
|
|
212
|
+
} else {
|
|
213
|
+
after.reply = 'Not quite: it’s ' + said(card.back) + ' No harm done. It comes back in your next review, and that’s the system working.';
|
|
214
|
+
}
|
|
215
|
+
return after;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
name: 'Noor',
|
|
220
|
+
role: 'Study Partner',
|
|
221
|
+
greeting: 'Hi, I’m Noor. Four cards are due this morning, and **een bos bloemen** keeps slipping, so it’s first in line. Start the review when you’re ready, or ask me for more cards.',
|
|
222
|
+
suggestions: BASE,
|
|
223
|
+
respond: function (text, ctx) {
|
|
224
|
+
// Every reply refreshes the keys, so an answer to a finished quiz never lingers.
|
|
225
|
+
return Promise.resolve(answer()).then(function (r) {
|
|
226
|
+
return r == null || (typeof r === 'object' && !Array.isArray(r)) ? r : { reply: r, suggestions: keys() };
|
|
227
|
+
});
|
|
228
|
+
function answer() {
|
|
229
|
+
var lower = text.toLowerCase();
|
|
230
|
+
var other = /\b(how am i|progress|explain|quiz|add|more|due|hardest)\b/.test(lower);
|
|
231
|
+
if (quiz && /\b(not sure|don.?t know|tell me|give up|no idea|reveal|show me|what is it)\b/.test(lower)) {
|
|
232
|
+
var card = quiz;
|
|
233
|
+
quiz = null;
|
|
234
|
+
return {
|
|
235
|
+
reply: 'It’s ' + said(card.back) + ' That’s exactly why it’s in the deck; it comes back in your next review.',
|
|
236
|
+
suggestions: keys([quizzes % 2 ? 'Quiz me on another' : 'One more quiz']),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (quiz && !other) return grade(text);
|
|
240
|
+
quiz = null;
|
|
241
|
+
if (/\b(explain|what does|meaning|why)\b/.test(lower)) return explain(ctx, text);
|
|
242
|
+
if (/\b(practice cards?|new angle|another angle|ones? i missed|missed ones|yes)\b/.test(lower)) return angleCards(ctx);
|
|
243
|
+
if (/\b(quiz|test me|ask me)\b/.test(lower)) return startQuiz(ctx);
|
|
244
|
+
if (/\b(how am i|progress|stats|summary|status|how.?s it going)\b/.test(lower)) return progress(ctx);
|
|
245
|
+
if (/\b(due)\b/.test(lower)) {
|
|
246
|
+
return deck(ctx).then(function (d) {
|
|
247
|
+
var due = d.dueCardIds.map(function (id) { return byId(d, id); }).filter(Boolean);
|
|
248
|
+
return due.length
|
|
249
|
+
? 'Due now, in review order:\n\n' + due.map(function (c) { return '- ' + c.front; }).join('\n')
|
|
250
|
+
: 'Nothing is due right now. The deck brings each card back on schedule.';
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
if (/\b(hardest|struggl\w*|trouble|difficult|tricky)\b/.test(lower)) {
|
|
254
|
+
return deck(ctx).then(function (d) {
|
|
255
|
+
var tough = hardest(d).slice(0, 3);
|
|
256
|
+
return tough.length
|
|
257
|
+
? 'The ones that slip most:\n\n' + tough.map(function (c) { return '- **' + c.front + '**: missed ' + plural(c.stats.missed, 'time'); }).join('\n')
|
|
258
|
+
: 'Nothing has slipped yet. Every card you’ve reviewed, you got.';
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (/\b(add|more|write|make|new)\b/.test(lower) && /\b(cards?|phrases?|words?|greetings?|numbers?|prices?|produce|fruit)\b/.test(lower)) return addTopic(ctx, text);
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
reactions: {
|
|
266
|
+
// The live reaction: one short, specific line after a review session.
|
|
267
|
+
finish_session: function (input, output, ctx) {
|
|
268
|
+
return deck(ctx).then(function (d) {
|
|
269
|
+
var reviewed = Number(input.reviewed) || 0;
|
|
270
|
+
var missed = (input.missedIds || []).map(function (id) { return byId(d, id); }).filter(Boolean);
|
|
271
|
+
var top = reviewedLately(d).filter(function (c) { return c.box === 3; })[0];
|
|
272
|
+
var lift = top ? ' **' + top.front + '** made it to the weekly shelf.' : '';
|
|
273
|
+
if (!missed.length) {
|
|
274
|
+
return (reviewed > 1 ? 'All ' + reviewed + ', no misses.' : 'Got it, no misses.') + (lift || ' Every one moved up a box.');
|
|
275
|
+
}
|
|
276
|
+
var names = missed.map(function (c) { return '**' + c.front + '**'; }).join(' and ');
|
|
277
|
+
offer = missed.length === 1 ? 'Yes, add practice cards for it' : 'Yes, add practice cards for those';
|
|
278
|
+
return {
|
|
279
|
+
reply: (reviewed - missed.length) + ' of ' + reviewed + '.' + lift + ' ' + names + ' slipped, which is the deck doing its job. ' +
|
|
280
|
+
'Want a couple of fresh cards that come at ' + (missed.length === 1 ? 'it' : 'them') + ' from a new angle?',
|
|
281
|
+
suggestions: keys(),
|
|
282
|
+
};
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
// The live reaction turns staged notes into cards with add_cards.
|
|
286
|
+
forge_from_notes: function (input, output, ctx) {
|
|
287
|
+
var cards = cardsFromNotes(String((output && output.notes) || input.notes || ''));
|
|
288
|
+
if (!cards.length) return 'I couldn’t find clear facts in those notes. Try a few full sentences, one fact each.';
|
|
289
|
+
return ctx.invoke('add_cards', { cards: cards }, plural(cards.length, 'card') + ' from your notes').then(function (out) {
|
|
290
|
+
return out.summary;
|
|
291
|
+
});
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// One fact per card, the way the live prompt asks: a term and its meaning,
|
|
297
|
+
// "X means Y", a short "X is Y", or a fill-in-the-blank for anything else.
|
|
298
|
+
function cardsFromNotes(notes) {
|
|
299
|
+
var NUMBER = /^(\d[\d.,]*|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|twenty|hundred|thousand)$/i;
|
|
300
|
+
var ARTICLE = /^(the|a|an|een|de|het)\s/i;
|
|
301
|
+
var cards = [];
|
|
302
|
+
notes.split(/(?<=[.!?])\s+|\n+/).forEach(function (raw) {
|
|
303
|
+
if (cards.length >= 8) return;
|
|
304
|
+
var s = raw.trim().replace(/[.!]+$/, '');
|
|
305
|
+
if (s.length < 6) return;
|
|
306
|
+
var m = /^(.{1,60}?)(?:\s*[:=]\s+|\s+[-–]\s+)(.+)$/.exec(s);
|
|
307
|
+
if (m) return cards.push({ front: m[1], back: m[2] });
|
|
308
|
+
m = /^(.+?)\s+means\s+(.+)$/i.exec(s);
|
|
309
|
+
if (m) {
|
|
310
|
+
var term = m[1].split(/\s+/).length <= 2 ? m[1].charAt(0).toLowerCase() + m[1].slice(1) : m[1];
|
|
311
|
+
return cards.push({ front: 'What does ' + term + ' mean?', back: m[2] });
|
|
312
|
+
}
|
|
313
|
+
m = /^(.+?)\s+(is|are)\s+(.+)$/i.exec(s);
|
|
314
|
+
if (m && m[1].split(/\s+/).length <= 3) {
|
|
315
|
+
return cards.push({ front: 'What ' + m[2].toLowerCase() + ' ' + m[1].replace(ARTICLE, function (a) { return a.toLowerCase(); }) + '?', back: m[3] });
|
|
316
|
+
}
|
|
317
|
+
var words = s.split(/\s+/);
|
|
318
|
+
if (words.length < 4) return;
|
|
319
|
+
var at = words.findIndex(function (w) { return NUMBER.test(w); });
|
|
320
|
+
if (at < 0) at = words.findIndex(function (w, i) { return i > 0 && /^[A-Z][a-z]/.test(w); });
|
|
321
|
+
if (at < 0) {
|
|
322
|
+
for (var i = words.length - 1; i > 0; i -= 1) if (words[i].replace(/\W/g, '').length >= 4) { at = i; break; }
|
|
323
|
+
}
|
|
324
|
+
if (at < 0) return;
|
|
325
|
+
var answer = words[at].replace(/[^\w’'-]/g, '');
|
|
326
|
+
words[at] = '___';
|
|
327
|
+
cards.push({ front: 'Fill in the blank: ' + words.join(' ') + '.', back: answer });
|
|
328
|
+
});
|
|
329
|
+
return cards;
|
|
330
|
+
}
|
|
331
|
+
})();
|