|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.northwestern.at.wordhoard.swing.calculator.modelutils.CountMapUtils
public class CountMapUtils
Count map utilities.
Count maps have a String or Spelling key representing items to count and Number values as the counts. In many cases, the Number values are integers, but this is not necessarily the case. For example, a count map may have word spellings as keys and scaled word frequencies (taking on values between 0.0 and 1.0) as Number values.
Constructor Summary | |
---|---|
protected |
CountMapUtils()
Don't allow instantiation but do allow overrides. |
Method Summary | |
---|---|
static void |
addCountMap(java.util.Map destinationMap,
java.util.Map sourceMap)
Add words/counts from one map to another. |
static java.util.Map |
booleanizeCountMap(java.util.Map map)
Convert map values to integer 1 or 0. |
static java.util.Map |
convertKeysToStrings(java.util.Map countMap)
Convert keys in count map to plain strings. |
static java.util.Map |
deepClone(java.util.Map countMap)
Get deep clone of a count map. |
static int |
getCountOfWordsInCommon(java.util.Map countMap1,
java.util.Map countMap2)
Get count of words which two count maps share. |
static java.util.Map |
getCountsFromFile(java.io.File file)
Get the word counts from a file. |
static java.util.Map |
getCountsFromFile(java.lang.String fileName)
Get the word counts from a file. |
static java.util.Map |
getCountsFromReader(java.io.Reader reader)
Get the word counts from a reader. |
static java.util.Map |
getCountsFromString(java.lang.String countsString)
Get the word counts from a string. |
static double[] |
getSummaryCountsFromCountMap(java.util.Map map)
Get summary counts from a count map. |
static double |
getSumOfCrossProducts(java.util.Map countMap1,
java.util.Map countMap2)
Get sum of cross products for counts in two maps. |
static int |
getTotalWordCount(java.util.Map map)
Get total count of words in map. |
static int |
getWordCount(java.util.Map countMap,
java.lang.Object word)
Get count for a specific word form from a count map. |
static java.util.Set |
getWordsFromMap(java.util.Map map)
Get words from a map. |
static java.util.List |
getWordsInCommon(java.util.Map countMap1,
java.util.Map countMap2)
Get list of words which two count maps share. |
static void |
incrementCountMap(java.util.Map destinationMap,
java.util.Map sourceMap)
Increment words/counts in one map from another. |
static void |
saveCountsToFile(java.util.Map countsMap,
java.io.File file)
Save the word counts to a file. |
static void |
saveCountsToFile(java.util.Map countsMap,
java.lang.String fileName)
Save the word counts to a file. |
static java.lang.String |
saveCountsToString(java.util.Map countsMap)
Save the word counts to a string. |
static void |
saveCountsToWriter(java.util.Map countsMap,
java.io.PrintWriter printWriter)
Save the keyed counts to a file. |
static java.util.Map |
scaleCountMap(java.util.Map map,
double scaleFactor)
Scale count entries in count map. |
static java.lang.String[] |
splitKeyedCountString(java.lang.String s)
Split string at tab character. |
static void |
subtractCountMap(java.util.Map destinationMap,
java.util.Map sourceMap)
Subtract words/counts in one map from another. |
static void |
updateWordCountMap(java.lang.Object word,
int count,
java.util.Map countMap)
Updates counts for a word in a map. |
static void |
updateWorkMap(java.lang.Object word,
java.lang.Long workId,
java.util.Map workMap)
Updates works for a word in a map. |
static void |
worksToWorkCounts(java.util.Map map)
Convert work map to work count map. |
static java.util.Map |
worksToWorkCounts(java.util.Map[] maps)
Convert multiple work maps to a single work count map. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected CountMapUtils()
Method Detail |
---|
public static double[] getSummaryCountsFromCountMap(java.util.Map map)
map
- The map with string keys and Number counts
as values.
public static int getTotalWordCount(java.util.Map map)
map
- The map with string keys and Number counts
as values.
public static double getSumOfCrossProducts(java.util.Map countMap1, java.util.Map countMap2)
countMap1
- First count map.countMap2
- Second count map.
public static java.util.Map booleanizeCountMap(java.util.Map map)
map
- Count map to booleanize.
Non-zero counts are converted to integer 1, 0 counts are converted to integer 0.
public static java.util.Map scaleCountMap(java.util.Map map, double scaleFactor)
map
- The count map.scaleFactor
- The double value by which to
multiply each count value in the count map.
public static java.util.Set getWordsFromMap(java.util.Map map)
map
- The map with keys and Number counts
as values.
public static void worksToWorkCounts(java.util.Map map)
map
- The map with string keys and HashSet of work IDs
as values.
On return, map is modified to have work counts in place of hash set for each key, e.g., the hash set is replaced by its size.
public static java.util.Map worksToWorkCounts(java.util.Map[] maps)
maps
- The map withs string keys and HashSet of work IDs
as values.
public static java.lang.String[] splitKeyedCountString(java.lang.String s)
s
- The string to split into a key and a count.
public static java.util.Map getCountsFromReader(java.io.Reader reader) throws java.io.IOException
reader
- The reader.
java.io.IOException
public static java.util.Map getCountsFromFile(java.io.File file) throws java.io.IOException
file
- The input file.
java.io.IOException
public static java.util.Map getCountsFromString(java.lang.String countsString) throws java.io.IOException
countsString
- The input string.
java.io.IOException
public static java.util.Map getCountsFromFile(java.lang.String fileName) throws java.io.IOException
fileName
- The input file name.
java.io.IOException
public static void saveCountsToWriter(java.util.Map countsMap, java.io.PrintWriter printWriter) throws java.io.IOException
countsMap
- The map containing keyed counts.printWriter
- The printWriter specifying the output file.
Each key is output on a separate line followed by a tab and the count.
Example:
aardvark\t25
abacus\t10
...
java.io.IOException
public static void saveCountsToFile(java.util.Map countsMap, java.io.File file) throws java.io.IOException
countsMap
- The map containing keyed counts.file
- The output file.
java.io.IOException
public static void saveCountsToFile(java.util.Map countsMap, java.lang.String fileName) throws java.io.IOException
countsMap
- The map containing keyed counts.fileName
- The output file name.
java.io.IOException
public static java.lang.String saveCountsToString(java.util.Map countsMap) throws java.io.IOException
countsMap
- The map containing keyed counts.
java.io.IOException
public static void addCountMap(java.util.Map destinationMap, java.util.Map sourceMap)
destinationMap
- Destination map.sourceMap
- Source map.
On output, the destination map is updated with words and counts from the source map.
public static void incrementCountMap(java.util.Map destinationMap, java.util.Map sourceMap)
destinationMap
- Destination map.sourceMap
- Source map.
On output, the destination map counts are incremented by one for each word appearing in the source map. If a source word does not already appear in the destination, it is added with a count of one.
public static void subtractCountMap(java.util.Map destinationMap, java.util.Map sourceMap)
destinationMap
- Destination map.sourceMap
- Source map.
On output, the destination map counts are updated by removing the counts for matching words from the source map. If the count goes to zero for any word in the destination, that word is removed from from the destination map.
public static java.util.List getWordsInCommon(java.util.Map countMap1, java.util.Map countMap2)
countMap1
- First count map.countMap2
- Second count map.
public static int getCountOfWordsInCommon(java.util.Map countMap1, java.util.Map countMap2)
countMap1
- First count map.countMap2
- Second count map.
public static int getWordCount(java.util.Map countMap, java.lang.Object word)
countMap
- The word count map.word
- The word text.
public static void updateWordCountMap(java.lang.Object word, int count, java.util.Map countMap)
word
- The word.count
- The word count.countMap
- The word count map. public static void updateWorkMap(java.lang.Object word, java.lang.Long workId, java.util.Map workMap)
word
- The word.workId
- The work ID.workMap
- The map containing work IDs for the word. public static java.util.Map deepClone(java.util.Map countMap)
countMap
- The count map to clone.
public static java.util.Map convertKeysToStrings(java.util.Map countMap)
countMap
- The count map whose keys should be
converted to strings.
Each key element's toString() method is called to convert the key object to a plain text string. Key elements without a toString() method will not be added to the result map. The object values (counts) are left untouched. Note that no key should be null. Null keys will be ignored.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |