Reply to topic  [ 2 posts ] 
Create Word list 
Author Message
User avatar

Joined: 2004-12-14 07:54:49
Posts: 156
Location: Düsseldorf Germany
Hi there nise people,

is there a word list macro, that works with german text in a german version of Nisus Writer?
I need a macro, that counts each word of a document and displays the number of occurences.

Best regards, Matze


2014-10-15 05:44:33
Profile WWW
User avatar

Joined: 2004-12-14 07:54:49
Posts: 156
Location: Düsseldorf Germany
Stupid me. I should have read the other Subjects first ...
capvideo has created a Perl-Script, which I just had to translate here and there.

For any german Nisus User, who needs this script as well:

# Get the current document
$document = Document.active

# Get all the text (but not headers or tables)
$text = $document.text

# Count them
$words = ''
Begin Perl
   #sort subroutine to sort by frequency in descending order
   sub byFrequency {
      $words{$b} <=> $words{$a};
   }

   #break text into individual words
   @words = $text =~ /(\w+(?:'\w+)*)/g;

   #count each occurence in hash
   foreach $word (@words) {
      #normalize text
      $word = lc($word);
      #increment frequency count for this word
      $words{$word}++;
   }

   #sort the words
   @words = keys %words;
   @sortedWords = sort byFrequency @words;

   #construct the frequency table
   foreach $word (@sortedWords) {
      $frequency = $words{$word};
      $words .= "$word:\t$frequency\n";
   }
End

#create new document with frequency table
$frequency = Document.newWithText $words

#format table
Bearbeiten:Auswählen:Alles Auswählen
Tabelle:In Tabelle konvertieren
Tabelle:An Inhalte anpassen

$emptyEdges = LineAttributes.newInvisible
Tabelle:Auswählen:Tabelle
$table = $frequency.tableSelection
$table.applyLineAttributesToEdges $emptyEdges, "All"

#deselect table
Select Start

A big THANK YOU capvideo!!

Matze


2014-10-15 06:35:12
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software