Answered
List of words used in document
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!
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!
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
* @9397041 the array to check
* @9397041 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;
}

Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.