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

130

Likes

translate

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

Adobe Community Professional , 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...

Likes

translate

Translate

Translate
Adobe Community Professional ,
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 

Likes

translate

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
Adobe Community Professional ,
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

 

Likes

translate

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!

Likes

translate

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
Adobe Community Professional ,
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();
}

Likes

translate

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
Adobe Community Professional ,
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.

Likes

translate

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