Re: Capitilization and OSX dictionary
Re: Capitilization and OSX dictionary
- Subject: Re: Capitilization and OSX dictionary
- From: has <email@hidden>
- Date: Sat, 20 Apr 2002 16:50:08 +0100
Matthew Stuckwisch wrote:
>
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:
======================================================================
on getPhrase(theString)
try
set thePara to some paragraph of theString
set wordCount to count thePara's words
set a to random number from 1 to wordCount
set b to random number from a to wordCount
thePara's text (word a) thru (word b)
on error number -1728 -- trap and retry if thePara contains no words
getPhrase(theString)
end try
end getPhrase
======================================================================
The above code assumes the string doesn't contain any individual paragraphs
over 32KB, as those will choke AS's 'word' keyword. Otherwise it works
fine; even on large strings (as long as you've got the memory). To improve
its speed, I suggest replacing the 'random number' osax calls with calls to
Michael Sullivan's pseudoRand library instead (see AppleMods over at
macscripter).
--
>
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"}
>
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.
HTH
has
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
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.