1
1
const { dbGetter } = require ( "./getter.js" ) ;
2
2
3
+ async function findART ( obj , langRef ) {
4
+ const addART = [ ]
5
+ let i = 0 , j = 0 ;
6
+ while ( i < obj . words . length ) {
7
+ if ( obj . types [ i ] === 'NOUN' || obj . types [ i ] === 'SUBJ' ) {
8
+ const articlesGenders = await dbGetter . getPersistent ( langRef , 'ARTICLES/GENDERS' , { } ) ;
9
+ addART . push ( [ i , articlesGenders [ genders [ j ] ] ] )
10
+ j ++ ;
11
+ }
12
+ i ++ ;
13
+ }
14
+ addART . forEach ( ( v , i ) => {
15
+ obj . words . splice ( v [ 0 ] + i , 0 , v [ 1 ] )
16
+ obj . types . splice ( v [ 0 ] + i , 0 , 'ART' )
17
+ } )
18
+ }
19
+
3
20
async function handleType ( obj , sentence , langRef , src , forces ) {
21
+ if ( obj . position > 0 ) {
22
+ if ( sentence [ obj . position - 1 ] . props . next ) {
23
+ obj . props . prev = sentence [ obj . position - 1 ] . props . next ;
24
+ }
25
+ }
4
26
switch ( obj . type ) {
5
27
case 'VERB' :
6
28
obj = await handleVERB ( obj , sentence , langRef , src , forces ) ;
@@ -60,15 +82,16 @@ async function handleVERB(obj, sentence, langRef, src, forces){
60
82
}
61
83
62
84
async function conjugateVERB ( obj , langRef , src ) {
63
- const defaults = await dbGetter . getPersistent ( langRef , 'DEFAULTS' , { } )
85
+ const defaults = await dbGetter . getPersistent ( langRef , 'DEFAULTS' , { } ) ;
64
86
const newWordsInf = obj . words . map ( word => getVERBInfinitive ( word , langRef ) ) ;
65
87
const newWordsSeq = newWordsInf . map ( p => new Promise ( ( resolve ) => {
66
88
p . then ( inf => dbGetter . getOnce ( langRef , `VERBS/SEQUENCES/${ inf } ` ) )
67
89
. then ( seq => resolve ( seq ) )
68
- } ) )
90
+ } ) ) ;
69
91
const newWords = obj . words . map ( ( w , i ) => new Promise ( ( resolve ) => {
70
92
Promise . all ( [ newWordsInf [ i ] , newWordsSeq [ i - 1 ] ] )
71
93
. then ( ( [ inf , seq ] ) => {
94
+ seq = i == 0 ? obj . props . prev ?. VERB : seq ?. VERB
72
95
if ( seq ) {
73
96
if ( seq === 'INF' ) return inf . split ( ' ' )
74
97
return Promise . all ( inf . split ( ' ' ) . map ( winf => getVERBConjugations ( winf , src , langRef , seq ) ) )
@@ -79,8 +102,10 @@ async function conjugateVERB(obj, langRef, src){
79
102
return Promise . all ( inf . split ( ' ' ) . map ( winf => getVERBConjugations ( winf , src , langRef , obj . meta . TIME , obj . meta . PERSON ) ) )
80
103
}
81
104
} ) . then ( conj => resolve ( conj . join ( ' ' ) ) )
82
- } ) )
83
- obj . words = await Promise . all ( newWords )
105
+ } ) ) ;
106
+ obj . words = await Promise . all ( newWords ) ;
107
+ obj . infs = await Promise . all ( newWordsInf ) ;
108
+ obj . props . next = await newWordsSeq . at ( - 1 ) ;
84
109
if ( obj . words . at ( - 1 ) . includes ( ':CON:' ) ) {
85
110
obj . words . splice ( - 1 , 1 , ...[ defaults . CON , obj . words . at ( - 1 ) . replace ( ' :CON:' , '' ) ] )
86
111
obj . types . splice ( - 1 , 0 , 'CON' )
@@ -127,11 +152,34 @@ async function getVERBInfinitive(word, langRef){
127
152
128
153
async function handleNOUN ( obj , sentence , langRef , src ) {
129
154
const defaults = await dbGetter . getPersistent ( langRef , 'DEFAULTS' , { } )
155
+ if ( obj . props . prev ) {
156
+ if ( obj . props . prev [ obj . types [ 0 ] ] ) {
157
+ const toPrepend = obj . props . prev [ obj . types [ 0 ] ] . EXCEPTION
158
+ ? obj . props . prev [ obj . types [ 0 ] ] . EXCEPTION [ obj . words [ 0 ] ] || obj . props . prev [ obj . types [ 0 ] ] . DEFAULT
159
+ : obj . props . prev [ obj . types [ 0 ] ] . DEFAULT ;
160
+ const toPrependSplit = toPrepend . split ( ',' )
161
+ for ( let t = toPrependSplit . length - 1 ; t <= 0 ; t -- ) {
162
+ const tp = toPrependSplit [ t ] ;
163
+ switch ( tp ) {
164
+ case 'ART' :
165
+ const articlesGenders = await dbGetter . getPersistent ( langRef , 'ARTICLES/GENDERS' , { } ) ;
166
+ obj . words . unshift ( articlesGenders [ obj . genders [ 0 ] ] )
167
+ obj . types . unshift ( 'ART' )
168
+ break ;
169
+ case 'NONE' :
170
+ continue ;
171
+ default :
172
+ obj . words [ 0 ] = [ tp , obj . words [ 0 ] ] . join ( ' ' )
173
+ break ;
174
+ }
175
+ }
176
+ }
177
+ }
130
178
if ( obj . composed ) {
131
- if ( obj . types . at ( - 2 ) === 'NOUN' ) {
179
+ if ( obj . types . at ( - 2 ) === 'NOUN' || obj . types . at ( - 2 ) === 'SUBJ' ) {
132
180
obj . words . splice ( - 1 , 0 , defaults . CON ) ;
133
181
obj . types . splice ( - 1 , 0 , "CON" ) ;
134
- } else if ( obj . types . at ( - 2 ) === 'ART' && obj . types . at ( - 3 ) === 'NOUN' ) {
182
+ } else if ( obj . types . at ( - 2 ) === 'ART' && ( obj . types . at ( - 3 ) === 'NOUN' || obj . types . at ( - 3 ) === 'SUBJ' ) ) {
135
183
obj . words . splice ( - 2 , 0 , defaults . CON ) ;
136
184
obj . types . splice ( - 2 , 0 , "CON" ) ;
137
185
}
@@ -149,11 +197,35 @@ async function handleNOUN(obj, sentence, langRef, src){
149
197
150
198
async function handleSUBJ ( obj , sentence , langRef , src ) {
151
199
const defaults = await dbGetter . getPersistent ( langRef , 'DEFAULTS' , { } )
200
+ if ( obj . props . prev ) {
201
+ if ( obj . props . prev [ obj . types [ 0 ] ] ) {
202
+ const toPrepend = obj . props . prev [ obj . types [ 0 ] ] . EXCEPTION
203
+ ? obj . props . prev [ obj . types [ 0 ] ] . EXCEPTION [ obj . words [ 0 ] ] || obj . props . prev [ obj . types [ 0 ] ] . DEFAULT
204
+ : obj . props . prev [ obj . types [ 0 ] ] . DEFAULT ;
205
+ const toPrependSplit = toPrepend . split ( ',' )
206
+ for ( let t = toPrependSplit . length - 1 ; t >= 0 ; t -- ) {
207
+ const tp = toPrependSplit [ t ] ;
208
+ console . log ( tp )
209
+ switch ( tp ) {
210
+ case 'ART' :
211
+ const articlesGenders = await dbGetter . getPersistent ( langRef , 'ARTICLES/GENDERS' , { } ) ;
212
+ obj . words . unshift ( articlesGenders [ obj . genders [ 0 ] ] )
213
+ obj . types . unshift ( 'ART' )
214
+ break ;
215
+ case 'NONE' :
216
+ continue ;
217
+ default :
218
+ obj . words [ 0 ] = [ tp , obj . words [ 0 ] ] . join ( ' ' )
219
+ break ;
220
+ }
221
+ }
222
+ }
223
+ }
152
224
if ( obj . composed ) {
153
- if ( obj . types . at ( - 2 ) === 'SUBJ' ) {
225
+ if ( obj . types . at ( - 2 ) === 'NOUN' || obj . types . at ( - 2 ) === ' SUBJ') {
154
226
obj . words . splice ( - 1 , 0 , defaults . CON ) ;
155
227
obj . types . splice ( - 1 , 0 , "CON" ) ;
156
- } else if ( obj . types . at ( - 2 ) === 'ART' && obj . types . at ( - 3 ) === 'SUBJ' ) {
228
+ } else if ( obj . types . at ( - 2 ) === 'ART' && ( obj . types . at ( - 3 ) === 'NOUN' || obj . types . at ( - 3 ) === ' SUBJ') ) {
157
229
obj . words . splice ( - 2 , 0 , defaults . CON ) ;
158
230
obj . types . splice ( - 2 , 0 , "CON" ) ;
159
231
}
0 commit comments