Re: limiting numeric runs
Re: limiting numeric runs
- Subject: Re: limiting numeric runs
- From: julifos <email@hidden>
- Date: Fri, 10 Jan 2003 15:25:47 +0100
>
So, here's real data sampled from a plist...
>
>
"<dict>
>
<key>Balance</key>
>
<real>0.071404993534088135</real>
>
<key>DeviceLevels</key>
>
<array>
>
<real>0.76713436841964722</real>
>
<real>0.82872772216796875</real>
>
</array>
>
<key>Level</key>
>
<real>0.83050847053527832</real>
>
</dict>
>
</dict>
>
</dict>
>
</dict>"
>
>
When I posted the question, I was trying to do the limiting after
>
other parsing. Since then, I realized my folly and do the limiting
>
first based on the tags for reals and so I no longer have to loop
>
through irrelevant data; only the reals. I still use the same method I
>
posted previously, but the speed over a large plist with no reals is
>
immeasurably small and with a reasonable number of reals it is just
>
measurably small! : )
>
>
here's the current version If anyone wants to critique it...
>
>
on LimitReals(inputText, runLengthLimit)
>
set AppleScript's text item delimiters to "<real>"
>
set inputText to text items of inputText
>
set numeralRun to 0
>
repeat with i from 2 to length of inputText
>
set AppleScript's text item delimiters to "</real>"
>
set thisWordList to text items of item i of inputText
>
set thisw to item 1 of thisWordList
>
if length of thisw > runLengthLimit then
>
set AppleScript's text item delimiters to ""
>
set thisw to characters of thisw
>
set numeralRun to 0
>
repeat with z from 1 to length of thisw
>
set thischar to item z of thisw
>
if thischar is in {"1", "2", "3", "4", "5", "6", "7", "8", "9",
>
"0"} then
>
set numeralRun to numeralRun + 1
>
if numeralRun > runLengthLimit then set item z of thisw to ""
>
else
>
set numeralRun to 0
>
end if
>
end repeat
>
set thisw to thisw as string
>
end if
>
set item 1 of thisWordList to thisw
>
set AppleScript's text item delimiters to "</real>"
>
set thisWordList to thisWordList as string
>
set item i of inputText to thisWordList
>
end repeat
>
set AppleScript's text item delimiters to "<real>"
>
return inputText as string
>
end LimitReals
>
>
> where you didn't just want the first X characters of a numeric string.
>
> (Right?) but X number of numeric characters from a larger chunk of
>
> mixed
>
> stuff...
>
>
>
> So...
>
>
>
> Your script chrono-timed with "0.033333335072"
>
>
>
> The one below brought that time to "0.016666667536"
>
>
Nice! Unfortunately half the time is still HUGE when processing a large
>
body of text.
If your "real" data is gonna going to be enclosed in a xml document, whith
tags "<real>" & "</real>"... What about 4 times faster? (1000 runs with the
string above)
on LimitReals2(inputText, runLengthLimit)
set AppleScript's text item delimiters to "</real>"
set inputText to text items of inputText
set AppleScript's text item delimiters to {""}
set newtext to {}
repeat with i in inputText
if (offset of "<real>" in i) = 0 then
set newtext to newtext & i
else
set newtext to newtext & ((characters 1 thru ((offset of "." in
i) + runLengthLimit) of i) as text)
end if
end repeat
set AppleScript's text item delimiters to "</real>"
set newtext to newtext as text
set AppleScript's text item delimiters to {""}
newtext
end LimitReals2
JJ
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.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.