-
Notifications
You must be signed in to change notification settings - Fork 53
/
rhymer.ps1
57 lines (44 loc) · 1.29 KB
/
rhymer.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<#
Author: Doug Finke
Email: [email protected]
Blog: https://dfinke.github.io/
Twitter: https://twitter.com/dfinke
GitHub: https://github.com/dfinke
YouTube: https://www.youtube.com/dougfinke
PowerShell Meetup: https://www.meetup.com/NycPowershellMeetup/
LinkedIn: https://www.linkedin.com/in/douglasfinke/
#>
param(
$word
)
function Invoke-Stemmer {
param($word)
$word = $word.ToLower()
$vowelPos = $(foreach ($vowel in 'aeiou'.ToCharArray()) {
$word.IndexOf($vowel)
}).Where( { $_ -gt -1 })
if ($vowelPos) {
$firstVowel = ($vowelPos | Measure-Object -Minimum).Minimum
$word.Substring(0, $firstVowel)
$word.Substring($firstVowel)
}
else {
$word
}
}
if ($word) {
[string[]]$prefixes = 'bcdfghjklmnpqrstvwxyz'.ToCharArray() + $(
'bl br ch cl cr dr fl fr gl gr pl pr sc'
'sh sk sl sm sn sp st sw th tr tw thw wh wr'
'sch scr shr sph spl spr squ str thr'
).split()
$start, $rest = Invoke-Stemmer $word
if ($rest) {
$(foreach ($p in $prefixes.where( { $_ -ne $start } )) {
$p + $rest
}) | Sort-Object
}
else {
"Cannot rhyme '$word'"
}
}