@@ -38,52 +38,92 @@ async function solveMOD(tokens, personsPlurals, personsGenders, advTimes, defaul
38
38
return tokens ;
39
39
}
40
40
41
- async function solveMISC ( words , types , definitivesRef ) {
42
- var definitives ;
43
-
41
+ async function solveMISC ( words , types , langRef ) {
44
42
for ( let i = 0 ; i < types . length ; i ++ ) {
45
43
if ( types [ i ] === 'MISC' ) {
46
- if ( ! definitives ) {
47
- const definitivesSn = await definitivesRef . get ( ) ;
48
- definitives = definitivesSn . val ( ) || { } ;
49
- }
50
- types [ i ] = definitives [ words [ i ] ] || 'MISC' ;
44
+ const definitiveMiscSn = await langRef . child ( `DEFINITIVES/MISC/${ words [ i ] } ` ) . get ( ) ;
45
+ types [ i ] = definitiveMiscSn . exists ( ) ? definitiveMiscSn . val ( ) : 'MISC' ;
51
46
}
52
47
}
53
48
return [ words , types ] ;
54
49
}
55
50
56
- function prepareMeta ( obj , personsPlurals , personsGenders , advTimes , defaults ) {
51
+ async function findART ( obj , articlesGenders ) {
52
+ for ( let i = 0 ; i < obj . words . length ; i ++ ) {
53
+ const wordsSplit = obj . words [ i ] . split ( ' ' ) ;
54
+ if ( wordsSplit . length > 1 ) {
55
+ const newWords = [ ]
56
+ const newTypes = [ ]
57
+ let currentNewWord = [ ]
58
+ const articleList = Object . keys ( articlesGenders ) . map ( k => articlesGenders [ k ] )
59
+ for ( w of wordsSplit ) {
60
+ if ( articleList . includes ( w ) ) {
61
+ if ( currentNewWord . length > 0 ) {
62
+ newWords . push ( currentNewWord . join ( ' ' ) )
63
+ newTypes . push ( obj . types [ i ] )
64
+ currentNewWord = [ ]
65
+ }
66
+ newWords . push ( w )
67
+ newTypes . push ( 'ART' )
68
+ console . log ( newWords )
69
+ console . log ( newTypes )
70
+ } else {
71
+ currentNewWord . push ( w )
72
+ }
73
+ }
74
+ newWords . push ( currentNewWord . join ( ' ' ) )
75
+ newTypes . push ( obj . types [ i ] )
76
+ obj . words . splice ( i , 1 , ...newWords )
77
+ obj . types . splice ( i , 1 , ...newTypes )
78
+ }
79
+ }
80
+ }
81
+
82
+ async function prepareMeta ( obj , personsPlurals , personsGenders , advTimes , articlesGenders , defaults , langRef ) {
83
+
57
84
switch ( obj . type ) {
58
85
case 'NOUN' :
59
- return prepareMetaNOUN ( obj , personsPlurals , personsGenders , defaults ) ;
86
+ return await prepareMetaNOUN ( obj , personsPlurals , personsGenders , articlesGenders , defaults , langRef ) ;
60
87
case 'SUBJ' :
61
- return prepareMetaSUBJ ( obj , personsPlurals , personsGenders , defaults ) ;
88
+ return await prepareMetaSUBJ ( obj , personsPlurals , personsGenders , defaults , langRef ) ;
62
89
case 'ADV' :
63
- return prepareMetaADV ( obj , advTimes , defaults ) ;
90
+ return await prepareMetaADV ( obj , advTimes , defaults ) ;
64
91
case 'ADJ' :
65
- return prepareMetaADJ ( obj ) ;
92
+ return await prepareMetaADJ ( obj ) ;
66
93
}
67
94
return obj ;
68
95
}
69
96
70
- function prepareMetaNOUN ( obj , personsPlurals , personsGenders , defaults ) {
97
+ async function prepareMetaNOUN ( obj , personsPlurals , personsGenders , articlesGenders , defaults , langRef ) {
71
98
99
+ await findART ( obj , articlesGenders )
72
100
const genders = [ ]
101
+ const addART = [ ]
73
102
for ( let i = 0 ; i < obj . words . length ; i ++ ) {
74
103
if ( obj . types [ i ] === 'NOUN' ) {
75
104
if ( personsGenders . flat ( 1 ) . includes ( obj . words [ i ] ) ) genders . push ( obj . words [ i ] )
76
105
else if ( obj . props [ i ] ) genders . push ( obj . props [ i ] . gender || defaults . GENDER )
77
- else genders . push ( defaults . GENDER )
106
+ else {
107
+ const definitiveGenderSn = await langRef . child ( `DEFINITIVES/GENDER/${ obj . words [ i ] } ` ) . get ( )
108
+ genders . push ( definitiveGenderSn . exists ( ) ? definitiveGenderSn . val ( ) : defaults . GENDER )
109
+ }
110
+ }
111
+ if ( i === 0 ) {
112
+ addART . push ( [ 0 , articlesGenders [ genders . at ( - 1 ) ] ] )
113
+ }
114
+ else if ( obj . types [ i - 1 ] !== 'ART' && obj . types [ i - 1 ] !== 'CON' ) {
115
+ addART . push ( [ i , articlesGenders [ genders . at ( - 1 ) ] ] )
78
116
}
79
117
}
118
+ addART . forEach ( ( v , i ) => {
119
+ obj . words . splice ( v [ 0 ] + i , 0 , v [ 1 ] )
120
+ obj . types . splice ( v [ 0 ] + i , 0 , 'ART' )
121
+ } )
80
122
if ( genders . length > 0 ) {
81
- const foundPerson = personsPlurals . find ( person => ( obj . words . includes ( person [ 0 ] ) || obj . words . includes ( person [ 1 ] ) ) ) || defaults . PERSON ;
123
+ const foundPerson = personsPlurals . find ( person => ( obj . words . includes ( person [ 0 ] ) || obj . words . includes ( person [ 1 ] ) ) ) || personsPlurals . at ( - 1 ) ;
82
124
obj . meta . PERSON = genders . length > 1 ? foundPerson [ 1 ] : foundPerson [ 0 ] ;
83
- if ( ! personsGenders . flat ( 1 ) . includes ( obj . meta . PERSON ) ) {
84
- const foundGender = personsGenders . find ( gender => ( genders . includes ( gender [ 0 ] ) || genders . includes ( gender [ 1 ] ) ) ) ;
85
- obj . meta . GENDER = genders . length > 1 ? foundGender [ 1 ] : foundGender [ 0 ] ;
86
- }
125
+ const foundGender = personsGenders . find ( gender => ( genders . includes ( gender [ 0 ] ) || genders . includes ( gender [ 1 ] ) ) ) ;
126
+ obj . meta . GENDER = genders . length > 1 ? foundGender [ 1 ] : foundGender [ 0 ] ;
87
127
} else {
88
128
obj . meta . PERSON = defaults . GENDER ;
89
129
}
@@ -94,14 +134,17 @@ function prepareMetaNOUN(obj, personsPlurals, personsGenders, defaults){
94
134
return obj ;
95
135
}
96
136
97
- function prepareMetaSUBJ ( obj , personsPlurals , personsGenders , defaults ) {
137
+ async function prepareMetaSUBJ ( obj , personsPlurals , personsGenders , defaults , langRef ) {
98
138
99
139
const genders = [ ]
100
140
for ( let i = 0 ; i < obj . words . length ; i ++ ) {
101
141
if ( obj . types [ i ] === 'SUBJ' ) {
102
142
if ( personsGenders . flat ( 1 ) . includes ( obj . words [ i ] ) ) genders . push ( obj . words [ i ] )
103
143
else if ( obj . props [ i ] ) genders . push ( obj . props [ i ] . gender || defaults . GENDER )
104
- else genders . push ( defaults . GENDER )
144
+ else {
145
+ const definitiveGenderSn = await langRef . child ( `DEFINITIVES/GENDER/${ obj . words [ i ] } ` ) . get ( )
146
+ genders . push ( definitiveGenderSn . exists ( ) ? definitiveGenderSn . val ( ) : defaults . GENDER )
147
+ }
105
148
}
106
149
}
107
150
if ( genders . length > 0 ) {
@@ -116,7 +159,7 @@ function prepareMetaSUBJ(obj, personsPlurals, personsGenders, defaults){
116
159
return obj ;
117
160
}
118
161
119
- function prepareMetaADV ( obj , advTimes , defaults ) {
162
+ async function prepareMetaADV ( obj , advTimes , defaults ) {
120
163
obj . types = obj . types . map ( t => t === 'MOD' ? 'ADV' : t )
121
164
122
165
for ( word of obj . words ) {
@@ -130,7 +173,7 @@ function prepareMetaADV(obj, advTimes, defaults){
130
173
return obj ;
131
174
}
132
175
133
- function prepareMetaADJ ( obj ) {
176
+ async function prepareMetaADJ ( obj ) {
134
177
obj . types = obj . types . map ( t => t === 'MOD' ? 'ADJ' : t )
135
178
return obj ;
136
179
}
0 commit comments