edu.northwestern.at.wordhoard.swing.calculator.modelutils
Class PhraseSetUtils

java.lang.Object
  extended by edu.northwestern.at.wordhoard.swing.calculator.modelutils.PhraseSetUtils

public class PhraseSetUtils
extends java.lang.Object

Phrase set utilities.


Constructor Summary
protected PhraseSetUtils()
          Don't allow instantiation but do allow overrides.
 
Method Summary
static boolean addPhrases(PhraseSet phraseSet, java.util.Map words, java.util.Map phrases, ProgressReporter progressReporter)
          Add phrases to a phrase set.
static PhraseSet addPhraseSet(java.lang.String title, java.lang.String description, java.lang.String webPageURL, java.lang.String owner, boolean isPublic, java.lang.String query)
          Add a new phrase set.
static PhraseSet addPhraseSet(java.lang.String title, java.lang.String description, java.lang.String webPageURL, java.lang.String owner, boolean isPublic, java.lang.String query, java.util.Map words, java.util.Map phrases, ProgressReporter progressReporter)
          Add a new phrase set with specified phrases.
static PhraseSet addPhraseSet(java.lang.String title, java.lang.String description, java.lang.String webPageURL, java.lang.String owner, boolean isPublic, WordCounter analysisText, java.lang.String query, java.awt.Window parentWindow)
          Add a new phrase set using a specified query.
static boolean deletePhraseSet(PhraseSet phraseSet)
          Delete a phrase set.
static boolean deletePhraseSet(java.lang.String title, java.lang.String owner)
          Delete a phrase set by title.
static boolean deletePhraseSets(PhraseSet[] phraseSets)
          Delete multiple phrase sets.
static boolean deletePhraseSets(PhraseSet[] phraseSets, ProgressReporter progressReporter)
          Delete multiple phrase sets.
static int getDistinctWordFormCount(PhraseSet phraseSet, int wordForm)
          Get distinct word form count in a phrase set.
static java.util.Map[] getPhraseCounts(PhraseSet[] phraseSets, int wordForm)
          Get word form counts in a set of phrase sets.
static java.util.Map[] getPhraseCounts(PhraseSet[] phraseSets, int wordForm, boolean getWorkCounts)
          Get word form counts in a set of phrase sets.
static java.util.Map getPhraseCounts(PhraseSet phraseSet, int wordForm)
          Get phrase counts in a single phrase set.
static Phrase[] getPhrases(PhraseSet phraseSet)
          Get all available phrases in a phrase set as an array.
static PhraseSet getPhraseSet(java.lang.String title)
          Get a phrase set by title.
static PhraseSet getPhraseSet(java.lang.String title, java.lang.String owner)
          Get a phrase set by title.
static PhraseSet[] getPhraseSets()
          Get all available public phrase sets as an array.
static PhraseSet[] getPhraseSets(java.lang.String owner)
          Get all available phrase sets for a specified owner as an array.
static PhraseSet[] getPhraseSets(java.lang.String owner, boolean onlyPrivate)
          Get all available phrase sets for a specified owner as an array.
static int getPhraseSetsCount()
          Get count of all available phrase sets.
static int getPhraseSetsCount(java.lang.String owner)
          Get count of phrase sets for a user.
static int getPhraseSetsCount(java.lang.String owner, boolean onlyPrivate)
          Get count of phrase sets for a user.
static PhraseSet[] getPhraseSetsForLoggedInUser()
          Get phrase sets for logged in user.
static Word[] getSpan(PhraseSet phraseSet, Word word, int leftSpan, int rightSpan)
          Get surrounding words of a specified word in a phrase set.
static java.util.Map[] getWordCounts(PhraseSet[] phraseSets, int wordForm)
           
static java.util.Map[] getWordCounts(PhraseSet[] phraseSets, int wordForm, boolean getWorkCounts)
          Get word form counts in a set of phrase sets.
static java.util.Map getWordCounts(PhraseSet phraseSet, int wordForm)
          Get word counts in a single phrase set.
static java.util.Map getWordFormCount(PhraseSet[] phraseSets, Spelling[] words, int wordForm)
          Get word count for multiple words in a set of phrase sets.
static int getWordFormCount(PhraseSet phraseSet, int wordForm)
          Get total word form count in a phrase set.
static int getWordFormCount(PhraseSet phraseSet, int wordForm, Work work)
          Get total word form count for one work represented in a phrase set.
static java.util.Map getWordFormCount(PhraseSet phraseSet, Spelling[] words, int wordForm)
          Get word count for multiple words in a phrase set.
static int getWordFormCount(PhraseSet phraseSet, Spelling word, int wordForm)
          Get word count in a phrase set.
static int getWordFormCount(PhraseSet phraseSet, Spelling word, int wordForm, Work work)
          Get word count in a phrase set for a specific work.
static int getWordFormPhraseCount(PhraseSet phraseSet, Spelling phrase, int wordForm, Work work)
          Get phrase count in a phrase set for a specific phrase in a work.
static Word[] getWordOccurrences(PhraseSet phraseSet, int wordForm, Spelling word)
          Get word occurrences for a word in a specified phrase set.
static Word[] getWords(PhraseSet phraseSet)
          Get all available words in a phrase set as an array.
static WorkPart[] getWorkParts(PhraseSet phraseSet)
          Get array of all work parts for a phrase set.
static Work[] getWorks(PhraseSet phraseSet)
          Get array of all works for a phrase set.
static java.util.Collection preloadPhrases(PhraseSet phraseSet)
          Preload phrase data.
protected static PhraseSet[] udosToPhraseSets(UserDataObject[] udos)
          Copy UserDataObject array to PhraseSet array.
static boolean updatePhraseSet(PhraseSet phraseSet, java.lang.String title, java.lang.String description, java.lang.String webPageURL, boolean isPublic)
          Update a phrase set.
static boolean updatePhraseSet(PhraseSet phraseSet, java.lang.String title, java.lang.String description, java.lang.String webPageURL, boolean isPublic, java.util.Collection phrases)
          Update a phrase set.
static boolean updatePhraseSet(PhraseSet phraseSet, java.lang.String title, java.lang.String description, java.lang.String webPageURL, boolean isPublic, Phrase[] phrases)
          Update a phrase set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhraseSetUtils

protected PhraseSetUtils()
Don't allow instantiation but do allow overrides.

Method Detail

udosToPhraseSets

protected static PhraseSet[] udosToPhraseSets(UserDataObject[] udos)
Copy UserDataObject array to PhraseSet array.

Parameters:
udos - Array of user data objects, all actually PhraseSet objects.
Returns:
Array of PhraseSet objects.

addPhraseSet

public static PhraseSet addPhraseSet(java.lang.String title,
                                     java.lang.String description,
                                     java.lang.String webPageURL,
                                     java.lang.String owner,
                                     boolean isPublic,
                                     java.lang.String query,
                                     java.util.Map words,
                                     java.util.Map phrases,
                                     ProgressReporter progressReporter)
                              throws DuplicatePhraseSetException
Add a new phrase set with specified phrases.

Parameters:
title - Title for the new phrase set.
description - Description for the new phrase set.
webPageURL - Web page URL for the new phrase set.
owner - The phrase set owner.
isPublic - True if phrase set to be public.
query - The query string generating the phrases.
phrases - Phrases to add to phrase set.
progressReporter - Progress display to update. May be null.
Returns:
PhraseSet object if phrase set added, else null.
Throws:
DuplicatePhraseSetException

addPhraseSet

public static PhraseSet addPhraseSet(java.lang.String title,
                                     java.lang.String description,
                                     java.lang.String webPageURL,
                                     java.lang.String owner,
                                     boolean isPublic,
                                     java.lang.String query)
                              throws DuplicatePhraseSetException
Add a new phrase set.

Parameters:
title - Title for the new phrase set.
description - Description for the new phrase set.
webPageURL - Web page URL for the new phrase set.
owner - The phrase set owner.
isPublic - True if phrase set is to be public.
query - The query string generating the phrases.
Returns:
PhraseSet object if phrase set added, else null.
Throws:
DuplicatePhraseSetException

addPhraseSet

public static PhraseSet addPhraseSet(java.lang.String title,
                                     java.lang.String description,
                                     java.lang.String webPageURL,
                                     java.lang.String owner,
                                     boolean isPublic,
                                     WordCounter analysisText,
                                     java.lang.String query,
                                     java.awt.Window parentWindow)
                              throws DuplicatePhraseSetException,
                                     InvalidCQLQueryException
Add a new phrase set using a specified query.

Parameters:
title - Title for the new phrase set.
description - Description for the new phrase set.
webPageURL - Web page URL for the new phrase set.
owner - The phrase set owner.
isPublic - True if phrase set to be public.
analysisText - Text set from which to extract phrases.
query - Query to select phrases in analysis text.
parentWindow - Parent window.
Returns:
PhraseSet object if phrase set added, else null.
Throws:
DuplicatePhraseSetException
InvalidCQLQueryException

addPhrases

public static boolean addPhrases(PhraseSet phraseSet,
                                 java.util.Map words,
                                 java.util.Map phrases,
                                 ProgressReporter progressReporter)
Add phrases to a phrase set.

Parameters:
phraseSet - The phrase set.
words - Words to add to phrase set.
phrases - Phrases to add to phrase set.
progressReporter - Progress display to update. May be null.
Returns:
true if phrases added successfully.

If this method returns false, the caller should delete the phrase set.


deletePhraseSet

public static boolean deletePhraseSet(PhraseSet phraseSet)
Delete a phrase set.

Parameters:
phraseSet - The phrase set to delete.
Returns:
true if phrase set deleted, false otherwise.

deletePhraseSet

public static boolean deletePhraseSet(java.lang.String title,
                                      java.lang.String owner)
Delete a phrase set by title.

Parameters:
title - The title of the phrase set to delete.
owner - Owner of phrase set.
Returns:
true if phrase set deleted, false otherwise. If the phrase set didn't exist, true is returned.

deletePhraseSets

public static boolean deletePhraseSets(PhraseSet[] phraseSets)
Delete multiple phrase sets.

Parameters:
phraseSets - The phrase sets to delete.
Returns:
true if phrase sets deleted, false otherwise.

deletePhraseSets

public static boolean deletePhraseSets(PhraseSet[] phraseSets,
                                       ProgressReporter progressReporter)
Delete multiple phrase sets.

Parameters:
phraseSets - The phrase sets to delete.
progressReporter - A progress reporter.
Returns:
true if phrase sets deleted, false otherwise.

getPhraseSet

public static PhraseSet getPhraseSet(java.lang.String title,
                                     java.lang.String owner)
Get a phrase set by title.

Parameters:
title - The title of the phrase set to fetch.
owner - The owner of the phrase set to fetch.
Returns:
The phrase set with the requested title, or null if not found.

getPhraseSet

public static PhraseSet getPhraseSet(java.lang.String title)
Get a phrase set by title.

Parameters:
title - The title of the phrase set to fetch.
Returns:
The phrase set with the requested title, or null if not found.

getPhraseSets

public static PhraseSet[] getPhraseSets()
Get all available public phrase sets as an array.

Returns:
All available phrase sets as an array of PhraseSet.

getPhraseSets

public static PhraseSet[] getPhraseSets(java.lang.String owner,
                                        boolean onlyPrivate)
Get all available phrase sets for a specified owner as an array.

Parameters:
owner - Currently logged in owner.
onlyPrivate - True to get only private phrase sets for owner.
Returns:
All available phrase sets as an array of PhraseSet.

getPhraseSets

public static PhraseSet[] getPhraseSets(java.lang.String owner)
Get all available phrase sets for a specified owner as an array.

Parameters:
owner - Currently logged in owner.
Returns:
All available phrase sets as an array of PhraseSet.

getPhraseSetsCount

public static int getPhraseSetsCount(java.lang.String owner,
                                     boolean onlyPrivate)
Get count of phrase sets for a user.

Parameters:
owner - Currently logged in owner.
onlyPrivate - True to count only private phrase sets for owner.
Returns:
Count of phrase sets owned by "owner".

getPhraseSetsForLoggedInUser

public static PhraseSet[] getPhraseSetsForLoggedInUser()
Get phrase sets for logged in user.

Returns:
Phrase sets owned by currently logged in user.

getPhraseSetsCount

public static int getPhraseSetsCount(java.lang.String owner)
Get count of phrase sets for a user.

Parameters:
owner - Currently logged in owner.
Returns:
Count of phrase sets owned by "owner".

getPhraseSetsCount

public static int getPhraseSetsCount()
Get count of all available phrase sets.

Returns:
Count of all available phrase sets.

getPhrases

public static Phrase[] getPhrases(PhraseSet phraseSet)
Get all available phrases in a phrase set as an array.

Parameters:
phraseSet - The phrase set.
Returns:
All available phrases in the phrase set as an array of Phrase.

Returns null if phrase set is null.


preloadPhrases

public static java.util.Collection preloadPhrases(PhraseSet phraseSet)
Preload phrase data.

Parameters:
phraseSet - The phrase set.

Returns null if phrase set is null.


getWords

public static Word[] getWords(PhraseSet phraseSet)
Get all available words in a phrase set as an array.

Parameters:
phraseSet - The phrase set.
Returns:
All available unique words in the phrase set as an array of Word.

Returns null if phrase set is null.


updatePhraseSet

public static boolean updatePhraseSet(PhraseSet phraseSet,
                                      java.lang.String title,
                                      java.lang.String description,
                                      java.lang.String webPageURL,
                                      boolean isPublic,
                                      Phrase[] phrases)
                               throws DuplicatePhraseSetException
Update a phrase set.

Parameters:
phraseSet - The phrase set to update.
title - Title for the phrase set.
description - Description for the phrase set.
webPageURL - Web page URL for the phrase set.
isPublic - True if phrase set is public.
phrases - Array of Phrase entries for phrase set. Set to null to leave current phrase set. Set to empty array to remove current phrases.
Returns:
true if update succeed, false otherwise.
Throws:
DuplicatePhraseSetException

updatePhraseSet

public static boolean updatePhraseSet(PhraseSet phraseSet,
                                      java.lang.String title,
                                      java.lang.String description,
                                      java.lang.String webPageURL,
                                      boolean isPublic,
                                      java.util.Collection phrases)
                               throws DuplicatePhraseSetException
Update a phrase set.

Parameters:
phraseSet - The phrase set to update.
title - Title for the phrase set.
description - Description for the phrase set.
webPageURL - Web page URL for the phrase set.
isPublic - True if phrase set is public.
phrases - Collection of Phrase entries for phrase set.
Returns:
true if update succeed, false otherwise.
Throws:
DuplicatePhraseSetException

updatePhraseSet

public static boolean updatePhraseSet(PhraseSet phraseSet,
                                      java.lang.String title,
                                      java.lang.String description,
                                      java.lang.String webPageURL,
                                      boolean isPublic)
                               throws DuplicatePhraseSetException
Update a phrase set.

Parameters:
phraseSet - The phrase set to update.
title - Title for the phrase set.
description - Description for the phrase set.
webPageURL - Web page URL for the phrase set.
isPublic - True if phrase set is public.
Returns:
true if update succeed, false otherwise.
Throws:
DuplicatePhraseSetException

getWorkParts

public static WorkPart[] getWorkParts(PhraseSet phraseSet)
Get array of all work parts for a phrase set.

Parameters:
phraseSet - The phrase set.
Returns:
Array of WorkPart for all worK parts represented in phrase set.

getWorks

public static Work[] getWorks(PhraseSet phraseSet)
Get array of all works for a phrase set.

Parameters:
phraseSet - The phrase set.
Returns:
Array of Work for all works represented in phrase set.

getWordFormCount

public static int getWordFormCount(PhraseSet phraseSet,
                                   int wordForm,
                                   Work work)
Get total word form count for one work represented in a phrase set.

Parameters:
phraseSet - The phrase set.
wordForm - The word form.
work - The work.
Returns:
Count of the word form in the phrase set.

getWordFormCount

public static int getWordFormCount(PhraseSet phraseSet,
                                   int wordForm)
Get total word form count in a phrase set.

Parameters:
phraseSet - The phrase set.
wordForm - The word form.
Returns:
Count of the word form in the phrase set.

getDistinctWordFormCount

public static int getDistinctWordFormCount(PhraseSet phraseSet,
                                           int wordForm)
Get distinct word form count in a phrase set.

Parameters:
phraseSet - The phrase set.
wordForm - The word form.
Returns:
Count of the distinct word forms in the phrase set.

getWordFormCount

public static int getWordFormCount(PhraseSet phraseSet,
                                   Spelling word,
                                   int wordForm)
Get word count in a phrase set.

Parameters:
phraseSet - The phrase set.
word - The word.
wordForm - The word form.
Returns:
Count of the word form in the phrase set.

getWordFormCount

public static int getWordFormCount(PhraseSet phraseSet,
                                   Spelling word,
                                   int wordForm,
                                   Work work)
Get word count in a phrase set for a specific work.

Parameters:
phraseSet - The phrase set.
word - The word.
wordForm - The word form.
work - The work.
Returns:
Count of the word form in the phrase set.

getWordFormCount

public static java.util.Map getWordFormCount(PhraseSet phraseSet,
                                             Spelling[] words,
                                             int wordForm)
Get word count for multiple words in a phrase set.

Parameters:
phraseSet - The phrase set.
words - The words.
wordForm - The word form.
Returns:
Map with words as keys and counts of each word in the phrase set as values.

getWordFormCount

public static java.util.Map getWordFormCount(PhraseSet[] phraseSets,
                                             Spelling[] words,
                                             int wordForm)
Get word count for multiple words in a set of phrase sets.

Parameters:
phraseSets - The phrase sets.
words - The words.
wordForm - The word form.
Returns:
Map with words as keys and counts of each word in the phrase sets as values.

getWordCounts

public static java.util.Map getWordCounts(PhraseSet phraseSet,
                                          int wordForm)
Get word counts in a single phrase set.

Parameters:
phraseSet - The phrase set.
wordForm - The word form to count.
Returns:
Map containing each word in the phrase set as a key and the count of the word as the value.

getPhraseCounts

public static java.util.Map getPhraseCounts(PhraseSet phraseSet,
                                            int wordForm)
Get phrase counts in a single phrase set.

Parameters:
phraseSet - The phrase set.
wordForm - The word form to count.
Returns:
Map containing each phrase in the phrase set as a key and the count of the phrase as the value.

getWordCounts

public static java.util.Map[] getWordCounts(PhraseSet[] phraseSets,
                                            int wordForm,
                                            boolean getWorkCounts)
Get word form counts in a set of phrase sets.

Parameters:
phraseSets - The phrase sets.
wordForm - The word form to count.
getWorkCounts - if true, work counts are returned in the second result map (see below). If false, hashsets of work IDs are returned in the second result map.
Returns:
Array of two maps. The first map contains each word of then specified word form in the phrase sets as a key and the count of the appearance of the word in the phrase sets as a value. The second map also has the word as the key. If "getWorkCounts" is true, the values for each word are the counts of the works in which the word appears. If "getWorkCounts" is false, the value is a hash set of the word IDs for each work in which the word appears.

getWordCounts

public static java.util.Map[] getWordCounts(PhraseSet[] phraseSets,
                                            int wordForm)

getPhraseCounts

public static java.util.Map[] getPhraseCounts(PhraseSet[] phraseSets,
                                              int wordForm,
                                              boolean getWorkCounts)
Get word form counts in a set of phrase sets.

Parameters:
phraseSets - The phrase sets.
wordForm - The word form to count.
getWorkCounts - if true, work counts are returned in the second result map (see below). If false, hashsets of work IDs are returned in the second result map.
Returns:
Array of two maps. The first map contains each phrase of the specified word form in the phrase sets as a key and the count of the appearance of the phrase in the phrase sets as a value. The second map also has the phrase as the key. If "getWorkCounts" is true, the values for each phrase are the counts of the works in which the phrase appears. If "getWorkCounts" is false, the value is a hash set of the word IDs for each work in which the phrase appears.

getPhraseCounts

public static java.util.Map[] getPhraseCounts(PhraseSet[] phraseSets,
                                              int wordForm)
Get word form counts in a set of phrase sets.

Parameters:
phraseSets - The phrase sets.
wordForm - The word form to count.
Returns:
Array of two maps. The first map contains each word of then specified word form in the phrase sets as a key and the count of the appearance of the word in the phrase sets as a value. The second map also has the word as the key but provides the number of parent works for the phrase sets in which the word appears as a value.

getWordFormPhraseCount

public static int getWordFormPhraseCount(PhraseSet phraseSet,
                                         Spelling phrase,
                                         int wordForm,
                                         Work work)
Get phrase count in a phrase set for a specific phrase in a work.

Parameters:
phraseSet - The phrase set.
phrase - The phrase text.
wordForm - The word form.
work - The work.
Returns:
Count of the word form in the phrase set.

getWordOccurrences

public static Word[] getWordOccurrences(PhraseSet phraseSet,
                                        int wordForm,
                                        Spelling word)
Get word occurrences for a word in a specified phrase set.

Parameters:
phraseSet - The phrase set.
wordForm - The word form.
word - The word to look up.
Returns:
Array of Word entries for selected word in phrase set.

getSpan

public static Word[] getSpan(PhraseSet phraseSet,
                             Word word,
                             int leftSpan,
                             int rightSpan)
Get surrounding words of a specified word in a phrase set.

Parameters:
phraseSet - The phrase set.
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.
Returns:
Span of words in the phrase set for the specified word.