edu.cmu.sphinx.util
Class SphinxProperties

java.lang.Object
  extended byedu.cmu.sphinx.util.SphinxProperties

public class SphinxProperties
extends java.lang.Object

Manages configuration data for sphinx. Configuration data in Sphinx is managed via property files. Objects that need configuration data should get the SphinxProperties object for their context and extract properties. Property names have the form: objectName.propertyName There is a hierarchy of Configuration data. When a getProperty method is called on a SphinxProperties object, the System properties are checked first to see if there is a property with the given name, if so, the system property is used, otherwise the properties associated with the URL are checked and if found that is used, otherwise the default value for the property is used.


Field Summary
static java.lang.String PROP_WARN_NO_PROPERTY
          SphinxProperty specifying whether a warning message should be printed out if a queried property is not defined.
static boolean PROP_WARN_NO_PROPERTY_DEFAULT
          The default value of PROP_WARN_NO_PROPERTY.
 
Method Summary
 boolean contains(java.lang.String propertyName)
          Returns true if this SphinxProperties contains the given property.
 boolean getBoolean(java.lang.String propertyName, boolean defaultValue)
          Searches for the property with the specified name.
 boolean getBoolean(java.lang.String instanceName, java.lang.String propertyName, boolean defaultValue)
          Searches for the property with the specified name of a particular instance.
 java.lang.String getContext()
          Retrieves the context name for this SphinxProperties
 double getDouble(java.lang.String propertyName, double defaultValue)
          Searches for the property with the specified name.
 double getDouble(java.lang.String instanceName, java.lang.String propertyName, double defaultValue)
          Searches for the property with the specified name of a particular instance.
 float getFloat(java.lang.String propertyName, float defaultValue)
          Searches for the property with the specified name.
 float getFloat(java.lang.String instanceName, java.lang.String propertyName, float defaultValue)
          Searches for the property with the specified name of a particular instance.
 int getInt(java.lang.String propertyName, int defaultValue)
          Searches for the property with the specified name.
 int getInt(java.lang.String instanceName, java.lang.String propertyName, int defaultValue)
          Searches for the property with the specified name of a particular instance.
 java.util.Properties getProperties()
          Returns a new Property object that contains all the properties of this SphinxProperties.
static SphinxProperties getSphinxProperties(java.lang.String context)
          Retrieves the SphinxProperties for the particular context.
 java.lang.String getString(java.lang.String propertyName, java.lang.String defaultValue)
          Searches for the property with the specified name.
 java.lang.String getString(java.lang.String instanceName, java.lang.String propertyName, java.lang.String defaultValue)
          Searches for the property with the specified name of a particular instance.
static void initContext(java.lang.String context, java.util.Properties properties)
          Initialize a new SphinxProperty with the given Properties object and context.
static void initContext(java.lang.String context, java.net.URL url)
          Initialize a particular context.
 void list(java.io.PrintStream out)
          Prints this property list out to the specified output stream
 void listUnused(java.io.PrintStream out)
          Prints the list of unused properties to the specified stream.
 void setProperty(java.lang.String name, java.lang.String value)
          Sets a sphinx property.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_WARN_NO_PROPERTY

public static final java.lang.String PROP_WARN_NO_PROPERTY
SphinxProperty specifying whether a warning message should be printed out if a queried property is not defined.

See Also:
Constant Field Values

PROP_WARN_NO_PROPERTY_DEFAULT

public static final boolean PROP_WARN_NO_PROPERTY_DEFAULT
The default value of PROP_WARN_NO_PROPERTY.

See Also:
Constant Field Values
Method Detail

initContext

public static void initContext(java.lang.String context,
                               java.net.URL url)
                        throws java.io.IOException
Initialize a particular context. There can be multiple contexts in a Sphinx system. Each context can have its own SphinxProperties. This method associates a URL with a particular context.

Parameters:
context - the name of the context
url - the location of the property sheet, or null if there is no property sheet.
Throws:
java.io.IOException - if the property list cannot be loaded from the given url

initContext

public static void initContext(java.lang.String context,
                               java.util.Properties properties)
Initialize a new SphinxProperty with the given Properties object and context.

Parameters:
context - the name of the context
properties - the Properties object where our Properties reside

getSphinxProperties

public static SphinxProperties getSphinxProperties(java.lang.String context)
Retrieves the SphinxProperties for the particular context.

Parameters:
context - the context of interest
Returns:
the SphinxProperties associated with the context. If the given context does not exist an empty SphinxProperties is returned

getContext

public java.lang.String getContext()
Retrieves the context name for this SphinxProperties

Returns:
the context name

list

public void list(java.io.PrintStream out)
Prints this property list out to the specified output stream

Parameters:
out - an output stream.

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
Sets a sphinx property. Note that there is no guarantee that modified properties will be actually used

Parameters:
name - the name of the property
value - the new value for the property

listUnused

public void listUnused(java.io.PrintStream out)
Prints the list of unused properties to the specified stream. Unused properties are properties that were defined in the property list or in the system environment but were never used by the system. They are potentially mispellings or properties that are no longer used. They almost always indicate that some sort of error has taken place.

Parameters:
out - an output stream.

getProperties

public java.util.Properties getProperties()
Returns a new Property object that contains all the properties of this SphinxProperties.

Returns:
a new Property object of all the properties of this SphinxProperties

contains

public boolean contains(java.lang.String propertyName)
Returns true if this SphinxProperties contains the given property.

Returns:
true if it has the given property, false otherwise

getString

public java.lang.String getString(java.lang.String propertyName,
                                  java.lang.String defaultValue)
Searches for the property with the specified name.

Parameters:
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property

getString

public java.lang.String getString(java.lang.String instanceName,
                                  java.lang.String propertyName,
                                  java.lang.String defaultValue)
Searches for the property with the specified name of a particular instance. This is a conveniance method, since many property accesses are built by concatenating the instance name and the property name, this method is provided to make it easier.

Parameters:
instanceName - the name of the particular instance
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property

getFloat

public float getFloat(java.lang.String propertyName,
                      float defaultValue)
               throws java.lang.NumberFormatException
Searches for the property with the specified name.

Parameters:
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property
Throws:
java.lang.NumberFormatException - if the property cannot be converted to the number format

getFloat

public float getFloat(java.lang.String instanceName,
                      java.lang.String propertyName,
                      float defaultValue)
               throws java.lang.NumberFormatException
Searches for the property with the specified name of a particular instance. This is a conveniance method, since many property accesses are built by concatenating the instance name and the property name, this method is provided to make it easier.

Parameters:
instanceName - the name of the particular instance
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property
Throws:
java.lang.NumberFormatException - if the property cannot be converted to the number format

getDouble

public double getDouble(java.lang.String propertyName,
                        double defaultValue)
                 throws java.lang.NumberFormatException
Searches for the property with the specified name.

Parameters:
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property
Throws:
java.lang.NumberFormatException - if the property cannot be converted to the number format

getDouble

public double getDouble(java.lang.String instanceName,
                        java.lang.String propertyName,
                        double defaultValue)
                 throws java.lang.NumberFormatException
Searches for the property with the specified name of a particular instance. This is a conveniance method, since many property accesses are built by concatenating the instance name and the property name, this method is provided to make it easier.

Parameters:
instanceName - the name of the particular instance
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property
Throws:
java.lang.NumberFormatException - if the property cannot be converted to the number format

getInt

public int getInt(java.lang.String propertyName,
                  int defaultValue)
           throws java.lang.NumberFormatException
Searches for the property with the specified name.

Parameters:
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property
Throws:
java.lang.NumberFormatException - if the property cannot be converted to the number format

getInt

public int getInt(java.lang.String instanceName,
                  java.lang.String propertyName,
                  int defaultValue)
           throws java.lang.NumberFormatException
Searches for the property with the specified name of a particular instance. This is a conveniance method, since many property accesses are built by concatenating the instance name and the property name, this method is provided to make it easier.

Parameters:
instanceName - the name of the particular instance
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property
Throws:
java.lang.NumberFormatException - if the property cannot be converted to the number format

getBoolean

public boolean getBoolean(java.lang.String propertyName,
                          boolean defaultValue)
Searches for the property with the specified name. The string values: true, on, 1 and enabled all correspond to true, anything else is considered false.

Parameters:
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property

getBoolean

public boolean getBoolean(java.lang.String instanceName,
                          java.lang.String propertyName,
                          boolean defaultValue)
Searches for the property with the specified name of a particular instance. This is a conveniance method, since many property accesses are built by concatenating the instance name and the property name, this method is provided to make it easier.

Parameters:
instanceName - the name of the particular instance
propertyName - the name of the property to search for
defaultValue - the value to return if the property is not found
Returns:
the value of the property
Throws:
java.lang.NumberFormatException - if the property cannot be converted to the number format