nct.service.synonyms
Class DIPSynonyms

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by nct.service.synonyms.DIPSynonyms
All Implemented Interfaces:
SynonymMapper, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class DIPSynonyms
extends org.xml.sax.helpers.DefaultHandler
implements SynonymMapper

Implements a SynonymMapper based on a DIP XIN file. This class is an XML ContentHandler which needs to be added to an XMLReader so that the events will be generated.


Field Summary
protected  java.util.Map<java.lang.String,java.lang.String> idMap
          Maps a synonym to a dip file id.
protected  java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> synMap
          Maps the dip file id to a synonym.
 
Constructor Summary
DIPSynonyms()
          Initializes the content handler.
 
Method Summary
protected  void addId(java.lang.String id, java.lang.String type, java.lang.String synonym)
          Adds an id to the synonym database for a specific type.
protected  void addValue(java.lang.String id, java.lang.String type, java.lang.String value)
          Adds a value to the synonym database for a specific type.
 void characters(char[] ch, int start, int length)
          Standard SAX event handler.
 void endDocument()
          Standard SAX event handler.
 void endElement(java.lang.String uri, java.lang.String name, java.lang.String qName)
          Standard SAX event handler.
 java.lang.String getIdFromSynonym(java.lang.String synonym)
          Returns the unique id for the specified synonym.
 java.util.List<java.lang.String> getPotentialSynonyms(java.lang.String regex)
          Returns a list of matches to the input string which is treated as a regular expression pattern.
 java.lang.String getSynonym(java.lang.String synonym, java.lang.String type)
          A shortcut method for calling: String s = syns.getSynonymFromId(syns.getIdFromSynonym(synonym), type);
 java.lang.String getSynonymFromId(java.lang.String id, java.lang.String type)
          Returns a synonym of a particular type for the specified id.
 void startDocument()
          Standard SAX event handler.
 void startElement(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes atts)
          Standard SAX event handler.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

synMap

protected java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> synMap
Maps the dip file id to a synonym. The first String is the id, the second the type, the third the synonym.


idMap

protected java.util.Map<java.lang.String,java.lang.String> idMap
Maps a synonym to a dip file id. The first String is the synonym, the second is the id;

Constructor Detail

DIPSynonyms

public DIPSynonyms()
Initializes the content handler.

Method Detail

getIdFromSynonym

public java.lang.String getIdFromSynonym(java.lang.String synonym)
Returns the unique id for the specified synonym.

Specified by:
getIdFromSynonym in interface SynonymMapper
Parameters:
synonym - The synonym to check the database for.
Returns:
The unique id for the input synonym, or null if the synonym can't be found in the database.

getSynonymFromId

public java.lang.String getSynonymFromId(java.lang.String id,
                                         java.lang.String type)
Returns a synonym of a particular type for the specified id.

Specified by:
getSynonymFromId in interface SynonymMapper
Parameters:
id - The id to check the database for.
type - The type of synonym desired for the specified id.
Returns:
The requested synonym or null if the id can't be found in the database.

getSynonym

public java.lang.String getSynonym(java.lang.String synonym,
                                   java.lang.String type)
A shortcut method for calling: String s = syns.getSynonymFromId(syns.getIdFromSynonym(synonym), type);

Specified by:
getSynonym in interface SynonymMapper
Parameters:
synonym - The synonym to check the database for.
type - The type of synonym desired for the specified input synonym.
Returns:
The requested synonym or null if the synonym can't be found in the database.

getPotentialSynonyms

public java.util.List<java.lang.String> getPotentialSynonyms(java.lang.String regex)
Returns a list of matches to the input string which is treated as a regular expression pattern.

Specified by:
getPotentialSynonyms in interface SynonymMapper
Parameters:
regex - The regular expression that will be evaluated against each key in the database.
Returns:
The list of matches found.

addId

protected void addId(java.lang.String id,
                     java.lang.String type,
                     java.lang.String synonym)
Adds an id to the synonym database for a specific type.

Parameters:
id - The id to use for the synonym.
type - The type of the synonym.
synonym - The synonym to be stored.

addValue

protected void addValue(java.lang.String id,
                        java.lang.String type,
                        java.lang.String value)
Adds a value to the synonym database for a specific type. Adding a value will be accessible to any synonym of the specified id, but the value itself will not be a synonym.

Parameters:
id - The id to use for the value.
type - The type of the value.
value - The value to be stored.

startDocument

public void startDocument()
Standard SAX event handler.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler

endDocument

public void endDocument()
Standard SAX event handler.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler

startElement

public void startElement(java.lang.String uri,
                         java.lang.String name,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
Standard SAX event handler.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler

endElement

public void endElement(java.lang.String uri,
                       java.lang.String name,
                       java.lang.String qName)
Standard SAX event handler.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
Standard SAX event handler.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler