Change e letters to i in words: Difference between revisions

m
(→‎{{header|JavaScript}}: Added a version in JavaScript)
Line 307:
 
===Functional===
Assuming a local copy of unixdict.txt (on the macOS Desktop), using the Foundation libraries,
 
using the Foundation libraries,
 
and defining the list of twins as an intersection of sets.
Line 316 ⟶ 318:
----- DICTIONARY WORDS TWINNED BY (E -> I) REPLACEMENT ---
 
-- ieTwins :: String -> [(String, String)]
on ieTwins(s)
-- ListingPairs of dictionary words twinned by (e -> i) replacement
set ca to current application
Line 334 ⟶ 337:
set possibleSet to ca's NSMutableSet's setWithArray:(possibles)
set lexicon to ca's NSSet's ¬
setWithArray:(shortWords's filteredArrayUsingPredicate:(containsChar("i")))¬
filteredArrayUsingPredicate:(containsChar("i")))
possibleSet's intersectSet:(lexicon)
-- Dictionary of possible words and their sources
set dict to ca's NSDictionary's dictionaryWithObjects:eWords forKeys:possibles¬
dictionaryWithObjects:eWords forKeys:possibles
-- Listing of candidate words which are found in the dictionary
Line 345 ⟶ 350:
script pair
on |λ|(k)
{((dict's objectForKey:(k)) as string) & " -> " &, k}
end |λ|
end script
unlines(map(pair, ((possibleSet's allObjects())'s ¬
sortedArrayUsingSelector:"compare:") as list))
end ieTwins
 
 
 
--------------------------- TEST -------------------------
on run
script go
on |λ|(ei)
set {e, i} to ei
e & " -> " & i
end |λ|
end script
unlines(map(go, ¬
ieTwins(readFile("~/Desktop/unixdict.txt"))))
end run
 
Line 368 ⟶ 379:
on containsChar(c)
tell current application
its (NSPredicate's predicateWithFormat:("self contains '" & c & "'"))¬
predicateWithFormat:("self contains '" & c & "'"))
end tell
end containsChar
Line 377 ⟶ 389:
-- A list of lines filtered by an NSPredicate string
tell current application
set predicate to its (NSPredicate's predicateWithFormat:predicateString)¬
predicateWithFormat:predicateString)
set array to its (NSArray's ¬
arrayWithArray:(s's componentsSeparatedByString:("\n")))
9,655

edits