Re: Project scope - is it worth doing?
Re: Project scope - is it worth doing?
- Subject: Re: Project scope - is it worth doing?
- From: email@hidden
- Date: Wed, 28 Feb 2001 01:27:02 -0500
On Mon, 26 Feb 2001 16:11:53 -0800, Doug Messick <email@hidden> asked,
>
I help edit a local non-profit newsletter, and get article submissions
>
(plain text) from various sources. I have to go through these in search of
>
animal names, and change the first reference to each to be the Common name
>
followed by Scientific name. I have a text file containing the common names
>
of 500 animals with their corresponding scientific names which I manually
>
look through for reference at the moment.
I'd use RegEx Commands. An example is,
to lineaify in scientificName into article beside commonName
set namePattern to "(\\<" & commonName & "\\>)(.*)"
REReplace article with "\\1 " & scientificName & "\\2" pattern namePattern
separator "~" -- watch out for line-wrap here.
return result
end lineaify
Key features of this regular expression replacement:
\\< and \\> represent the beginning and end of a word. So, "\\<dog\\>"
matches dog but not doggerel or boondoggle.
\\1 is replaced by the part of the match that corresponds to the first
subexpression; \\2 is replaced by the part of the match that corresponds to the
second subexpression. Subexpressions are the parts in the parentheses:
"(\\<dog\\>)" and "(.*)"
The second subexpression, (.*), matches all the rest of the text, so the
replacement only affects the first occurrence of "dog".
The use of "~" as a separator: you want a character that does not appear in
your text anywhere. Normally I use a Mac-specific high-8th-bit character, but
the list server won't pass such a character. Just pick something that you are
guaranteed won't appear in the text. If you have no preference, I'd suggest
option-5 (infinity sign), since that character isn't part of the ISO-8859-1
character set that Internet mail uses.
If you want a vanilla replacement approach, without scripting additions, you'll
need something like this.
to lineaify in scientificName into article beside commonName
set {oldTids, applescript's text item delimiters} to {applescript's text
item delimiters, commonName}
set pieces to text items of the article
set item 2 of pieces to (scientificName & item 2 of pieces)
return pieces as string
end lineaify
In this case, you have to worry about word boundaries. So you might call,
lineaify in "(canis familiaris) " into articleRef beside " dog "
Note that I put spaces on either side of "dog", so I wouldn't replace "doggerel"
or "boondoggle". But you'll have to also consider occurrences at the beginning
and end of lines, and with punctuation after, like, "Spot was a dog, with a wet
nose." Also, you'll need to worry about capitalized words, like, "Dog play
areas must include Frisbees and sticks to fetch." For more general handling of
word spacing and similar issues, you really need to use regular expressions and
not just simple search and replace.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden