@@ -268,7 +268,7 @@ const ADJECTIVE = {
268
268
ale : [ "all" ] ,
269
269
ali : [ "all" ] ,
270
270
anpa : [ "bottom" ] ,
271
- ante : [ "other" ] ,
271
+ ante : [ "different" , " other"] ,
272
272
awen : [ "staying" ] ,
273
273
esun : [ ] ,
274
274
ijo : [ ] ,
@@ -521,9 +521,11 @@ function translatePhraseToAdverb(phrase) {
521
521
return translations ;
522
522
}
523
523
/**
524
- * translates phrase into adjective
524
+ * translates phrase into adjective without "in X way"
525
+ *
526
+ * this doesn't handle whole phrase emphasis
525
527
*/
526
- function translatePhraseToAdjective ( phrase ) {
528
+ function translatePhraseToSimpleAdjective ( phrase ) {
527
529
let translations = ADJECTIVE [ phrase . headword ] . slice ( ) ;
528
530
if ( phrase . emphasis === "headword" ) {
529
531
translations = translations . flatMap ( ( word ) => [ `so ${ word } ` , `(${ word } )` ] ) ;
@@ -548,16 +550,13 @@ function translatePhraseToAdjective(phrase) {
548
550
break ;
549
551
case "pi" :
550
552
translations = translations . flatMap ( ( word ) =>
551
- translatePhraseToAdjective ( modifier ) . map (
553
+ translatePhraseToSimpleAdjective ( modifier ) . map (
552
554
( adverb ) => `${ adverb } ${ word } `
553
555
)
554
556
) ;
555
557
break ;
556
558
}
557
559
}
558
- if ( phrase . emphasis === "whole" ) {
559
- translations = translations . map ( ( translation ) => `(${ translation } )` ) ;
560
- }
561
560
return translations ;
562
561
}
563
562
/**
@@ -599,7 +598,7 @@ function translatePhraseToSimpleNoun(phrase) {
599
598
break ;
600
599
case "pi" :
601
600
translations = translations . flatMap ( ( word ) =>
602
- translatePhraseToAdjective ( modifier ) . map (
601
+ translatePhraseToSimpleAdjective ( modifier ) . map (
603
602
( adjective ) => `${ adjective } ${ word } `
604
603
)
605
604
) ;
@@ -608,6 +607,52 @@ function translatePhraseToSimpleNoun(phrase) {
608
607
}
609
608
return translations ;
610
609
}
610
+ /**
611
+ * translates phrase into adjective phrase with "in X way"
612
+ */
613
+ function translatePhraseToAdjective ( phrase ) {
614
+ let translations = translatePhraseToSimpleAdjective ( phrase ) ;
615
+ for ( const [ i , item ] of phrase . modifiers . entries ( ) ) {
616
+ const heads = translatePhraseToSimpleAdjective ( {
617
+ ...phrase ,
618
+ modifiers : [
619
+ ...phrase . modifiers . slice ( 0 , i ) ,
620
+ ...phrase . modifiers . slice ( i + 1 ) ,
621
+ ] ,
622
+ } ) ;
623
+ switch ( item . type ) {
624
+ case "proper word" :
625
+ continue ;
626
+ case "word" :
627
+ if ( item . emphasized ) {
628
+ for ( const head of heads ) {
629
+ for ( const adjective of ADJECTIVE [ item . word ] ) {
630
+ translations . push ( `${ head } in (${ adjective } ) way` ) ;
631
+ }
632
+ }
633
+ } else {
634
+ for ( const head of heads ) {
635
+ for ( const adjective of ADJECTIVE [ item . word ] ) {
636
+ translations . push ( `${ head } in ${ adjective } way` ) ;
637
+ }
638
+ }
639
+ }
640
+ break ;
641
+ case "pi" :
642
+ const phrases = translatePhraseToSimpleAdjective ( item ) ;
643
+ for ( const head of heads ) {
644
+ for ( const phrase of phrases ) {
645
+ translations . push ( `${ head } in ${ phrase } way` ) ;
646
+ }
647
+ }
648
+ break ;
649
+ }
650
+ }
651
+ if ( phrase . emphasis === "whole" ) {
652
+ translations = translations . map ( ( translation ) => `(${ translation } )` ) ;
653
+ }
654
+ return translations ;
655
+ }
611
656
/**
612
657
* translates phrase into noun phrase with "of"s
613
658
*/
@@ -654,43 +699,70 @@ function translatePhraseToNoun(phrase) {
654
699
}
655
700
return translations ;
656
701
}
657
- /**
658
- * translates clauses before la
659
- */
660
- function translateLaClause ( clause ) {
661
- switch ( clause . type ) {
662
- case "phrase" :
663
- const translations = translatePhraseToNoun ( clause ) ;
664
- if ( translations . length === 0 ) {
665
- throw new UntranslatableError ( "complicated phrase" ) ;
666
- }
667
- return translations ;
668
- default :
669
- throw new Error ( "todo" ) ;
670
- }
671
- }
702
+ // /**
703
+ // * translates clauses before la
704
+ // */
705
+ // function translateLaClause(clause) {
706
+ // switch (clause.type) {
707
+ // case "phrase":
708
+ // const translations = [
709
+ // ...translatePhraseToAdjective(clause),
710
+ // ...translatePhraseToNoun(clause),
711
+ // ];
712
+ // if (translations.length === 0) {
713
+ // throw new UntranslatableError("complicated phrase");
714
+ // }
715
+ // return translations;
716
+ // default:
717
+ // throw new Error("todo");
718
+ // }
719
+ // }
672
720
/**
673
721
* translates clauses after la or without la
674
722
*/
675
723
function translateFinalClause ( clause ) {
676
724
switch ( clause . type ) {
677
725
case "phrase" :
678
- return [
679
- ...translatePhraseToNoun ( clause ) ,
726
+ const translations = [
680
727
...translatePhraseToAdjective ( clause ) ,
728
+ ...translatePhraseToNoun ( clause ) ,
681
729
] ;
730
+ if ( translations . length === 0 ) {
731
+ throw new UntranslatableError ( "complicated phrase" ) ;
732
+ }
733
+ return translations ;
682
734
default :
683
735
throw new Error ( "todo" ) ;
684
736
}
685
737
}
686
738
/**
687
739
* translates sentence without a or taso
688
740
*/
689
- function translatePureSentence ( sentence ) {
690
- if ( sentence . beforeLa . length > 0 ) {
691
- throw new Error ( "todo" ) ;
741
+ function translatePureSentence ( pureSentence ) {
742
+ let translations = [ "" ] ;
743
+ for ( const beforeLa of pureSentence . beforeLa ) {
744
+ translations = translations . flatMap ( ( sentence ) => {
745
+ switch ( beforeLa . type ) {
746
+ case "phrase" :
747
+ return [
748
+ ...translatePhraseToAdjective ( beforeLa ) . map (
749
+ ( translation ) => `${ sentence } if ${ translation } , then `
750
+ ) ,
751
+ ...translatePhraseToNoun ( beforeLa ) . map (
752
+ ( translation ) => `${ sentence } given ${ translation } , `
753
+ ) ,
754
+ ] ;
755
+ default :
756
+ throw new Error ( "todo" ) ;
757
+ }
758
+ } ) ;
692
759
}
693
- return translateFinalClause ( sentence . sentence ) ;
760
+ translations = translations . flatMap ( ( sentence ) =>
761
+ translateFinalClause ( pureSentence . sentence ) . map (
762
+ ( translation ) => `${ sentence } ${ translation } `
763
+ )
764
+ ) ;
765
+ return translations ;
694
766
}
695
767
function translateSentence ( sentence ) {
696
768
let start ;
@@ -893,7 +965,7 @@ function parseClause(array) {
893
965
}
894
966
throw new Error ( "todo" ) ;
895
967
} else if ( array . includes ( "o" ) ) {
896
- if ( array . slice ( array . indexOf ( "o" ) ) . includes ( "o" ) ) {
968
+ if ( array . slice ( array . indexOf ( "o" ) + 1 ) . includes ( "o" ) ) {
897
969
throw new UnrecognizedError ( 'Multiple "o"s' ) ;
898
970
}
899
971
throw new Error ( "todo" ) ;
0 commit comments