NISUS Archives

July 2016

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show HTML Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Wed, 27 Jul 2016 10:40:46 +0900
Content-Type:
multipart/alternative
Parts/Attachments:
text/plain (2789 bytes) , text/html (9 kB)
What I meant by “not difficult” is that it’s not a problem to create a macro which will reverse the words. The question is whether that will solve the problem. The macro will be a solution if the words are indeed physically reversed. Just as others pointed out, I would have suspected that this is somehow the result of some special characters which cause the words to appear reversed.

But now taking the cue from Bob’s suggestion, I’m providing here a macro which looks for stretches of words separated by spaces. For each stretch, it will reverse the words in that stretch. It *will* modify the file, so use it on a copy. (But running it twice, should restore the file, knock on wood). Here’s the macro. I’ll send a macro file to Abdassamad directly.

[Caveat: I’m assuming that the ‘\w’ wildcard works for the relevant script(s). Same for the space. Otherwise the find expression will need to be adjusted. Arabists feel free to let me know whether this works or not.]

/* Macro Reverse Words in Sentence
written for Abdassamad Clarke from the Nisus List
p. spaelti, 2016.7.27
*/
$doc = Document.active
# Extract the stretches of words separated by spaces
# The stretch should start and end with a word and have at least two words
$sels = $doc.text.find '\w+ [\w ]*\w', 'Ea'
$stretches = $sels.arrayByMakingValuesDoCommand 'subtext'
# Reverse all the stretches
$results = Array.new
foreach $stretch in $stretches
$words = $stretch.split(' ')
$revWords = Array.new
while $words.count
$revWords.push $words.pop
end
$results.push $revWords.join(' ')
end
# Replace each stretch with the reversed stretch
foreach $i, $sel in $sels
$sel.text.replaceInRange $sel.range, $results[$i]
end
/* End of macro */




> On 2016 Jul 27, at 08:18, Bob Stern <[log in to unmask]> wrote:
> 
>> On Jul 21, 2016, at 7:36 PM, Philip Spaelti <[log in to unmask]> wrote:
>> 
>> it is not difficult to write a macro to reverse the order of words on a line, but one really wonders how such a file came about.
> 
> 
> Philip:  If you're feeling more ambitious than me and want to tackle this for Abdassamad, his and Erik Richard's subsequent posts state that the delimiter is an "end of sentence character".   One approach would be to use the Find command to step through the document one sentence at a time; use the split command, with a space as delimiter, to create an array; then output the array in reverse order.
> 
> Abdassamad:  I expect Martin could write such a macro much faster than any of us if you post your question on the Nisus Macros web forum.  Be sure to clarify what "end of sentence" characters may occur in the document.
> 
> http://www.nisus.com/forum/viewforum.php?f=17
> 
> Bob

Philip Spaelti
[log in to unmask]







ATOM RSS1 RSS2