s←⊢⊆⍨' '≠⊢
a b c←2097144 131064 1957895
f←{(⊂⍵)∊(12↑v),(s'yi ya ye yao you yan yang yin ying yong yu yue yuan yun wu wa wo wai wei wan wang wen weng nv lv nve lve'),(,⊤(a-8)1966080 393208 1966064 2096720 1966072 1048568a a 2056184a 131048a 7288b 7280 106488b 7280b 0 1958911 73735c c 352263c 24583 1859591c,5⍴7)/,('bpmfdtnlgkhzcs',s'zh ch sh r j q x')∘.,v←'aoe',s'ai ei ao ou an ang en eng ong u ua uo uai ui uan uang un ueng i ia ie iao iu ian iang in ing iong u ue uan un'}
Try it online!
Golfing in progress.
Ungolfed
s←{⍵⊆⍨' '≠⍵}
con←s'b p m f d t n l g k h z c s zh ch sh r j q x'
vwl←s'a o e ai ei ao ou an ang en eng ong u ua uo uai ui uan uang un ueng i ia ie iao iu ian iang in ing iong u ue uan un'
tab←con∘.,vwl
bin←,⊤2097136 1966080 393208 1966064 2096720 1966072 1048568 2097144 2097144 2056184 2097144 131048 2097144 7288 131064 7280 106488 131064 7280 131064 0 1958911 73735 1957895 1957895 352263 1957895 24583 1859591 1957895 7 7 7 7 7
all←'aoe',(12↑vwl),(s'yi ya ye yao you yan yang yin ying yong yu yue yuan yun wu wa wo wai wei wan wang wen weng nv lv nve lve'),bin/,tab
f←{(⊂⍵)∊all}
Try it online!
The helper function s
unpacks a space-delimited string:
{⍵⊆⍨' '≠⍵} monadic function taking a string
' '≠⍵ 0s at spaces, 1s elsewhere
⍵⊆⍨ Partition (split at 0s)
I first store the possible initial and final strings in the syllable, then make a table tab
containing the concatenation of each string from the first list with each string from the second list.
Next, I store binary data as a list of integers. Some of the integers are repeated and can therefore be stored in variables, which also allows elision of some spaces.
Each integer is decoded into binary, and represents one row of the table. Each bit in the number represents whether a certain syllable in that row is a valid syllable, with the MSB representing the first column. All invalid syllables are removed from the table.
We flatten the table into a list, add on the forms with no initial consonant as a special case, and finally check if our input is in the list.
Possible further golfing potential:
- Write base64 or base255 encoding
- Reorder the columns and rows to make the numbers smaller.
Python helpful script and test-case generator: Try it online!
nar
? :P \$\endgroup\$nvi
is ever a valid combination. \$\endgroup\$