|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.billpringle.utils.wrputils.WrpWordCount
public class WrpWordCount
This class identifies what words appear in a string and how many. A key string is used to identify the specific entity that is beingn counted. For example, you can count words in several text documents, and report on how many times a given word appears in both documents.
![]() |
![]() |
Unless noted otherwise, all materials available for download from my site are copyrighted by Bill Pringle, and are licensed under a Creative Commons License. |
Nested Class Summary | |
---|---|
class |
WrpWordCount.WordCount
Internal class for word count information |
Field Summary | |
---|---|
protected java.lang.String |
key
unique key |
protected java.io.BufferedReader |
rdr
reader for file |
protected java.util.Vector<WrpWordCount.WordCount> |
words
collection of words |
Constructor Summary | |
---|---|
WrpWordCount()
Default constructor |
|
WrpWordCount(java.lang.String key)
Constructor with key string |
Method Summary | |
---|---|
void |
dump()
Dump the word count information This method is useful for debugging. |
void |
dump(java.io.PrintStream prt)
Dump the word count information using the specified stream |
int |
getCount(int cnt)
Get the word count information for specified word |
int |
getCount(java.lang.String key,
java.lang.String word)
Get the count associated with the given key / word pair. |
java.lang.String |
getKey()
Get the current key string |
java.lang.String |
getKey(int cnt)
Get the key associated with the specified word |
int |
getNumberWords()
Get the number of words that have been found |
java.lang.String |
getWord(int cnt)
Get the specified word |
WrpWordCount.WordCount |
getWordCount(int cnt)
Get the word count information associated with a specific word |
java.lang.String |
lettersOnly(java.lang.String str)
Extract only letters and digits from string, removing punctuation, etc. |
static void |
main(java.lang.String[] args)
Test driver for the WrpWordCount class |
void |
parseFile()
Parse the file using the predefined BufferedReader |
void |
parseFile(java.io.BufferedReader rdr)
Parse a file using the specified reader |
void |
parseFile(java.lang.String fname)
Parse the specified file and count words |
void |
parseString(java.lang.String str)
Parse the specified strings into words |
void |
updateCount(java.lang.String key,
java.lang.String word)
Update count of words. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String key
protected java.io.BufferedReader rdr
protected java.util.Vector<WrpWordCount.WordCount> words
Constructor Detail |
---|
public WrpWordCount()
public WrpWordCount(java.lang.String key)
key
- the key stringMethod Detail |
---|
public void parseFile(java.lang.String fname)
fname
- the name of the file to be readpublic void parseFile(java.io.BufferedReader rdr)
rdr
- the BufferedReader to be usedpublic void parseFile()
public void parseString(java.lang.String str)
str
- the string to parsepublic java.lang.String lettersOnly(java.lang.String str)
str
- the string to extract from
public void updateCount(java.lang.String key, java.lang.String word)
key
- key stringword
- the word whose count is to be updatedpublic int getCount(java.lang.String key, java.lang.String word)
key
- key stringword
- desired word
public int getNumberWords()
public WrpWordCount.WordCount getWordCount(int cnt)
cnt
- which words to extract
public java.lang.String getWord(int cnt)
cnt
- the word number
public int getCount(int cnt)
cnt
- the number of the word
public java.lang.String getKey()
public java.lang.String getKey(int cnt)
cnt
- the number of the word to extract
public void dump()
public void dump(java.io.PrintStream prt)
prt
- the PrintStream to use for the dumppublic static void main(java.lang.String[] args)
args
- command line arguments
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |