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:(containsChar("e"))
filteredArrayUsingPredicate:(containsString("e"))
set lexicon to ca's NSSet's ¬
set lexicon to ca's NSSet's ¬
setWithArray:(longWords's ¬
setWithArray:(longWords's ¬
filteredArrayUsingPredicate:(containsChar("i")))
filteredArrayUsingPredicate:(containsString("i")))
set possibles to ((eWords's ¬
set possibles to (allReplaced("e", "i", ¬
componentsJoinedByString:(linefeed))'s ¬
(eWords'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 343: Line 341:
-- Dictionary of possible words and their sources
-- Dictionary of possible words and their sources
set dict to ca's NSDictionary's ¬
set dict to dictFromZip(possibles, eWords)
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 371: Line 368:
ieTwins(readFile("~/Desktop/unixdict.txt"))))
ieTwins(readFile("~/Desktop/unixdict.txt"))))
end run
end run





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


-- allRplaced :: String -> String -> NSString -> NSString
-- containsChar :: Char -> NSPredicate
on allReplaced(needle, replacement, haystack)
on containsChar(c)
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 '" & c & "'"))
predicateWithFormat:("self contains '" & s & "'"))
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 containsChar
end dictFromZip




-- filteredLines :: String -> NString -> [a]
-- filteredLines :: String -> NSString -> [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 392: Line 404:
predicateWithFormat:predicateString)
predicateWithFormat:predicateString)
set array to its (NSArray's ¬
set array to its (NSArray's ¬
arrayWithArray:(s's componentsSeparatedByString:("\n")))
arrayWithArray:(s's componentsSeparatedByString:(linefeed)))
end tell
end tell