gov.nih.nlm.nls.utils
Class GlobalBehavior

java.lang.Object
  extended bygov.nih.nlm.nls.utils.GlobalBehavior

public class GlobalBehavior
extends java.lang.Object

GlobalBehavior governs what options are set, what configuration settings used when analizing the text. Options are configurable settings. This package allows for the creation, use, and maitenance of options. Options can be set from configuration files and/or from the command line. The presidence is the last configuration file setting run overides prior settings. The non-configuration file calling command line settings get applied last and overide everything else. Configuration settings have a short form (one or two characters), and a long form for clarity. Short forms are referred to with a single dash, and long forms are referred to with a double dash. Configuration settings can be

boolean
Integer
string

The configuration files contents are similar to properties files. They have the syntax attribute=value on each line, where each attribute is either a long or a short name, referenced with the dash or double dash. This gives some continuity between what is put on the commandline and what can be found in a configuration file.

All possible Configuration settings are to be registered in a registry file. Registry files have a different syntax and contain additional information than configuration files.

The registry file, contains the following fields:

 shortName|longName    |type  |Default value                     |Description
 ---------+------------+------+----------------------------------+-------------
 -X       |--configFile|string|/export/nls/mmtx/config/          |Bla bla bla
 
We have also added an extensible number of fields to the end of the above line to accommodate specifying what options specifically go to which user/program component of MMTX. Fields added so far include:
    optForMetaMap  -  MetaMap specific options - boolean
    optForMMTX     -  MMTX specific options - boolean
 
Configuration/registry files are either read from the $MMTX/config directory, (having the $MMTX/config directory in the CLASSPATH in unix or in the PATH environment variable on the NT.

The get methods all take ONLY the long names. The modivation behind this is that the long names provide maintainers (beyond the original authors) a clearer indication of what is being asked for. Operationally, the hash function is a constant operation and no more expensive than getting the hash of the shorter name less illustritive name.

Examples:

   --configName=[path]ConfigFile
   -X=[path]ConfigFile
 
Examples of how one would use options in an application:
      String version = (StringOption) o.get("Version");
      boolean bestMappings = o.getBoolean("bestMappingsOnly");
 

Description: java source file.

History

Fri Jun 02 17:46:45 EDT 2000, divita Initial Version

Notes:

Version:
$Id: GlobalBehavior.java,v 1.34 2006/08/15 14:43:40 divita Exp $

Constructor Summary
GlobalBehavior(java.lang.String pApplication, java.lang.String registryFile)
          The constructor for GlobalBehavior instantiates configurable settings that other packages can take advantage of.
GlobalBehavior(java.lang.String pApplication, java.lang.String registryFile, java.lang.String configFile)
          The constructor for GlobalBehavior instantiates configurable settings that other packages can take advantage of.
GlobalBehavior(java.lang.String pApplication, java.lang.String registryFile, java.lang.String[] args)
          The constructor for GlobalBehavior instantiates configurable settings that other packages can take advantage of.
GlobalBehavior(java.lang.String pApplication, java.lang.String registryFile, java.lang.String configFile, java.lang.String[] args)
          The constructor for GlobalBehavior instantiates configurable settings that other packages can take advantage of.
 
Method Summary
 void checkConflictingOptions()
          Method checkConflictingOptions makes sure that conflicting options are mediated.
 void close()
          Method close closes the output DataOutputStream.
 boolean detectAmbiguousAbbreviation()
          Method detectAmbiguousAbbreviation returns true if the global behavior is to detect and not break sentences on ambiguous abbreviations.
 boolean display(java.lang.String x)
          Method display(x) returns whether or not the -x flag has been set to display x.
 boolean displayLexicalElements()
          Method displayLexicalElements returns true if --lexicalElements has been specified.
 java.util.Vector displayOptions(boolean allOptions, boolean withDescriptions)
          Method displayOptions returns a Vector of strings containing the options that have been set, and optionally, the descriptions of each of these options.
 boolean displayPipedOutput()
          Method displayPipedOutput returns whether or not the -pipedOutput flag has been set to display pipe delimited fields.
 boolean displaySentences()
          Method displaySentences returns whether or not the -sentence flag has been set to display sentences.
 boolean displaysettings()
          Method displaySettings returns whether or not the --displaySettings flag has been set to display Options.
 boolean displayTokens()
          Method displayTokens returns whether or not the -tokens flag has been set to display tokens.
 java.util.Vector echoSetOptions()
          Method echoSetOptions returns a Vector of strings containing the options that are currently set to true (for boolean) and options that have been specifically set.
 void flush()
          Method flush flushes the output DataOutputStream.
 Option get(java.lang.String longOptionName)
          get retrieves an option given the object's long option name.
 java.lang.String getAmbigAbbreviationsFile()
          getAmbigAbbreviationsFile returns the full path to the properties file that contains a short list of ambiguous abbreviations.
 java.lang.String getApplicationName()
          Method getApplicationName retrieves the applicationName (if set)
 boolean getBoolean(java.lang.String longOptionName)
          Method getBoolean returns the value from a known boolean option
 java.lang.ClassLoader getClassLoader()
          Method getClassLoader retrieves the current class loader
 java.lang.String getDataModel()
          Method getDataModel calculates what the data model is based on whether the --strict_model, --moderate_model, --relaxed_model has been set.
 java.lang.String getDataSet()
          Method getDataSet returns a String with the either the default Knowledge Source database name or user specified (-V option) database name.
 java.lang.String getDefaultDataSet()
          Method getDefaultDataSet returns a String with the either the default Knowledge Source database name or user specified (-V option) database name.
 java.lang.String getFileName()
          Method getFileName returns the name of the file that is being processed.
static java.lang.String getFullFile(java.lang.String fileName)
          Method getFullFile retrieves the full path of the file, given no path.
 int getInt(java.lang.String longOptionName)
          Method getInt returns the value from a known int option
 java.lang.String getInternalDBName(java.lang.String which)
          Method getInternalDBName returns a String with the internal nomenclature for the specified DB.
 java.lang.String getKSYear()
          Method getKSYear returns a String with the either the default Knowledge Source 2-digit year or user specified KS year.
 java.io.PrintWriter getOutputPrintWriter()
          Method getOutputPrintWriter By default this is standard out, but is the file pointed to by --outputFile= if this is specified.
 double getReal(java.lang.String longOptionName)
          Method getReal returns the value from a known real option
 java.lang.String getRunYear()
          Method getRunYear returns a String with the either the default Knowledge Source year or user specified KS year.
 java.lang.String getString(java.lang.String longOptionName)
          Method getString returns the value from a known string option
 int getThreshold()
          Method getThreshold returns an int with the value of threshold
 int getTruncNumber()
          Method getTruncNumber returns an int with the value of the truncate_candidates_number.
 java.lang.String getUsage(java.lang.String fileName)
          getUsage returns a string with the usage in it.
 boolean isOptionSet(java.lang.String longOptionName)
          Method isOptionSet returns whether the option is set or not
static boolean isShortName(java.lang.String optionName)
          isShortName method indicates whether the name is a long name (argument preceeded by "--") or a shortName (argument preceeded by a "-")
static void main(java.lang.String[] args)
          This is a test main, whose purpose is to test the functionality of each method developed for this class.
 void print(java.lang.String x)
          Method print prints the string out to a DataOutputStream.
 void println()
          Method println prints a NL out to a DataOutputStream, By default this is standard out, but is the file pointed to by --outputFile= if this is specified.
 void println(java.lang.String x)
          Method println prints the string out to a DataOutputStream, (with a newLine appended).
 void pull(java.lang.String longOptionName, java.lang.String shortOptionName)
          Method pull removes this option from the set of options
 void readCommandLineOptions(java.lang.String[] args)
          Method readCommandLineOptions sets options to what was given via command line options.
 void readConfigFile(java.lang.String fileName)
          Method readConfigFile sets options for an application.
 void set(Option option)
          Method set adds this option to the set of options
 void set(java.lang.String pCommandLineOption)
          Method set adds this option to the set of options
 void set(java.lang.String longOptionName, Option option)
          Method set adds this option to the set of options
 void setApplicationName(java.lang.String pApplicationName)
          Method setApplicationName sets what application has been called
 void setBoolean(java.lang.String longOptionName, boolean pValue)
          Method setBoolean sets the boolean option to the value specified.
 void setOutputFile(java.io.OutputStream pStream)
          Method setOutputFile By default this is standard out, but is the file pointed to by --outputFile= if this is specified.
 void setOutputFile(java.io.PrintWriter pStream)
          Method setOutputFile By default this is standard out, but is the file pointed to by --outputFile= if this is specified.
 void setOutputFile(java.lang.String pFileName)
          Method setOutputFile By default this is standard out, but is the file pointed to by --outputFile= if this is specified.
 void setPOptionOn()
          Method setPOptionOn Sets all of the values to TRUE for the Composite_Phrase option.
 void setQOptionOn()
          Method setQOptionOn Sets all of the values to TRUE for the Quick_Composite_Phrase option.
 void setQuickBrowseModeOn()
          Method setQuickBrowseModeOn Sets all of the values to TRUE for the --quick_browse_mode option.
 void setUnicodeOutput(boolean pValue)
          Method setUnicodeOutput enables the outputfile to print out unicode streams
 java.lang.String showProperties()
          showProperties returns all the configuration settings
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GlobalBehavior

public GlobalBehavior(java.lang.String pApplication,
                      java.lang.String registryFile,
                      java.lang.String configFile,
                      java.lang.String[] args)
The constructor for GlobalBehavior instantiates configurable settings that other packages can take advantage of. It can take command line arguments and/or the name of a configuration file. The configuration file will have to be placed in the CLASSPATH for this class to find it.

Parameters:
pApplication - [NULL|MmtX|Tokenize|Parse|Tag|lexicalLookUp|VariantGeneration ...]
registryFile - The name of a Registry configuration file (contains all ops)
configFile - The name of a configuration file to read values from.
args - an array of strings that come from the command line

GlobalBehavior

public GlobalBehavior(java.lang.String pApplication,
                      java.lang.String registryFile,
                      java.lang.String[] args)
The constructor for GlobalBehavior instantiates configurable settings that other packages can take advantage of. It can take command line arguments.

Parameters:
pApplication - [NULL|MmtX|Tokenize|Parse|Tag|lexicalLookUp|VariantGeneration ...]
registryFile - The name of a Registry configuration file (contains all ops)
args - an array of strings that come from the command line

GlobalBehavior

public GlobalBehavior(java.lang.String pApplication,
                      java.lang.String registryFile,
                      java.lang.String configFile)
The constructor for GlobalBehavior instantiates configurable settings that other packages can take advantage of. It can take the name of a configuration file. The configuration file will have to be placed in the CLASSPATH for this class to find it.

Parameters:
pApplication - [NULL|MmtX|Tokenize|Parse|Tag|lexicalLookUp|VariantGeneration ...]
registryFile - The name of a Registry configuration file (contains all ops)
configFile - The name of a configuration file to read values from.

GlobalBehavior

public GlobalBehavior(java.lang.String pApplication,
                      java.lang.String registryFile)
The constructor for GlobalBehavior instantiates configurable settings that other packages can take advantage of. It can take the name of a configuration file. The configuration file will have to be placed in the CLASSPATH for this class to find it.

Parameters:
pApplication - [NULL|MmtX|Tokenize|Parse|Tag|lexicalLookUp|VariantGeneration ...]
registryFile - The name of a Registry configuration file (contains all ops)
Method Detail

get

public Option get(java.lang.String longOptionName)
get retrieves an option given the object's long option name. The option object knows what type of object it is, and can be queried to find out.

Parameters:
longOptionName -
Returns:
Option

getBoolean

public boolean getBoolean(java.lang.String longOptionName)
Method getBoolean returns the value from a known boolean option

Parameters:
longOptionName -
Returns:
boolean Will return false if the longOptionName is not set.

setBoolean

public void setBoolean(java.lang.String longOptionName,
                       boolean pValue)
Method setBoolean sets the boolean option to the value specified. This method should only be used with boolean options that have already been created.

Parameters:
longOptionName -
pValue -

getString

public java.lang.String getString(java.lang.String longOptionName)
Method getString returns the value from a known string option

Parameters:
longOptionName -
Returns:
String Will return null if longOptionName was not set.

getInt

public int getInt(java.lang.String longOptionName)
Method getInt returns the value from a known int option

Parameters:
longOptionName -
Returns:
int This will be 0 if the longOptionName was not found in the GlobalBehavior.

getReal

public double getReal(java.lang.String longOptionName)
Method getReal returns the value from a known real option

Parameters:
longOptionName -
Returns:
double This will be 0 if the longOptionName was not found in the GlobalBehavior.

isOptionSet

public boolean isOptionSet(java.lang.String longOptionName)
Method isOptionSet returns whether the option is set or not

Parameters:
longOptionName -
Returns:
boolean

getRunYear

public java.lang.String getRunYear()
Method getRunYear returns a String with the either the default Knowledge Source year or user specified KS year.

Returns:
String

getDataSet

public java.lang.String getDataSet()
Method getDataSet returns a String with the either the default Knowledge Source database name or user specified (-V option) database name.

Returns:
String

getDefaultDataSet

public java.lang.String getDefaultDataSet()
Method getDefaultDataSet returns a String with the either the default Knowledge Source database name or user specified (-V option) database name.

Returns:
String

getInternalDBName

public java.lang.String getInternalDBName(java.lang.String which)
Method getInternalDBName returns a String with the internal nomenclature for the specified DB.

Returns:
String

getKSYear

public java.lang.String getKSYear()
Method getKSYear returns a String with the either the default Knowledge Source 2-digit year or user specified KS year.

Returns:
String

getThreshold

public int getThreshold()
Method getThreshold returns an int with the value of threshold

Returns:
int

getTruncNumber

public int getTruncNumber()
Method getTruncNumber returns an int with the value of the truncate_candidates_number.

Returns:
int

pull

public void pull(java.lang.String longOptionName,
                 java.lang.String shortOptionName)
Method pull removes this option from the set of options

Parameters:
longOptionName -
shortOptionName -

set

public void set(java.lang.String longOptionName,
                Option option)
Method set adds this option to the set of options

Parameters:
longOptionName -
option -

set

public void set(Option option)
Method set adds this option to the set of options

Parameters:
option -

set

public void set(java.lang.String pCommandLineOption)
Method set adds this option to the set of options

Parameters:
pCommandLineOption -

setPOptionOn

public void setPOptionOn()
Method setPOptionOn Sets all of the values to TRUE for the Composite_Phrase option. Involves: -zogiX In MetaMap, this involves: -z, (term processing, and ignore word order. The term processing is is presumably turned on to re-assign the head after the phrases are combined. In MMTx, when the "of" phrases are combined, the head is re-assigned as part of the process. So, term processing is not needed here. In fact, having term processing on causes all the phrases within the input to be combined (per the intent of the term processing flag). (GD, 4/18/06)


setQuickBrowseModeOn

public void setQuickBrowseModeOn()
Method setQuickBrowseModeOn Sets all of the values to TRUE for the --quick_browse_mode option. Involves: -zogmC and --quick_browse_mode_component


setQOptionOn

public void setQOptionOn()
Method setQOptionOn Sets all of the values to TRUE for the Quick_Composite_Phrase option. In MetaMap, this involves: -zi, (term processing, and ignore word order. The term processing is is presumably turned on to re-assign the head after the phrases are combined. In MMTx, when the "of" phrases are combined, the head is re-assigned as part of the process. So, term processing is not needed here. In fact, having term processing on causes all the phrases within the input to be combined (per the intent of the term processing flag). (GD, 4/18/06)


checkConflictingOptions

public void checkConflictingOptions()
Method checkConflictingOptions makes sure that conflicting options are mediated.


readConfigFile

public void readConfigFile(java.lang.String fileName)
                    throws java.lang.RuntimeException
Method readConfigFile sets options for an application.

Parameters:
fileName - application config file. This will either be the full path or no path, assuming it's in the application config directory, that has been added to the CLASSPATH or equivalant.
Throws:
java.lang.RuntimeException

displayOptions

public java.util.Vector displayOptions(boolean allOptions,
                                       boolean withDescriptions)
Method displayOptions returns a Vector of strings containing the options that have been set, and optionally, the descriptions of each of these options.

Parameters:
allOptions - if you want to see all options rather than just those options that were set to something other than the default value.
withDescriptions - Add descriptions to the output
Returns:
Vector of String

echoSetOptions

public java.util.Vector echoSetOptions()
Method echoSetOptions returns a Vector of strings containing the options that are currently set to true (for boolean) and options that have been specifically set.

Returns:
Vector of String

getAmbigAbbreviationsFile

public java.lang.String getAmbigAbbreviationsFile()
getAmbigAbbreviationsFile returns the full path to the properties file that contains a short list of ambiguous abbreviations. Ambiguous abbreviations are those which could be the indication of the end of a sentence or a true abbreviation. This method relies on the file $MMTX/data/lexicon/ambiguousAbbreviations as its source.

Returns:
String A full path to a properties file.

displaysettings

public boolean displaysettings()
Method displaySettings returns whether or not the --displaySettings flag has been set to display Options. This is, by default, set off.

Returns:
boolean

getUsage

public java.lang.String getUsage(java.lang.String fileName)
getUsage returns a string with the usage in it. When this object matures, there may be different usages returned depending on whether we can detect who is calling this. This method is intended to be called from a main when it is noted that the usage has been called for via g.displayUsage() == true;

Parameters:
fileName - Name of the Usage file.
Returns:
String of the usage notes

getFileName

public java.lang.String getFileName()
Method getFileName returns the name of the file that is being processed.

Returns:
String

showProperties

public java.lang.String showProperties()
showProperties returns all the configuration settings

Returns:
String

displaySentences

public boolean displaySentences()
Method displaySentences returns whether or not the -sentence flag has been set to display sentences. This is, by default, set off.

Returns:
boolean

displayTokens

public boolean displayTokens()
Method displayTokens returns whether or not the -tokens flag has been set to display tokens. This is, by default, set off.

Returns:
boolean

displayPipedOutput

public boolean displayPipedOutput()
Method displayPipedOutput returns whether or not the -pipedOutput flag has been set to display pipe delimited fields. This is, by default, set off.

Returns:
boolean

display

public boolean display(java.lang.String x)
Method display(x) returns whether or not the -x flag has been set to display x. (This applies only to the --sentence, --phrases --tokens, --lexicalElements, --variants type variables ). This method should be superseeded by the invocations of getBoolean("--sentence") in the future.

Parameters:
x -
Returns:
boolean

detectAmbiguousAbbreviation

public boolean detectAmbiguousAbbreviation()
Method detectAmbiguousAbbreviation returns true if the global behavior is to detect and not break sentences on ambiguous abbreviations. The default is to have this set on. This behavior can be set in the config file)

Returns:
boolean

displayLexicalElements

public boolean displayLexicalElements()
Method displayLexicalElements returns true if --lexicalElements has been specified.

Returns:
boolean

isShortName

public static boolean isShortName(java.lang.String optionName)
isShortName method indicates whether the name is a long name (argument preceeded by "--") or a shortName (argument preceeded by a "-")

Parameters:
optionName -
Returns:
boolean

getFullFile

public static java.lang.String getFullFile(java.lang.String fileName)
Method getFullFile retrieves the full path of the file, given no path. If the input file has a fileSeparator within it, this method will return the input, and not attempt to look for this file.

Parameters:
fileName -
Returns:
String

setOutputFile

public void setOutputFile(java.io.PrintWriter pStream)
Method setOutputFile By default this is standard out, but is the file pointed to by --outputFile= if this is specified.

Parameters:
pStream -

setOutputFile

public void setOutputFile(java.io.OutputStream pStream)
Method setOutputFile By default this is standard out, but is the file pointed to by --outputFile= if this is specified.

Parameters:
pStream -

setOutputFile

public void setOutputFile(java.lang.String pFileName)
                   throws java.lang.Exception
Method setOutputFile By default this is standard out, but is the file pointed to by --outputFile= if this is specified.

Parameters:
pFileName -
Throws:
java.lang.Exception

getOutputPrintWriter

public java.io.PrintWriter getOutputPrintWriter()
                                         throws java.lang.Exception
Method getOutputPrintWriter By default this is standard out, but is the file pointed to by --outputFile= if this is specified.

Returns:
PrintWriter
Throws:
java.lang.Exception

setUnicodeOutput

public void setUnicodeOutput(boolean pValue)
Method setUnicodeOutput enables the outputfile to print out unicode streams

Parameters:
pValue - True turns on , false turns this off

print

public void print(java.lang.String x)
Method print prints the string out to a DataOutputStream. By default this is standard out, but is the file pointed to by --outputFile= if this is specified.

Parameters:
x -

println

public void println(java.lang.String x)
Method println prints the string out to a DataOutputStream, (with a newLine appended). By default this is standard out, but is the file pointed to by --outputFile= if this is specified.

Parameters:
x -

println

public void println()
Method println prints a NL out to a DataOutputStream, By default this is standard out, but is the file pointed to by --outputFile= if this is specified.


close

public void close()
Method close closes the output DataOutputStream.


flush

public void flush()
Method flush flushes the output DataOutputStream.


setApplicationName

public void setApplicationName(java.lang.String pApplicationName)
Method setApplicationName sets what application has been called

Parameters:
pApplicationName -

getApplicationName

public java.lang.String getApplicationName()
Method getApplicationName retrieves the applicationName (if set)

Returns:
String [NULL|MMTx,Tokenize,LexicalLookUp,Tag,Parse,GenerateVariants]

getClassLoader

public java.lang.ClassLoader getClassLoader()
                                     throws java.lang.Exception
Method getClassLoader retrieves the current class loader

Returns:
ClassLoader
Throws:
java.lang.Exception

getDataModel

public java.lang.String getDataModel()
Method getDataModel calculates what the data model is based on whether the --strict_model, --moderate_model, --relaxed_model has been set.

Returns:
String

readCommandLineOptions

public void readCommandLineOptions(java.lang.String[] args)
Method readCommandLineOptions sets options to what was given via command line options.

Parameters:
args - arguments from the command line

main

public static final void main(java.lang.String[] args)
This is a test main, whose purpose is to test the functionality of each method developed for this class. This main strives to test the boundary conditions as well as some sample common ways each public method is intended to be used.

Parameters:
args - The command line input, tokenized


The use and distribution of this material is subject to the terms and conditions included in the file SPECIALIST_NLP_TOOLS_TERMS_AND_CONDITIONS.TXT, located in the root directory of the distribution.