-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.js
30 lines (29 loc) · 954 Bytes
/
classes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Word {
constructor(data) {
this.word = data.word;
this.meanings = data.meanings || [{definitions:[{definition:''}]}];
this.meanings.forEach(m => { m.def = m.definitions[0].definition.toLowerCase(); m.word = this.word; });
this.pos = this.meanings.map(m => m.partOfSpeech);
this.patterns = {};
}
}
class Pattern {
constructor(conditions, uncert = 0, check = this.check) {
this.conditions = conditions;
this.uncert = uncert;
this.check = check;
}
check(wordData) {
//If some definition matches every condition
if (this.conditions.every(c =>
wordData.meanings.some(m =>
c.eq?.includes(m[c.key]) ||
c.starts?.some(e => m[c.key].substr(0, e.length) === e) ||
c.has?.some(e => m[c.key].includes(e))
)
)) {
return this.uncert;
}
return 1;
}
}