|
|||||||||
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.WordCounter
public class WordCounter
A word form counter.
WordCounter wraps a WordHoard model object which can count "words," specifically, spellings, lemmata, speaker gender, parts of speech, prose versus poetry flag, and (eventually) semantic category. Currently wrappable objects include the Corpus, PhraseSet, WordSet, WorkSet, Work, and WorkPart objects. All parts of WordHoard requiring word and work counts should get them through a WordCounter object. WordCounter hides all the ugly details involved in getting counts for the different types of objects.
Field Summary | |
---|---|
static int |
CORPUS
Word counter types for the classes above. |
protected java.lang.Object |
object
The object containing countable words. |
protected int |
objectType
The type of word form counter object. |
static int |
PHRASESET
|
static java.lang.Class[] |
wordFormCounterClasses
The word counter classes. |
static int |
WORDSET
|
static int |
WORK
|
static int |
WORKPART
|
static int |
WORKSET
|
Constructor Summary | |
---|---|
WordCounter(CanCountWords canCountWords)
Create a word form counter for a CanCountWords object. |
|
WordCounter(int anObjectType,
java.lang.Long anObjectId)
Create a word form counter for a specified object type and ID. |
|
WordCounter(int anObjectType,
java.lang.String aTag)
Create a word form counter for a specified object type and tag. |
Method Summary | |
---|---|
boolean |
equals(java.lang.Object object)
Compare another word form object to this one for equality. |
WorkPart[] |
getActualWorkParts()
Return all actual work parts in this object. |
int |
getDistinctWordFormCount(int wordForm)
Get distinct word count for word form type. |
java.lang.Object |
getObject()
Get the word form counter object. |
java.lang.Long |
getObjectId()
Get the word form counter object's persistence Id. |
int |
getObjectType()
Get the word form counter object type. |
java.util.Map[] |
getPhrasesAndCounts(int wordForm)
Get phrases and their counts of a specific word form type. |
Word[] |
getSpan(Word word,
int leftSpan,
int rightSpan)
Get surrounding words of a specified word. |
java.lang.String |
getTag()
Get the tag for an object. |
int |
getTotalWordFormCount(int wordForm)
Get total word count for word form type. |
static WordCounter[] |
getWordCounters()
Get all available word counter types as WordCounter objects. |
static WordCounter[] |
getWordCounters(boolean includeCorpora,
boolean includeWorks,
boolean includeWorkSets,
boolean includeWordSets,
boolean includePhraseSets)
Get all available works, work sets, and corpora as WordCounter objects. |
java.util.Map |
getWordFormCount(Spelling[] words,
int wordForm)
Get counts for several words. |
int |
getWordFormCount(Spelling word,
int wordForm)
Get count of a word form. |
java.util.Map[] |
getWordFormCountByYear(Spelling word,
int wordForm,
boolean usePhrases)
Get word form and its counts by year. |
Word[] |
getWordOccurrences(Spelling word,
int wordForm)
Get word occurrences for a word. |
java.util.Map[] |
getWordsAndCounts(int wordForm)
Get words and their counts of a specific word form type. |
java.util.Map[] |
getWordsAndCounts(int wordForm,
boolean getWorkCounts)
Get words and their counts of a specific word form type. |
java.util.Map[] |
getWordsAndCounts(WordCounter otherCounter,
int wordForm)
Get words and counts for two WordCounter objects. |
int |
getWorkCount()
Get the number of works represented in this word counter. |
int |
getWorkCount(WordCounter otherCounter)
Get the number of works represented in this word counter and another. |
WorkPart[] |
getWorkParts()
Return all work parts in this object. |
Work[] |
getWorks()
Return all works represented in this object. |
int |
hashCode()
Returns a hash code for the object. |
protected java.lang.String |
htmlizeTitle(java.lang.String title)
HTMLize an object title. |
boolean |
isCorpus()
Is word counter a Corpus? |
boolean |
isPhraseSet()
Is word counter a PhraseSet? |
boolean |
isWordSet()
Is word counter a WordSet? |
boolean |
isWork()
Is word counter a Work? |
boolean |
isWorkPart()
Is word counter a work part? |
boolean |
isWorkSet()
Is word counter a WorkSet? |
java.lang.String |
toHTMLString()
Return HTML string form of object. |
java.lang.String |
toHTMLString(boolean useShortName)
Return HTML string form of object. |
java.lang.String |
toString()
Return string form of object. |
java.lang.String |
toString(boolean useShortString)
Return string form of object. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Class[] wordFormCounterClasses
public static final int CORPUS
public static final int PHRASESET
public static final int WORDSET
public static final int WORK
public static final int WORKPART
public static final int WORKSET
protected java.lang.Object object
protected int objectType
Constructor Detail |
---|
public WordCounter(CanCountWords canCountWords)
canCountWords
- The object implementing CanCountWords. public WordCounter(int anObjectType, java.lang.Long anObjectId)
anObjectType
- WordCounter object type.anObjectId
- The object's ID. public WordCounter(int anObjectType, java.lang.String aTag)
anObjectType
- WordCounter object type.aTag
- The object's tag.
Not all WordCounter objects have permanent tags. Only those with permanent tags can be created using this constructor.
Method Detail |
---|
public java.lang.Object getObject()
public int getObjectType()
public java.lang.Long getObjectId()
public java.lang.String getTag()
Not all WordCounter objects have tags. For those that do not, toString() is returned as the tag.
public boolean isCorpus()
public boolean isPhraseSet()
public boolean isWork()
public boolean isWorkPart()
public boolean isWordSet()
public boolean isWorkSet()
public int getWordFormCount(Spelling word, int wordForm)
word
- The word form whose count is desired.wordForm
- The type of word form as specified
in WordForms
.
public java.util.Map getWordFormCount(Spelling[] words, int wordForm)
words
- The words whose counts are desired.wordForm
- The type of word form as specified
in WordForms
.
public java.util.Map[] getWordsAndCounts(int wordForm, boolean getWorkCounts)
wordForm
- The word form as specified in WordForms
.getWorkCounts
- true to get work counts instead of work list
in second result map (see below).
The first map contains each word of the specified word form in the first set of work parts as a key and the count of the appearance of the word in the first set of work parts as a value.
The second map also has the word as the key. If getWorkCounts is true, the value for each word provides the number of works (NOT work parts) in which the word appears as a value. If getWorkParts is false, the value is a hash set containing the work IDs of the works in which the word appears.
public java.util.Map[] getWordsAndCounts(int wordForm)
wordForm
- The word form as specified in WordForms
.
The first map contains each word of the specified word form in the first set of work parts as a key and the count of the appearance of the word in the first set of work parts as a value.
The second map also has the word as the key but provides the number of works (NOT work parts) in which the word appears as a value.
public java.util.Map[] getPhrasesAndCounts(int wordForm)
wordForm
- The word form as specified in WordForms
.
The first map contains each phrase containing the specified word form as a key and the count of the appearance of the phrase as a value.
The second map also has the phrase as the key but provides the number of works (NOT work parts) in which the phrase appears as a value.
public java.util.Map[] getWordsAndCounts(WordCounter otherCounter, int wordForm)
otherCounter
- The other word counter.wordForm
- The word form as specified in WordForms
.
The first map contains each word of the specified word form in the first set of work parts as a key and the count of the appearance of the word in the first set of work parts as a value.
The second map contains each word of the specified word form in the second set of work parts as a key and the count of the appearance of the word in the second set of work parts as a value.
The third map also has the word as the key but provides the number of works (NOT work parts) in which the word appears as a value in either of the two sets of work parts.
This method significantly reduces the query load when the two sets of work parts have common entries.
public int getTotalWordFormCount(int wordForm)
wordForm
- The word form as specified in WordForms
.
public int getDistinctWordFormCount(int wordForm)
wordForm
- The word form as specified in WordForms
.
public java.util.Map[] getWordFormCountByYear(Spelling word, int wordForm, boolean usePhrases)
word
- The word form whose count is desired.wordForm
- The type of word form as specified
in WordForms
.usePhrases
- Analyze phrase counts instead of word counts
if the current object allows this.
public static WordCounter[] getWordCounters(boolean includeCorpora, boolean includeWorks, boolean includeWorkSets, boolean includeWordSets, boolean includePhraseSets)
includeCorpora
- Return corpora.includeWorks
- Return works.includeWorkSets
- Return work sets.includeWordSets
- Return word sets.includePhraseSets
- Return phrase sets.
public static WordCounter[] getWordCounters()
public WorkPart[] getWorkParts()
For a work, the returned array has just one entry for the work. For a work part, the returned array has just one entry for the work part. For a corpus, the returned array usually has more than one entry, one for each work in the corpus. For both Work and Corpus, all the returned WorkPart entries are actually Work objects. For a WorkSet, the returned entries may be a combination of Work and WorkPart objects.
public WorkPart[] getActualWorkParts()
This is what getWorkParts should probably do but does not for historical reasons.
$$$PIB$$$ Need to rectify this with getWorkParts.public Work[] getWorks()
public int getWorkCount()
public int getWorkCount(WordCounter otherCounter)
otherCounter
- The other counter.
public Word[] getWordOccurrences(Spelling word, int wordForm)
word
- The word to look up.wordForm
- The word form.
public Word[] getSpan(Word word, int leftSpan, int rightSpan)
word
- Word for which to get span.leftSpan
- # of words to left of
specified word to retrieve.rightSpan
- # of words to right of
specified word to retrieve.
protected java.lang.String htmlizeTitle(java.lang.String title)
title
- The object title.
public java.lang.String toHTMLString(boolean useShortName)
useShortName
- True to use short object name.
public java.lang.String toHTMLString()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean useShortString)
useShortString
- Return short string.
At present, we only return short strings if requested for Work objects.
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
object
- The other word form object.
Two WordCounter objects are equal if they wrap objects with the same id.
public int hashCode()
hashCode
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |