edu.northwestern.at.wordhoard.model
Class WorkPart

java.lang.Object
  extended by edu.northwestern.at.wordhoard.model.WorkPart
All Implemented Interfaces:
CanCountWords, CanGetRelFreq, GroupingObject, HasTag, PersistentObject, SearchCriterion, SearchDefaults
Direct Known Subclasses:
Work

public class WorkPart
extends java.lang.Object
implements PersistentObject, CanCountWords, GroupingObject, SearchDefaults, SearchCriterion, CanGetRelFreq, HasTag

A work part.

Works are divided into parts which form a tree.

Here's some examples of how works might be divided into parts:

Each work part has the following attributes:

Note that each work and work part has both a short title and a full title. The different titles are used in different contexts. For example, for Shakespeare's Hamlet, the full title is "Hamlet, Prince of Denmark", while the short title is just "Hamlet". The full title of act 1, scene 2 is "Act 1, Scene 2", while the short title is just "Scene 2".

The tag is required. It permanently and uniquely identifies the work part across all corpora. It may be used to refer to the work part from outside the object model. It is guaranteed not to change across versions of the object model. For example, the tag for Hamlet (the root of the work part tree for Hamlet) is "sha-ham", and the tag for Hamlet Act 3, Scene 2 is "sha-ham-3-2".

The path tag is optional but usually present. Path tags are used to build short "path" strings that identify parts - e.g., "ham.3.2" for Hamlet Act 3, Scene 2, or "can.mil.p" for the prologue to The Miller's Tale.


Constructor Summary
WorkPart()
          Creates a new work part.
 
Method Summary
 void addChild(WorkPart child)
          Adds a child.
 void addTranslation(java.lang.String name, TextWrapper translation)
          Adds a translation.
 void appendDescendants(java.util.List list)
          Appends all of the descendants to a list.
 void appendDescendantsWithText(java.util.List list)
          Appends all of the descendants which have text to a list.
 void appendDescription(TextLine line, FontInfo romanFontInfo, FontInfo[] fontInfo)
          Appends a description to a text line.
 boolean equals(java.lang.Object obj)
          Returns true if some other object is equal to this one.
 java.util.List getAvailableTranslations()
          Gets the available translations.
 WorkPart getChildByShortTitle(java.lang.String title)
          Gets a child by short title.
 java.util.List getChildren()
          Gets the children.
 WorkPart getFirstDescendantWithText()
          Gets the first descendant part with text.
 java.lang.String getFullTitle()
          Gets the full title.
 Spelling getGroupingSpelling(int numHits)
          Gets the spelling of the grouping object.
 boolean getHasChildren()
          Returns true if this part has any children.
 boolean getHasStanzaNumbers()
          Returns true if the text has stanza numbers.
 java.lang.Long getId()
          Gets the unique id.
 java.lang.Class getJoinClass()
          Gets the join class.
 int getNumChildren()
          Gets the number of children.
 int getNumLines()
          Gets the number of lines.
 int getNumWords()
          Gets the number of words.
 int getNumWorkPartsTree()
          Gets the number of work parts in the subtree rooted at this part.
 WorkPart getParent()
          Gets the parent.
 java.lang.String getPath()
          Gets the path string for the part.
 java.lang.String getPathTag()
          Gets the path tag.
 TextWrapper getPrimaryText()
          Gets the primary text.
 float getRelFreq(int count)
          Gets the relative frequency of a word count.
 java.lang.String getReportPhrase()
          Gets the report phrase.
 SearchCriterion getSearchDefault(java.lang.Class cls)
          Gets a search criterion default value.
 java.lang.String getShortTitle()
          Gets the short title.
 java.lang.String getTag()
          Gets the tag.
 TaggingData getTaggingData()
          Gets the tagging data flags.
 java.util.Map getTranslations()
          Gets the translation map.
 java.lang.String getWhereClause()
          Gets the Hibernate where clause.
 Work getWork()
          Gets the work.
 int getWorkOrdinal()
          Gets the work ordinal.
 int hashCode()
          Returns a hash code for the object.
 boolean isActive()
          Returns active state of item.
 void removeChild(WorkPart child)
          Removes a child.
 void setActive(boolean isActive)
          Sets active state of item.
 void setArg(org.hibernate.Query q, org.hibernate.Session session)
          Sets the Hibernate query argument.
 void setFullTitle(java.lang.String fullTitle)
          Sets the full title.
 void setHasStanzaNumbers(boolean hasStanzaNumbers)
          Sets the has stanza numbers flag.
 void setId(java.lang.Long id)
          Sets the unique id.
 void setNumLines(int numLines)
          Sets the number of lines.
 void setNumWords(int numWords)
          Sets the number of words.
 void setPathTag(java.lang.String pathTag)
          Sets the path tag.
 void setPrimaryText(TextWrapper primaryText)
          Sets the primary text.
 void setShortTitle(java.lang.String shortTitle)
          Sets the short title.
 void setTag(java.lang.String tag)
          Sets the tag.
 void setTaggingData(TaggingData taggingData)
          Sets the tagging data flags.
 void setWork(Work work)
          Sets the work.
 void setWorkOrdinal(int workOrdinal)
          Sets the work ordinal.
 java.lang.String toString()
          Gets a string representation of the part.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WorkPart

public WorkPart()
Creates a new work part.

Method Detail

getId

public java.lang.Long getId()
Gets the unique id.

Specified by:
getId in interface PersistentObject
Returns:
The unique id.

setId

public void setId(java.lang.Long id)
Sets the unique id.

Parameters:
id - The unique id.

getTag

public java.lang.String getTag()
Gets the tag.

Specified by:
getTag in interface HasTag
Returns:
The tag, or null if none.

setTag

public void setTag(java.lang.String tag)
Sets the tag.

Parameters:
tag - The tag, or null if none.

getPathTag

public java.lang.String getPathTag()
Gets the path tag.

Returns:
The path tag.

setPathTag

public void setPathTag(java.lang.String pathTag)
Sets the path tag.

Parameters:
pathTag - The path tag.

getShortTitle

public java.lang.String getShortTitle()
Gets the short title.

Returns:
The short title.

setShortTitle

public void setShortTitle(java.lang.String shortTitle)
Sets the short title.

Parameters:
shortTitle - The short title.

getFullTitle

public java.lang.String getFullTitle()
Gets the full title.

Returns:
The full title.

setFullTitle

public void setFullTitle(java.lang.String fullTitle)
Sets the full title.

Parameters:
fullTitle - The full title.

getTaggingData

public TaggingData getTaggingData()
Gets the tagging data flags.

Returns:
Tagging data flags.

setTaggingData

public void setTaggingData(TaggingData taggingData)
Sets the tagging data flags.

Parameters:
taggingData - Tagging data flags.

getParent

public WorkPart getParent()
Gets the parent.

Returns:
The parent work part.

getWork

public Work getWork()
Gets the work.

Returns:
The work.

setWork

public void setWork(Work work)
Sets the work.

Parameters:
work - The work.

getChildren

public java.util.List getChildren()
Gets the children.

Returns:
The children as an unmodifiable list.

getChildByShortTitle

public WorkPart getChildByShortTitle(java.lang.String title)
Gets a child by short title.

Parameters:
title - Title.
Returns:
Child work part with specified short title, or null if none.

getHasChildren

public boolean getHasChildren()
Returns true if this part has any children.

Returns:
True if part has children.

addChild

public void addChild(WorkPart child)
Adds a child.

The new child is added at the end of the ordered list of children.

Parameters:
child - The new child.

removeChild

public void removeChild(WorkPart child)
Removes a child.

Parameters:
child - The child to remove.

getNumChildren

public int getNumChildren()
Gets the number of children.

Returns:
The number of children.

getPrimaryText

public TextWrapper getPrimaryText()
Gets the primary text.

Returns:
The primary text, or null if none.

setPrimaryText

public void setPrimaryText(TextWrapper primaryText)
Sets the primary text.

Parameters:
primaryText - The primary text for the work part.

getTranslations

public java.util.Map getTranslations()
Gets the translation map.

Returns:
A map from translation names (e.g., "English") to text wrappers for the translations.

addTranslation

public void addTranslation(java.lang.String name,
                           TextWrapper translation)
Adds a translation.

Parameters:
name - The name of the translation (e.g., "English").
translation - The text of the translation.

getAvailableTranslations

public java.util.List getAvailableTranslations()
Gets the available translations.

Returns:
List of all available translations in this part or any of its descendants, enumerated in the same order as in the owning corpus.

getNumWorkPartsTree

public int getNumWorkPartsTree()
Gets the number of work parts in the subtree rooted at this part.

Returns:
Number of work parts in subtree.

getWorkOrdinal

public int getWorkOrdinal()
Gets the work ordinal.

Returns:
The ordinal of the part within its work.

setWorkOrdinal

public void setWorkOrdinal(int workOrdinal)
Sets the work ordinal.

Parameters:
workOrdinal - The ordinal of the part within its work.

getNumLines

public int getNumLines()
Gets the number of lines.

Returns:
Number of lines in subtree rooted at this part.

setNumLines

public void setNumLines(int numLines)
Sets the number of lines.

Parameters:
numLines - Number of lines in subtree rooted at this part.

getNumWords

public int getNumWords()
Gets the number of words.

Returns:
Number of words in subtree rooted at this part.

setNumWords

public void setNumWords(int numWords)
Sets the number of words.

Parameters:
numWords - Number of words in subtree rooted at this part.

getHasStanzaNumbers

public boolean getHasStanzaNumbers()
Returns true if the text has stanza numbers.

Returns:
True if the text has stanza numbers.

setHasStanzaNumbers

public void setHasStanzaNumbers(boolean hasStanzaNumbers)
Sets the has stanza numbers flag.

Parameters:
hasStanzaNumbers - True if the text has stanza numbers.

getRelFreq

public float getRelFreq(int count)
Gets the relative frequency of a word count.

Specified by:
getRelFreq in interface CanGetRelFreq
Parameters:
count - Word count.
Returns:
10,000 times count / number of words in part.

getFirstDescendantWithText

public WorkPart getFirstDescendantWithText()
Gets the first descendant part with text.

Returns:
The first descendant part with text, or null if none.

appendDescendantsWithText

public void appendDescendantsWithText(java.util.List list)
Appends all of the descendants which have text to a list.

Parameters:
list - The list.

appendDescendants

public void appendDescendants(java.util.List list)
Appends all of the descendants to a list.

Parameters:
list - The list.

getPath

public java.lang.String getPath()
Gets the path string for the part.

Returns:
The path string.

getSearchDefault

public SearchCriterion getSearchDefault(java.lang.Class cls)
Gets a search criterion default value.

Specified by:
getSearchDefault in interface SearchDefaults
Parameters:
cls - Model class of search criterion.
Returns:
Default value for search criterion.

getJoinClass

public java.lang.Class getJoinClass()
Gets the join class.

Specified by:
getJoinClass in interface SearchCriterion
Returns:
The join class, or null if none.

getWhereClause

public java.lang.String getWhereClause()
Gets the Hibernate where clause.

Specified by:
getWhereClause in interface SearchCriterion
Returns:
The Hibernate where clause.

setArg

public void setArg(org.hibernate.Query q,
                   org.hibernate.Session session)
Sets the Hibernate query argument.

Specified by:
setArg in interface SearchCriterion
Parameters:
q - Hibernate query.
session - Hibernate session.

appendDescription

public void appendDescription(TextLine line,
                              FontInfo romanFontInfo,
                              FontInfo[] fontInfo)
Appends a description to a text line.

Specified by:
appendDescription in interface SearchCriterion
Parameters:
line - Text line.
romanFontInfo - Roman font info.
fontInfo - Array of font info indexed by character set.

getReportPhrase

public java.lang.String getReportPhrase()
Gets the report phrase.

Specified by:
getReportPhrase in interface GroupingObject
Returns:
The report phrase "in".

getGroupingSpelling

public Spelling getGroupingSpelling(int numHits)
Gets the spelling of the grouping object.

Specified by:
getGroupingSpelling in interface GroupingObject
Parameters:
numHits - Number of hits.
Returns:
The spelling of the grouping object.

toString

public java.lang.String toString()
Gets a string representation of the part.

Overrides:
toString in class java.lang.Object
Returns:
The full title.

equals

public boolean equals(java.lang.Object obj)
Returns true if some other object is equal to this one.

The two work parts are equal if their works and their work ordinals are equal.

Specified by:
equals in interface GroupingObject
Overrides:
equals in class java.lang.Object
Parameters:
obj - The other object.
Returns:
True if this object equals the other object.

hashCode

public int hashCode()
Returns a hash code for the object.

Specified by:
hashCode in interface GroupingObject
Overrides:
hashCode in class java.lang.Object
Returns:
The hash code.

isActive

public boolean isActive()
Returns active state of item.

Returns:
The isActive.

setActive

public void setActive(boolean isActive)
Sets active state of item.

Parameters:
isActive - Active state.