Re: Capitilization and OSX dictionary
Re: Capitilization and OSX dictionary
- Subject: Re: Capitilization and OSX dictionary
- From: Matthew Stuckwisch <email@hidden>
- Date: Sat, 20 Apr 2002 11:32:24 -0500
Okay, this is probably not entirely necessary for my app, but it would be
a nice nuance to have (and I post here instead of AS Studio because this
doesn't deal with the interface).
I did the following: set theReturn to do shell script "perl " & POSIX
path of (path to me) & "/Contents/Resources/random.pl"
random.pl is a perl script designed to access the main two dictionary
files for OSX and randomly choose a word or phrase from them
(AppleScript
can't handle over 5000 items in a list...no way it can do over 230 000).
<squelch> AppleScript can handle >5000 items in a list just fine. It just
can't _create_ lists of >4000 items without barfing; to build big lists
you
have to create several smaller lists and then concatenate them.
As for creating a 230 000 item list, I don't think you ever want to make
such a huge ram-hogging beast in the first place. Better to keep your data
as a simple string and work with that. For example, the following code
will
extract a random word or phrase from a string:
I'm stealing a random word from OSX's dictionary ;-)
Its got over 230 000 words, return delimitted, not to mention I'm joining
the single words dictionary with the two words+ one (/usr/shared/dict/web2[
a]) and that's questionable if AS could do that one. Even if AS could
theoretically handle it, the memory part as you mentioned would be
horrendous.
Any quick and dirty way to capitalize words that should be (eg, no "in,
of,
a, an, the" if they're not at the beginning) sans OSAX?
Take an existing capitalisation function and add a list of excepted words
to it. You'll find one such beast, capitaliseString(), in the stringLib
library on my site. All you'd need to do is modify the middle tell block
a
bit:
======================================================================
tell its first word
if it is in exceptionList then
set tempList's end to it
else
set AppleScript's text item delimiters to its first character
tell _currentCharset
(its lowerCaseChars's first text item's length) + 1
set tempList's end to its upperCaseChars's character result
end tell
if wordLength is not 1 then set tempList's end to its text 2
[NO-BREAK]thru -1
end if
end tell
======================================================================
and add a list of excepted words:
property exceptionList : {"in", "of", "a", "an", "the"}
Thanks, I'll probably try this one.
Of course, I'm probably going to get an
answer so simple I'm going to feel even stupider than I already do after
today (but that's an entire 'nother story...too long for lists).
If you're partially using Perl already, why don't you use it for the
entire
job? Text munging is supposed to be one of its big strengths after all.
Besides, Perl has modules for everything; I wouldn't be surprised if you
could get all the components you need straight off the shelf.
I didn't say I knew perl now did it? ;-)
A friend wrote the code for me. I suppose I could ask him if he could get
it in the perl script for me... *goes and asks*
Matthew Stuckwisch
[AIM/MSN]{GuifaSwimmer} | [Yahoo!]{SapphireTree} | [ICQ]{137477701}
[IRC]{guifa / G}(esperNET / irc.massinova.com)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.