chemaxon.naming
Interface NameConverter


public interface NameConverter

The interface of a converter from names to structures.

Author:
Daniel Bonniot

Method Summary
 Molecule convert(java.lang.String name)
          Convert a name into the corresponding structure.
 boolean setPrefixMode(boolean prefixMode)
          Set the prefix mode flag.
 

Method Detail

convert

Molecule convert(java.lang.String name)
                 throws NameFormatException
Convert a name into the corresponding structure. The failure to convert the name can be indicated either by returning null, or by throwing a NameFormatException. When a converter fails by returning null or throwing NameFormatException, converters of lower priority will be called with the same name. To prevent that and guarantee that the name is not converted at all, a converter should throw NameFormatException.FilteredCase.

Parameters:
name - the chemical name to be converted
Returns:
the Molecule object corresponding to the name, or null if the name is not recognized.
Throws:
NameFormatException - when the name does not correspond to a structure
NameFormatException.FilteredCase - when the name does not correspond to a structure, and not other converter should be tried on this name.
NamePrefixException - when the name does not correspond to a structure, but is a possible prefix of a valid name.

setPrefixMode

boolean setPrefixMode(boolean prefixMode)
Set the prefix mode flag. The prefix mode is an optimization, only used when extracting structures from text documents. It is irrelevant when converting a single name to a structure.

When converting a document, it is not directly possible to know where name start and end. For instance, suppose that a converter knows the structure for "Prussian Blue" by looking it up in a database. Given the sentence "The Prussian Blue chemical was used to color textiles in blue", the word "Prussian" alone would be passed to the converter. If prefix mode has been successfully activated, the converter should throw a NamePrefixException, indicating that it knows a name starting with this prefix.

The prefix mode is an optional optimization. If a converter does not support it, it can return false to this call. In this case, the system will always try to call again after concatenating several words (up to a limit or a detected end of sentence). This ensures that names containing spaces will be recognized, at the cost of more conversion attempts.

Returns:
true if prefix mode is supported, false otherwise.