NISUS Archives

November 2015

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text 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:
Fri, 6 Nov 2015 22:10:31 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (129 lines)
Hello Nobumi,

thanks for your comments. You are absolutely correct. The empty table is for the unused index. Similarly there is a problem if the indexed string contains carriage return, since I just use the “Convert to Table” command to create the tables. Both of these problems are easily fixed. I’ll send you a copy of the improved macro directly.

best
Philip

> On Nov 6, 2015, at 19:06 , Nobumi Iyanaga <[log in to unmask]> wrote:
> 
> Hello Philip,
> 
> I just tested this one. It does something really wonderful! However, it seems to have to be tested more: it makes a new document with a table (one column, one row) without any content (perhaps is this for the "Default Index" which is empty in my file?); and in some rare cases (when the indexed words cover more than one paragraph??), it makes table rows without any topics. If you are interested, I can send you my file off list, to ask you to improve it.
> 
> But in the current state, it helps me tremendously.
> 
> Thank you very very much!!
> 
> Best regard,
> 
> Nobumi Iyanaga
> Tokyo,
> Japan
> 
>> On Nov 5, 2015, at 10:52 PM, spaelti <[log in to unmask]> wrote:
>> 
>> 
>>> On Nov 5, 2015, at 9:42 , Nobumi Iyanaga <[log in to unmask]> wrote:
>>> 
>>> 2. The second macro would be much more complicated. Here is the situation. I have files for several chapters (one file for each chapter), which are being written and will be finished successively. As the deadline is very soon, I began to work to create indices for each file, beginning with chapter one. These indices being done, I have to create indices for the next files (and finally join all the files, to make big a big file and big indices). To make coherent indices, I have to use those for the first chapter, that is take the same topics, and find the same words, and make indices of the subsequent chapter files with them -- and after that, add other words under other topics for these files...
>>> 
>>> So the macro should take a list of topics (which would be the selected text), and make a list of all the topics, and all the words, etc. associated with each of these topics in a file. Ideally, the result should be a file with a table of two columns, that would look like the following:
>>> 
>>> 	words, etc.			topics
>>> _____________________________________________________
>>> word1|word2|chunk_of_string3		topic
>>> 		etc.			etc.
>>> 
>>> When such a file would be created, I would be able to examine each entry, and make a list of words and topics, so that I would be able to index these words in the new chapter file, at once, with the macro "Index Using Word List (PowerfindPro)" that Philip created for me...
>>> 
>>> Would it be possible to write such a macro?
>>> 
>> 
>> Sure.
>> 
>> # Macro Make Word Lists from Index Topics
>> # v.1.0  2015/11/5
>> #
>> 
>> $doc = Document.active
>> 
>> # Prepare a hash for all the indexes
>> $indexes = Hash.new
>> 
>> # Check all the index styles
>> $indexNames = Text Index Names
>> foreach $indexName in $indexNames
>> 
>> # Prepare a hash for all the topic for a given index
>> $indexTopics = Hash.new
>> 
>> # Go through all the texts of the document and look for indexed items
>> foreach $text in $doc.allTexts
>> $loc = 0
>> while $loc < $text.length
>> $range = $text.rangeOfAttributesAtIndex $loc
>> $topics = $text.attributesAtIndex($loc).textIndexTopicsForStyleName($indexName)
>> 
>> # when we find an indexed item
>> if $topics
>> 
>> # save the selection of the indexed topic in the hash
>> foreach $topic in $topics
>> $sel = TextSelection.new($text,$range)
>> if $indexTopics.definesKey($topic)
>> if $indexTopics{$topic}.lastValue.bound == $sel.location
>> $prev = $indexTopics{$topic}.pop
>> $sel = $prev.unionKissingSelection $sel
>> end
>> $indexTopics{$topic}.push $sel
>> else
>> $indexTopics{$topic} = Array.new $sel
>> end
>> end
>> 
>> end
>> $loc = $range.bound
>> end
>> end
>> 
>> # save the selection hash for the given index
>> $indexes{$indexName} = $indexTopics
>> end
>> 
>> # generate output word list tables
>> # one for each index
>> foreach $indexName in $indexNames
>> $list = Array.new
>> foreach $topic in $indexes{$indexName}.keys
>> foreach $sel in $indexes{$indexName}{$topic}
>> if $topic.count
>> $indexAs = Cast to String $topic
>> $indexAs.replaceAll '", "', ':'
>> $indexAs.replaceAll '^\("', '', 'E'
>> $indexAs.replaceAll '"\)$', '', 'E'
>> else
>> $indexAs = '—'
>> # $indexAs = $sel.substring
>> end
>> $list.push $sel.substring & "\t" & $indexAs
>> end
>> end
>> $list.sort
>> $listDoc = Document.newWithText $list.join("\n") & "\n"
>> $listDoc.text.replaceAll '^(.+\n)\1+', '\1', 'E'
>> Select All
>> Convert to Table
>> end
>> 
>> Philip Spaelti
>> [log in to unmask]
>> 
>> 
>> 
>> 
>> 

Philip Spaelti
[log in to unmask]

ATOM RSS1 RSS2