Change e letters to i in words: Difference between revisions

Content added Content deleted
m (→‎AppleScript :: Functional: Adjusted display format, updated output)
Line 327: Line 327:
set longWords to filteredLines("5 < length", s)
set longWords to filteredLines("5 < length", s)
set eWords to longWords's ¬
set eWords to longWords's ¬
filteredArrayUsingPredicate:(containsString("e"))
filteredArrayUsingPredicate:(containsChar("e"))
set lexicon to ca's NSSet's ¬
set lexicon to ca's NSSet's ¬
setWithArray:(longWords's ¬
setWithArray:(longWords's ¬
filteredArrayUsingPredicate:(containsString("i")))
filteredArrayUsingPredicate:(containsChar("i")))
set possibles to (allReplaced("e", "i", ¬
set possibles to ((eWords's ¬
(eWords's componentsJoinedByString:(linefeed))))'s ¬
componentsJoinedByString:(linefeed))'s ¬
stringByReplacingOccurrencesOfString:("e") ¬
withString:("i"))'s ¬
componentsSeparatedByString:(linefeed)
componentsSeparatedByString:(linefeed)
set possibleSet to ca's NSMutableSet's setWithArray:(possibles)
set possibleSet to ca's NSMutableSet's setWithArray:(possibles)
Line 341: Line 343:
-- Dictionary of possible words and their sources
-- Dictionary of possible words and their sources
set dict to dictFromZip(possibles, eWords)
set dict to ca's NSDictionary's ¬
dictionaryWithObjects:eWords forKeys:possibles
-- Listing of candidate words which are found in the dictionary
-- Listing of candidate words which are found in the dictionary
Line 361: Line 364:
set {e, i} to ei
set {e, i} to ei
e & " -> " & i
i & " <- " & e
end |λ|
end |λ|
end script
end script
Line 368: Line 371:
ieTwins(readFile("~/Desktop/unixdict.txt"))))
ieTwins(readFile("~/Desktop/unixdict.txt"))))
end run
end run





------------------------- GENERIC ------------------------
------------------------- GENERIC ------------------------


-- containsChar :: Char -> NSPredicate
-- allRplaced :: String -> String -> NSString -> NSString
on containsChar(c)
on allReplaced(needle, replacement, haystack)
haystack's stringByReplacingOccurrencesOfString:(needle) ¬
withString:(replacement)
end allReplaced


-- containsString :: String -> NSPredicate
on containsString(s)
tell current application
tell current application
its (NSPredicate's ¬
its (NSPredicate's ¬
predicateWithFormat:("self contains '" & s & "'"))
predicateWithFormat:("self contains '" & c & "'"))
end tell
end containsString


-- dictFromZip :: NSArray -> NSArray -> NSDictionary
on dictFromZip(ks, vs)
tell current application
its (NSDictionary's ¬
dictionaryWithObjects:vs forKeys:ks)
end tell
end tell
end dictFromZip
end containsChar




-- filteredLines :: String -> NSString -> [a]
-- filteredLines :: String -> NString -> [a]
on filteredLines(predicateString, s)
on filteredLines(predicateString, s)
-- A list of lines filtered by an NSPredicate string
-- A list of lines filtered by an NSPredicate string
Line 404: Line 392:
predicateWithFormat:predicateString)
predicateWithFormat:predicateString)
set array to its (NSArray's ¬
set array to its (NSArray's ¬
arrayWithArray:(s's componentsSeparatedByString:(linefeed)))
arrayWithArray:(s's componentsSeparatedByString:("\n")))
end tell
end tell
Line 467: Line 455:
end unlines</lang>
end unlines</lang>
{{Out}}
{{Out}}
<pre>analyses -> analysis
<pre>analysis <- analyses
atlantis <- atlantes
atlantes -> atlantis
billow <- bellow
bellow -> billow
briton <- breton
breton -> briton
clinch <- clench
clench -> clinch
convict <- convect
convect -> convict
crisis <- crises
crises -> crisis
diagnosis <- diagnoses
diagnoses -> diagnosis
francis <- frances
frances -> francis
galatia <- galatea
galatea -> galatia
hardin <- harden
harden -> hardin
hickman <- heckman
heckman -> hickman
infant <- enfant
enfant -> infant
inflict <- inflect
inflect -> inflict
iniquity <- inequity
inequity -> iniquity
inquiry <- enquiry
enquiry -> inquiry
jacobian <- jacobean
jacobean -> jacobian
martin <- marten
marten -> martin
moduli <- module
module -> moduli
pigging <- pegging
pegging -> pigging
psychosis <- psychoses
psychoses -> psychosis
rabbit <- rabbet
rabbet -> rabbit
stirling <- sterling
sterling -> stirling
synopsis <- synopses
synopses -> synopsis
victor <- vector
vector -> victor
welles -> willis</pre>
willis <- welles</pre>


=={{header|AWK}}==
=={{header|AWK}}==