Skip to content

Instantly share code, notes, and snippets.

@PatheticMustan
Last active October 7, 2024 03:36
Show Gist options
  • Save PatheticMustan/5576992ebbe1cc2e7e59512f880ea3d8 to your computer and use it in GitHub Desktop.
Save PatheticMustan/5576992ebbe1cc2e7e59512f880ea3d8 to your computer and use it in GitHub Desktop.
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")
);
@PatheticMustan
Copy link
Author

fixed medial

@PatheticMustan
Copy link
Author

this is just a silly little script to help me with my phonetics class

@PatheticMustan
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment