Last active
October 7, 2024 03:36
-
-
Save PatheticMustan/5576992ebbe1cc2e7e59512f880ea3d8 to your computer and use it in GitHub Desktop.
Filtering words from https://github.com/open-dict-data/ipa-dict/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const x = `adversely /ædˈvɝsɫi/ | |
adversity /ædˈvɝsɪˌti/, /ədˈvɝsɪti/ | |
advert /ˈædvɝt/ | |
advertise /ˈædvɝˌtaɪz/ | |
advertised /ˈædvɝˌtaɪzd/, /ˌædvɝˈtaɪzd/ | |
advertisement /ˌædvɝˈtaɪzmənt/, /ædˈvɝtəzmənt/ | |
advertisements /ˈædvɝˌtaɪzmənts/ | |
advertiser /ˈædvɝˌtaɪzɝ/` | |
const y = x.split("\n").map(p => p.split("\t").filter(v => v)); | |
const z = y.map(([word, ipa]) => [word, ipa]); | |
// 0=initial, 1=medial, 2=final | |
let mode = 1; | |
let letter = "h"; | |
console.log( | |
z.filter(([word, ipa]) => { | |
const ps = ipa.replace(/[ˈˌ]/gi, '').split(", ").map(p => p.slice(1, -1)); | |
if (mode === 0) return ps.some(p => p.startsWith(letter)); | |
if (mode === 1) return ps.some(p => p.slice(1, -1).includes(letter)); | |
if (mode === 2) return ps.some(p => p.endsWith(letter)); | |
}) | |
// randomize array | |
.map((a) => ({ sort: Math.random(), value: a })) | |
.sort((a, b) => a.sort - b.sort) | |
.map((a) => a.value) | |
// join | |
.join("\n") | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
there are some issues with medial ʃ (like with dʃ), but these are things that would have to be manually handled. maybe if this was an actual project