File tree Expand file tree Collapse file tree 3 files changed +23
-25
lines changed
Expand file tree Collapse file tree 3 files changed +23
-25
lines changed Original file line number Diff line number Diff line change @@ -90,10 +90,10 @@ export type Preposition = Readonly<{
9090 object : NounPhrase ;
9191 emphasis : boolean ;
9292} > ;
93- export type Sentence =
93+ export type Sentence = Readonly < {
94+ clauses : ReadonlyArray < Clause > ;
95+ punctuation : string ;
96+ } > ;
97+ export type Sentences =
9498 | Readonly < { type : "free form" ; text : string } >
95- | Readonly < {
96- type : "sentence" ;
97- clauses : ReadonlyArray < Clause > ;
98- punctuation : string ;
99- } > ;
99+ | Readonly < { type : "sentences" ; sentences : ReadonlyArray < Sentence > } > ;
Original file line number Diff line number Diff line change @@ -132,24 +132,22 @@ function clause(ast: English.Clause): string {
132132 }
133133}
134134function sentence ( sentence : English . Sentence ) : string {
135- let text : string ;
136- switch ( sentence . type ) {
135+ const capitalized = capitalize ( sentence . clauses . map ( clause ) . join ( ", " ) ) ;
136+ return `${ capitalized } ${ sentence . punctuation } ` ;
137+ }
138+ export function multipleSentences (
139+ sentences : English . Sentences ,
140+ ) : string {
141+ switch ( sentences . type ) {
137142 case "free form" :
138- text = sentence . text ;
139- break ;
140- case "sentence" :
141- text = `${
142- sentence . clauses . map ( clause ) . join ( ", " )
143- } ${ sentence . punctuation } `;
144- break ;
143+ return capitalize ( sentences . text ) ;
144+ case "sentences" :
145+ return sentences . sentences . map ( sentence ) . join ( " " ) ;
145146 }
147+ }
148+ function capitalize ( text : string ) : string {
146149 return text . replace (
147150 / (?< ! [ < & \p{ Alpha} \p{ Nd} \p{ Nl} \p{ No} ] ) [ \p{ Alpha} \p{ Nd} \p{ Nl} \p{ No} ] / u,
148151 ( character ) => character . toLocaleUpperCase ( ) ,
149152 ) ;
150153}
151- export function multipleSentences (
152- sentences : ReadonlyArray < English . Sentence > ,
153- ) : string {
154- return sentences . map ( sentence ) . join ( " " ) ;
155- }
Original file line number Diff line number Diff line change @@ -177,23 +177,23 @@ function sentence(
177177}
178178export function multipleSentences (
179179 sentences : TokiPona . MultipleSentences ,
180- ) : ArrayResult < ReadonlyArray < English . Sentence > > {
180+ ) : ArrayResult < English . Sentences > {
181181 switch ( sentences . type ) {
182182 case "single word" : {
183183 const { word } = sentences ;
184184 return new ArrayResult ( dictionary . get ( word ) ! . definitions )
185185 . flatMap ( definitionAsPlainString )
186- . map < English . Sentence > ( ( definition ) => ( {
186+ . map ( ( definition ) => ( {
187187 type : "free form" ,
188188 text : definition ,
189- } ) )
190- . map ( ( definition ) => [ definition ] ) ;
189+ } ) ) ;
191190 }
192191 case "sentences" :
193192 return ArrayResult . combine (
194193 ...sentences . sentences . map ( ( value , i ) =>
195194 sentence ( value , i === sentences . sentences . length - 1 )
196195 ) ,
197- ) ;
196+ )
197+ . map ( ( sentences ) => ( { type : "sentences" , sentences } ) ) ;
198198 }
199199}
You can’t perform that action at this time.
0 commit comments