Solved

Real Word Count Utility

Posted on 1998-10-13
14
215 Views
Last Modified: 2006-11-17
Does anyone have (know of) a tool or program that will allow me to count the number of words in an HTML file?  I don't want all the tags counted, just the words that would appear in the browser.  

Our situation here is that we have documents coded in HTML that have to be translated into other languages.  The rate for translations comes down to a cost per word.  It would be beneficial if we had a utility that would examine all of the HTML files in a given directory tree and give us a total word count that applies to the words that need to be translated.

Any help is greatly appreciated.

Lankford
0
Comment
Question by:lankford
  • 5
  • 4
  • 2
  • +3
14 Comments
 
LVL 4

Expert Comment

by:raoool
ID: 1838703
What platform?

TextPad (Wintel -- www.textpad.com) has a word count which could probably be scripted (has its own macro) to run through a batch of files. The removing tags thing could be done with a SaveAs text from a browser (or also, likely, your HTML editor). BBEdit on a Mac has a remove tags function.

Hope this helps.


On a Mac, BBedit provides 'remove tags' and I THINK it's got a word count... TextPa

Hope this helps!
0
 

Expert Comment

by:talley
ID: 1838704
We use Translation Manager V2.0 from IBM.
It has markup tables that handle the tags and do not include them in word counts.

also...
sed 's/<[^>]*>//g' index.html  will strip out tags.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1838705
that sed script could be fooled by comments, scripts, and tags spanning more than one line
0
 

Author Comment

by:lankford
ID: 1838706
Let me open this up again.  I have heard that the word count feature in Microsoft Word will count the words correctly in an HTML document.  Can this funtion be used inside of a word macro and be applied to each of the files in a given directory?

Lankford
0
 
LVL 28

Expert Comment

by:sybe
ID: 1838707
It could be written in perl quite easily. I bet that ozo (he's very active in the perl area) would not need more then half an hour to make it. Scan a whole directory at once, and for each file give the number of words, excluding the HTML-tags.
It would take me a lot more time, but still I would choose to write such a thing in perl.
0
 

Expert Comment

by:talley
ID: 1838708
In my test it was never fooled by tags over more than one line...
beginnign with < and ending with > ...
I do agree that it is not the best answer..the BEST answer is to use TM2, but most people want things for free and dislike paying for software.
0
 
LVL 4

Expert Comment

by:mcix
ID: 1838709
You could use  

wordCount = ActiveDocument.ComputeStatistics(Statistic:=wdStatisticWords)

To obtain an accurate Word Count for an HTML document using word.

However, this method is terribly inefficient.

There is a better way using C++, Look at this article:

http://support.microsoft.com/support/kb/articles/q186/8/98.asp


0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:mcix
ID: 1838710
It looks something like this in Word:

Public Function ComputeWordCounts(vstrPath As String,vstrSpec As String)

Dim mwrdDocument As Word.Document
Dim mstrCurrentFile As String

mstrCurrentFile = Dir(vstrPath & vstrSpec)
Do While mstrCurrentFile <> ""
    Documents.Open vstrPath & mstrCurrentFile
    wordCount = ActiveDocument.ComputeStatistics(Statistic:=wdStatisticWords)
    MsgBox ActiveDocument.Name & " has " & wordCount
    ActiveDocument.Close wdDoNotSaveChanges
    mstrCurrentFile = Dir
Loop

End Function

ComputeWordCounts "C:\SomeDirectory\" ,"*.HTM"

This will be slow, because Word will Open Each file that meets the criteria.

 
0
 

Author Comment

by:lankford
ID: 1838711
mcix, that works for me.  Change your comment to an answer and you get the points.

Lankford
0
 
LVL 4

Accepted Solution

by:
mcix earned 50 total points
ID: 1838712
Glad it works...

Mark
0
 

Author Comment

by:lankford
ID: 1838713
I liked your response.  

The only significant change I made was to use the Application.FileSearch object instead of the Visual Basic Dir command.  FileSearch is a little more flexible.  I was able to specify files matching *.htm and *.html and have it search sub directories too.

It is slow, but everyone around here who needs the function already has word and can let this run at night or whenever.

Thanks again for the response.

Lankford
0
 
LVL 4

Expert Comment

by:mcix
ID: 1838714
Do you mind sharing your code?
0
 

Author Comment

by:lankford
ID: 1838715
What is your e-mail address?  I'll mail the entire DOC file to you.

Lankford
0
 
LVL 4

Expert Comment

by:mcix
ID: 1838716
E-Mail is:

marko_justus@hotmail.com

Thanks,

Mark
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now