standup.lexicon
Class ProfileLexicon

java.lang.Object
  extended by standup.profiling.Profile
      extended by standup.lexicon.ProfileLexicon
All Implemented Interfaces:
XMLizable, XMLsaveable

public class ProfileLexicon
extends Profile

A Profile relating to lexical resources.

An instance of ProfileLexicon is actually a simple wrapper class for an OptionsLexicon, as it does not contain any added information other than its OptionsLexicon.

Author:
Ruli Manurung

Field Summary
private  Hashtable<String,File> blacklistFiles
           
private  Hashtable<String,CustomLexicon> blacklists
           
private  Hashtable<String,File> customlexiconFiles
           
private  Hashtable<String,CustomLexicon> customlexicons
           
private  Hashtable<String,File> roottopicFiles
           
private  Hashtable<String,Topic> roottopics
           
static String XMLTAG
           
 
Constructor Summary
ProfileLexicon()
           
ProfileLexicon(Element element)
           
ProfileLexicon(File profileFile)
           
ProfileLexicon(Options options)
           
ProfileLexicon(URL profileURL)
           
 
Method Summary
 void addBlacklist(CustomLexicon blacklist)
          Adds the given blacklist to this profile, and saves it to a file with the default name of <label>.blacklist (where label is the given blacklist's label) in the directory returned by ProfileManager.getLexiconDirectory(String).
 void addBlacklist(CustomLexicon blacklist, String filename)
          Adds the given blacklist to this profile, and saves it to a file with the given filename in the directory returned by ProfileManager.getLexiconDirectory(String).
 void addCustomLexicon(CustomLexicon customLexicon)
          Adds the given custom lexicon to this profile, and saves it to a file with the default name of <label>.lexicon (where label is the given custom lexicon's label) in the directory returned by ProfileManager.getLexiconDirectory(String).
 void addCustomLexicon(CustomLexicon customLexicon, String filename)
          Adds the given custom lexicon to this profile, and saves it to a file with the given filename in the directory returned by ProfileManager.getLexiconDirectory(String).
 void addTopic(Topic topic)
          Adds the given topic to this profile, and saves it to a file with the default name of <label>.topic (where label is the given topic's root label) in the directory returned by ProfileManager.getLexiconDirectory(String).
 void addTopic(Topic topic, String filename)
          Adds the given topic to this profile, and saves it to a file with the given filename in the directory returned by ProfileManager.getLexiconDirectory(String).
 OptionsLexicon createDefaultOptions()
          Returns an appropriate instance of Options with default values, i.e.
 CustomLexicon getBlacklist(String label)
          Returns the blacklist CustomLexicon with the given label.
 Iterator<String> getBlacklistLabels()
          Returns an iterator of the labels of all the blacklist CustomLexicons contained within this ProfileLexicon.
 CustomLexicon getCustomLexicon(String label)
          Returns the CustomLexicon with the given label.
 Iterator<String> getCustomLexiconLabels()
          Returns an iterator of the labels of all the CustomLexicons contained within this ProfileLexicon.
private  File getLexicalFile(String filename)
           
 OptionsLexicon getOptions()
          Returns the Options contained within this Profile.
 Topic getRootTopic(String label)
          Returns the root Topic with the given label.
 Iterator<String> getRootTopicLabels()
          Returns an iterator of the labels of all the root Topics contained within this ProfileLexicon.
 OptionsLexicon loadOptions(Element element)
          Returns an appropriate instance of Options whose values are taken from the given XML Element.
 void quickSave(File file)
          Saves this Profile but not any associated files along with it.
 void removeBlacklist(CustomLexicon blacklist, boolean deleteFileAsWell)
          Removes the given blacklist from this profile.
 void removeCustomLexicon(CustomLexicon customLexicon, boolean deleteFileAsWell)
          Removes the given custom lexicon from this profile.
 void removeTopic(Topic topic, boolean deleteFileAsWell)
          Removes the given topic from this profile.
 void save(File file)
          This method saves the necessary information contained within an instance to an XML file.
 boolean setOptions(Options incomingOptions)
          Makes the given Options the one used within this Profile.
 void writeXML(Writer out, String indent)
          This method writes the necessary information contained within an instance to an XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XMLTAG

public static final String XMLTAG
See Also:
Constant Field Values

roottopics

private Hashtable<String,Topic> roottopics

customlexicons

private Hashtable<String,CustomLexicon> customlexicons

blacklists

private Hashtable<String,CustomLexicon> blacklists

roottopicFiles

private Hashtable<String,File> roottopicFiles

customlexiconFiles

private Hashtable<String,File> customlexiconFiles

blacklistFiles

private Hashtable<String,File> blacklistFiles
Constructor Detail

ProfileLexicon

public ProfileLexicon()
               throws ProfileException
Throws:
ProfileException

ProfileLexicon

public ProfileLexicon(Element element)

ProfileLexicon

public ProfileLexicon(File profileFile)

ProfileLexicon

public ProfileLexicon(Options options)

ProfileLexicon

public ProfileLexicon(URL profileURL)
Method Detail

getOptions

public OptionsLexicon getOptions()
Description copied from class: Profile
Returns the Options contained within this Profile. It might be useful to override this method to return the options cast as the appropriate specific Options subclass.

Overrides:
getOptions in class Profile
Returns:

getLexicalFile

private File getLexicalFile(String filename)
                     throws ProfileException
Throws:
ProfileException

setOptions

public boolean setOptions(Options incomingOptions)
Description copied from class: Profile
Makes the given Options the one used within this Profile. Always returns true. Override this method to do validation that the given Options is indeed appropriate for the particular subclass of Profile.

Overrides:
setOptions in class Profile
Returns:

writeXML

public void writeXML(Writer out,
                     String indent)
              throws IOException,
                     XMLException
Description copied from interface: XMLizable
This method writes the necessary information contained within an instance to an XML file.

Parameters:
out - The output stream for the XML file, which is assumed to be already opened and writable.
indent - A string to be prepended before every line written by this method. If passed appropriate white space, e.g. XMLUtils.xmlIndent, it can be used to control indentation.
Throws:
IOException
XMLException

quickSave

public void quickSave(File file)
               throws XMLException
Description copied from class: Profile
Saves this Profile but not any associated files along with it. This is for profiles which may depend on other files aside from the XML file created by ProfileManager. For example, the joke generation backend ProfileJokeGeneration contains pointers to XML files that contain the custom lexicon, topic database, etc. If a Profile doesn't have any such files, this method behaves the same as XMLsaveable.save(File).

Specified by:
quickSave in class Profile
Parameters:
file - the file to which this Profile should be saved.
Throws:
XMLException

save

public void save(File file)
          throws XMLException
Description copied from interface: XMLsaveable
This method saves the necessary information contained within an instance to an XML file. It should:

Parameters:
file - The file to be saved.
Throws:
XMLException

createDefaultOptions

public OptionsLexicon createDefaultOptions()
                                    throws ProfileException
Description copied from class: Profile
Returns an appropriate instance of Options with default values, i.e. those contained with the default options package (see ProfileManager.getDefaultOptionsPackage()).

Specified by:
createDefaultOptions in class Profile
Returns:
Throws:
ProfileException

loadOptions

public OptionsLexicon loadOptions(Element element)
Description copied from class: Profile
Returns an appropriate instance of Options whose values are taken from the given XML Element.

Specified by:
loadOptions in class Profile
Returns:

getRootTopicLabels

public Iterator<String> getRootTopicLabels()
Returns an iterator of the labels of all the root Topics contained within this ProfileLexicon.

Returns:

getCustomLexiconLabels

public Iterator<String> getCustomLexiconLabels()
Returns an iterator of the labels of all the CustomLexicons contained within this ProfileLexicon.

Returns:

getBlacklistLabels

public Iterator<String> getBlacklistLabels()
Returns an iterator of the labels of all the blacklist CustomLexicons contained within this ProfileLexicon.

Returns:

getRootTopic

public Topic getRootTopic(String label)
Returns the root Topic with the given label.

Parameters:
label - The label of the root topic to be retrieved.
Returns:
The root Topic that has the given label, or null if this ProfileLexicon does not contain a root topic with that label.

getCustomLexicon

public CustomLexicon getCustomLexicon(String label)
Returns the CustomLexicon with the given label.

Parameters:
label - The label of the custom lexicon to be retrieved.
Returns:
The CustomLexicon that has the given label, or null if this ProfileLexicon does not contain a custom lexicon with that label.

getBlacklist

public CustomLexicon getBlacklist(String label)
Returns the blacklist CustomLexicon with the given label.

Parameters:
label - The label of the blacklist custom lexicon to be retrieved.
Returns:
The blacklist CustomLexicon that has the given label, or null if this ProfileLexicon does not contain a blacklist custom lexicon with that label.

addTopic

public void addTopic(Topic topic)
              throws LexiconException
Adds the given topic to this profile, and saves it to a file with the default name of <label>.topic (where label is the given topic's root label) in the directory returned by ProfileManager.getLexiconDirectory(String).

If the given topic exists, or another one with the same root label exists, or a file with the same default filename exists, it will not add the topic and instead throw a {@link LexiconException}.

Parameters:
topic -
Throws:
LexiconException

addTopic

public void addTopic(Topic topic,
                     String filename)
              throws LexiconException
Adds the given topic to this profile, and saves it to a file with the given filename in the directory returned by ProfileManager.getLexiconDirectory(String).

If the given topic exists, or another one with the same root label exists, or a file with the same name exists, it will not add the topic and instead throw a {@link LexiconException}.

To obey the contract of filenaming, the given filename should end with a {@code .topic} extension.

Parameters:
topic -
filename -
Throws:
LexiconException

addCustomLexicon

public void addCustomLexicon(CustomLexicon customLexicon)
                      throws LexiconException
Adds the given custom lexicon to this profile, and saves it to a file with the default name of <label>.lexicon (where label is the given custom lexicon's label) in the directory returned by ProfileManager.getLexiconDirectory(String).

If the given custom lexicon exists, or another one with the same label exists, or a file with the same default filename exists, it will not add the custom lexicon and instead throw a {@link LexiconException}.

Parameters:
customLexicon -
Throws:
LexiconException

addCustomLexicon

public void addCustomLexicon(CustomLexicon customLexicon,
                             String filename)
                      throws LexiconException
Adds the given custom lexicon to this profile, and saves it to a file with the given filename in the directory returned by ProfileManager.getLexiconDirectory(String).

If the given custom lexicon exists, or another one with the same label exists, or a file with the same name exists, it will not add the custom lexicon and instead throw a {@link LexiconException}.

To obey the contract of filenaming, the given filename should end with a {@code .lexicon} extension.

Parameters:
customLexicon -
filename -
Throws:
LexiconException

addBlacklist

public void addBlacklist(CustomLexicon blacklist)
                  throws LexiconException
Adds the given blacklist to this profile, and saves it to a file with the default name of <label>.blacklist (where label is the given blacklist's label) in the directory returned by ProfileManager.getLexiconDirectory(String).

If the given blacklist exists, or another one with the same label exists, or a file with the same default filename exists, it will not add the blacklist and instead throw a {@link LexiconException}.

Parameters:
customLexicon -
Throws:
LexiconException

addBlacklist

public void addBlacklist(CustomLexicon blacklist,
                         String filename)
                  throws LexiconException
Adds the given blacklist to this profile, and saves it to a file with the given filename in the directory returned by ProfileManager.getLexiconDirectory(String).

If the given blacklist exists, or another one with the same label exists, or a file with the same name exists, it will not add the custom lexicon and instead throw a {@link LexiconException}.

To obey the contract of filenaming, the given filename should end with a {@code .blacklist} extension.

Parameters:
blacklist -
filename -
Throws:
LexiconException

removeTopic

public void removeTopic(Topic topic,
                        boolean deleteFileAsWell)
                 throws LexiconException
Removes the given topic from this profile. Additionally, if the given boolean value is true, it will also delete the corresponding file under the directory returned by ProfileManager.getLexiconDirectory(String). If it is false, it will retain the file.

If the topic didn't previously exist in this profile, it throws a LexiconException.

Parameters:
topic -
deleteFileAsWell -
Throws:
LexiconException

removeCustomLexicon

public void removeCustomLexicon(CustomLexicon customLexicon,
                                boolean deleteFileAsWell)
                         throws LexiconException
Removes the given custom lexicon from this profile. Additionally, if the given boolean value is true, it will also delete the corresponding file under the directory returned by ProfileManager.getLexiconDirectory(String). If it is false, it will retain the file.

If the custom lexicon didn't previously exist in this profile, it throws a LexiconException.

Parameters:
customLexicon -
deleteFileAsWell -
Throws:
LexiconException

removeBlacklist

public void removeBlacklist(CustomLexicon blacklist,
                            boolean deleteFileAsWell)
                     throws LexiconException
Removes the given blacklist from this profile. Additionally, if the given boolean value is true, it will also delete the corresponding file under the directory returned by ProfileManager.getLexiconDirectory(String). If it is false, it will retain the file.

If the blacklist didn't previously exist in this profile, it throws a LexiconException.

Parameters:
blacklist -
deleteFileAsWell -
Throws:
LexiconException