standup.lexicon
Class Topic

java.lang.Object
  extended by standup.lexicon.LexemeSet
      extended by standup.lexicon.CustomLexicon
          extended by standup.lexicon.Topic
All Implemented Interfaces:
XMLizable, XMLsaveable

public class Topic
extends CustomLexicon
implements XMLsaveable

A Topic represents a collection of Lexemes that are related in some sense, e.g. thematically.

A Topic also has a list of subtopics, potentially forming a hierarchical structure of sets of Lexemes.

As implemented, a Topic is essentially a CustomLexicon with a list of sub Topics.

Author:
Ruli Manurung

Field Summary
private  List<String> cachedImageFiles
           
private  SymbolType[] cachedSymbolSet
           
protected  String conceptCode
          An optional field that contains the Widgit 'real' conceptcode that specifies the symbol to be associated with this topic.
protected  Topic parent
          The parent of this Topic.
protected  Vector<Topic> subtopics
          A Vector of subtopics, each of which must also be a Topic.
 
Fields inherited from class standup.lexicon.CustomLexicon
active, label
 
Fields inherited from class standup.lexicon.LexemeSet
set
 
Constructor Summary
  Topic(Element topicElement)
          Constructor that loads a root Topic specified in the given XML Element.
  Topic(File file)
          Constructor that loads a Topic from an existing File.
private Topic(Topic parent, Element topicElement)
          Constructor that loads a Topic specified in the given XML Element.
  Topic(Topic p, String l, String c)
          Constructor for creating a new Topic with parent p, label l, and conceptcode c.
  Topic(URL url)
          Constructor that loads a Topic from an existing file referenced by the given URL.
 
Method Summary
 void addSubtopic(Topic t)
          Adds the given Topic to the list of subtopics.
private static void doTopicList(Topic t, Element topicListElement)
          Processes a Topic's list of subtopics from its XML Element.
 Topic duplicate()
          Returns a duplicate of this CustomLexicon.
 boolean equals(Object obj)
           
 LexemeSet getAllKeywords()
          Returns a LexemeSet that contains the union of all Lexemes associated with this Topic and, recursively, all Lexemes associated with all of its subtopics.
 String getConceptCode()
          Returns the Widgit conceptcode associated with this Topic.
 List<String> getImageFile(SymbolType[] symbolSet)
          This method returns the path and filename for the symbol representing this Topic, if one has been specified.
 String getLabelFromRoot()
          Returns a String that shows the path to this Topic from its root, e.g.
 Topic getParentTopic()
          Returns the parent of this Topic, or null if it's a root topic.
 int getSubtopicCount()
          Returns the number of subtopics this Topic has.
 Iterator<Topic> getSubtopics()
          Returns an Iterator of all the subtopics of this Topic.
private static String handleConceptCode(Element topicElement)
          Reads the 'conceptcode' tag of a Topic from its XML tag.
 int hashCode()
           
 boolean hasNamedSubtopic(String l)
          Returns true either if this Topic has label l, or has a descendent with label l, and false otherwise.
private  String indent(int n)
           
 boolean isAncestorOf(Topic t)
          Returns true if this Topic is an ancestor of the given Topic, false otherwise.
 boolean isDescendantOf(Topic t)
          Returns true if this Topic is a descendant of the given Topic, false otherwise.
 boolean isModified()
          Returns true if this Topic, or any of its subtopics, has been modified since the last time it was loaded from/saved to disk, false otherwise.
 String prettyPrint()
          Returns a nice tree-structured text output of this Topic.
private  String prettyPrint(int n)
           
 void removeSubtopic(Topic t)
          Removes the given Topic from this Topic's list of subtopics.
 void save(File file)
          Implementation of {@link XMLsaveable#save(File).
 void setModified(boolean mod)
          Sets the value to be returned by isModified().
 String toString()
           
 void writeXML(Writer out, String indent)
          Implementation of XMLizable.writeXML(Writer, String).
 
Methods inherited from class standup.lexicon.CustomLexicon
add, add, getLabel, isActive, remove, remove, removeRandom, rename, setActive
 
Methods inherited from class standup.lexicon.LexemeSet
addLexemesFromXML, contains, getLexemeCount, getLexemes, getLexemesIterator, getRandom, getSpelledClusters, getSpelledLexemes, getSpelledLexemes, isEmpty
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

subtopics

protected final Vector<Topic> subtopics
A Vector of subtopics, each of which must also be a Topic.


parent

protected Topic parent
The parent of this Topic. Its value is null if this Topic is a root topic.


conceptCode

protected final String conceptCode
An optional field that contains the Widgit 'real' conceptcode that specifies the symbol to be associated with this topic. If left to null there is no image associated with it.


cachedImageFiles

private transient List<String> cachedImageFiles

cachedSymbolSet

private transient SymbolType[] cachedSymbolSet
Constructor Detail

Topic

public Topic(Topic p,
             String l,
             String c)
Constructor for creating a new Topic with parent p, label l, and conceptcode c. It starts with no related Lexemes and no subtopics.

Parameters:
p - the parent topic -- null if the Topic to be created is a root topic
l - the label for the new Topic
c - the Widgit conceptcode to be associated with this Topic

Topic

public Topic(URL url)
Constructor that loads a Topic from an existing file referenced by the given URL.

Parameters:
url -

Topic

public Topic(File file)
Constructor that loads a Topic from an existing File.

Parameters:
file -

Topic

public Topic(Element topicElement)
Constructor that loads a root Topic specified in the given XML Element.

Parameters:
topicElement -

Topic

private Topic(Topic parent,
              Element topicElement)
Constructor that loads a Topic specified in the given XML Element. The instantiated Topic will be a subtopic of the given parent.

Parameters:
parent -
topicElement -
Method Detail

handleConceptCode

private static String handleConceptCode(Element topicElement)
Reads the 'conceptcode' tag of a Topic from its XML tag.

Parameters:
topicElement -
Returns:

doTopicList

private static void doTopicList(Topic t,
                                Element topicListElement)
                         throws LexiconException
Processes a Topic's list of subtopics from its XML Element.

Parameters:
t - the parent Topic of the specified subtopics
topicListElement - the XML Element containing the specification of the subtopics
Throws:
LexiconException

hashCode

public int hashCode()
Overrides:
hashCode in class CustomLexicon

equals

public boolean equals(Object obj)
Overrides:
equals in class CustomLexicon

toString

public String toString()
Overrides:
toString in class CustomLexicon

getConceptCode

public String getConceptCode()
Returns the Widgit conceptcode associated with this Topic.

Returns:

duplicate

public Topic duplicate()
Description copied from class: CustomLexicon
Returns a duplicate of this CustomLexicon. Sets modified of the returned CustomLexicon to true.

Overrides:
duplicate in class CustomLexicon

isModified

public boolean isModified()
Returns true if this Topic, or any of its subtopics, has been modified since the last time it was loaded from/saved to disk, false otherwise.

Overrides:
isModified in class CustomLexicon
Returns:

setModified

public void setModified(boolean mod)
Sets the value to be returned by isModified(). Additionally, if mod is false, all of its subtopics are setModified(false) as well.

Overrides:
setModified in class CustomLexicon
Parameters:
mod - the new value of modified

getParentTopic

public Topic getParentTopic()
Returns the parent of this Topic, or null if it's a root topic.


getLabelFromRoot

public String getLabelFromRoot()
Returns a String that shows the path to this Topic from its root, e.g. "root > animals > farmyard".

Returns:

hasNamedSubtopic

public boolean hasNamedSubtopic(String l)
Returns true either if this Topic has label l, or has a descendent with label l, and false otherwise.

Parameters:
l -
Returns:

isAncestorOf

public boolean isAncestorOf(Topic t)
Returns true if this Topic is an ancestor of the given Topic, false otherwise.

Parameters:
t -
Returns:

isDescendantOf

public boolean isDescendantOf(Topic t)
Returns true if this Topic is a descendant of the given Topic, false otherwise.

Parameters:
t -
Returns:

addSubtopic

public void addSubtopic(Topic t)
                 throws LexiconException
Adds the given Topic to the list of subtopics.

This effectively adds the relationship is_a(t,this). Additionally, it sets modified to true). Checks for additions which would result in ill-formed trees (i.e. cycles), and throws a LexiconException if detected.

Parameters:
t -
Throws:
LexiconException

removeSubtopic

public void removeSubtopic(Topic t)
                    throws LexiconException
Removes the given Topic from this Topic's list of subtopics.

This effectively removes the relationship is_a(t,this). Additionally, if the removal was succesful, it sets modified to true).

Parameters:
t -
Throws:
LexiconException

getSubtopics

public Iterator<Topic> getSubtopics()
Returns an Iterator of all the subtopics of this Topic.

Returns:

getSubtopicCount

public int getSubtopicCount()
Returns the number of subtopics this Topic has.

Returns:

getAllKeywords

public LexemeSet getAllKeywords()
Returns a LexemeSet that contains the union of all Lexemes associated with this Topic and, recursively, all Lexemes associated with all of its subtopics.

Returns:

getImageFile

public List<String> getImageFile(SymbolType[] symbolSet)
                          throws SymbolException
This method returns the path and filename for the symbol representing this Topic, if one has been specified. The symbol is assumed to exist in the location that SymbolManager#getImageFile(String, SymbolType[], boolean) expects to find it.

Parameters:
symbolset - an array indicating the preference of which SymbolType is to be used
Returns:
Throws:
SymbolException

writeXML

public void writeXML(Writer out,
                     String indent)
              throws IOException,
                     XMLException
Implementation of XMLizable.writeXML(Writer, String).

Specified by:
writeXML in interface XMLizable
Overrides:
writeXML in class CustomLexicon
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

save

public void save(File file)
Description copied from class: CustomLexicon
Implementation of {@link XMLsaveable#save(File).

Specified by:
save in interface XMLsaveable
Overrides:
save in class CustomLexicon
Parameters:
file - the file where this CustomLexicon is to be saved

prettyPrint

public String prettyPrint()
Returns a nice tree-structured text output of this Topic.

Returns:

prettyPrint

private String prettyPrint(int n)

indent

private String indent(int n)