• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

List of words used in document

New Here ,
Jan 14, 2021 Jan 14, 2021

Copy link to clipboard

Copied

Hi there, 

 

I am wanting to generate a list of words, punctuation, and frequency. Is there a way to do this through InDesign? or if I would need a script. 

 

Many thanks!

TOPICS
How to

Views

442

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 15, 2021 Jan 15, 2021

Not sure how well this will work on a long document, the list could be written to a text file rather than an alert dialog, but you could try this script:

 

 

alert(wordFrequency());
  
/**
* Displays a list of document words with their usage count
* @Return a string list of word frequency
* 
*/
function wordFrequency(){
    var wList = "Document Word Usage: \n";
    var aw = getAllWords()
    var cArray = []

    for (var i = 0; i < aw.length; i++){
        var cnt = 0;
        var cword = aw[i
...

Votes

Translate

Translate
Community Expert ,
Jan 14, 2021 Jan 14, 2021

Copy link to clipboard

Copied

This isn't a feature of InDesign. Maybe one of the scripters who volunteer here can weigh in.

 

You could also export the text from InDesign and create a word cloud fairly easily. See https://universeofmemory.com/how-to-create-your-own-frequency-list/.

 

I don't see that punctuation is picked up, though. 

 

~Barb 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Not sure how well this will work on a long document, the list could be written to a text file rather than an alert dialog, but you could try this script:

 

 

alert(wordFrequency());
  
/**
* Displays a list of document words with their usage count
* @Return a string list of word frequency
* 
*/
function wordFrequency(){
    var wList = "Document Word Usage: \n";
    var aw = getAllWords()
    var cArray = []

    for (var i = 0; i < aw.length; i++){
        var cnt = 0;
        var cword = aw[i];
        if (!checkItem(cArray, cword)) {
            cArray.push(cword)
            //gets the word count
            for (var j = i; j < aw.length; j++){
                if (aw[j] == cword) {
                    cnt++
                } 
            }
            wList = wList + cword + ": " + cnt.toString() + "\n"
        } 
    } 
    return wList
}


/**
* Get every word in active document
* @Return a string list of words 
* 
*/
function getAllWords(){
    var s = app.activeDocument.stories
    var allWords = []

    for(var i=0; i < s.length; i++){  
        var w = s[i].words; 
        for(var j=0; j < w.length; j++){  
            allWords.push(w[j].contents)
        }  
    } 
    return allWords
}



/**
* Check if an item is in an array
* @Param the array to check 
* @Param the item to look for 
* @Return true if the item is in the array 
* 
*/
function checkItem(a, obj) {
    for (var i = 0; i < a.length; i++) {
        if (a[i] === obj) {
            return true;
        }
    }
    return false;
}

 

 

 

Screen Shot 8.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

Fantastic, that works! 

 

Many thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

This version writes a tab delimited text file to the desktop:

 

var path = Folder.desktop + "/wordusage.txt";
writeText(path, wordFrequency())

/**
* Displays a list of document words with their usage count
* @Return a string list of word frequency
* 
*/
function wordFrequency(){
    var wList = "Document Word Usage: \n";
    var aw = getAllWords()
    var cArray = []

    for (var i = 0; i < aw.length; i++){
        var cnt = 0;
        var cword = aw[i];
        if (!checkItem(cArray, cword)) {
            cArray.push(cword)
            //gets the word count
            for (var j = i; j < aw.length; j++){
                if (aw[j] == cword) {
                    cnt++
                } 
            }
            wList = wList + cword + "\t" + cnt.toString() + "\n"
        } 
    } 
    return wList
}


/**
* Get every word in active document
* @Return a string list of words 
* 
*/
function getAllWords(){
    var s = app.activeDocument.stories
    var allWords = []

    for(var i=0; i < s.length; i++){  
        var w = s[i].words; 
        for(var j=0; j < w.length; j++){  
            allWords.push(w[j].contents)
        }  
    } 
    return allWords
}



/**
* Check if an item is in an array
* @Param the array to check 
* @Param the item to look for 
* @Return true if the item is in the array 
* 
*/
function checkItem(a, obj) {
    for (var i = 0; i < a.length; i++) {
        if (a[i] === obj) {
            return true;
        }
    }
    return false;
}


/**
* Write a text file 
* @Param the file path 
* @Param the text 
* 
*/
function writeText(p,s){
    var file = new File(p);
    file.encoding = 'UTF-8';
    file.open('w');
    file.write(s);
    file.close();
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 17, 2024 Mar 17, 2024

Copy link to clipboard

Copied

LATEST

you are the best, share knowledge in the biggest and best. Thanks. Sometimes they seem like simple things, but when people come along wanting to sell something similar, we know it's not simple. And we also know that it is not simple, because at some point, it required your time and knowledge. Thank you for your generosity in sharing knowledge.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Have a look at TextExporter 4 https://www.rorohiko.com/wordpress/indesign-downloads/textexporter-4/ though it may be overkill for your purposes.

TextExporter 4 can export all the stories of an InDesign document into a single file.

Supported output file formats: Rich Text Format (RTF), InDesign Tagged Text, Text

 

You could use Find/ Change to count the number of a particular punctuation marks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines