convertConvert a name into the corresponding structure.
The failure to convert the name can be indicated either by returning
null, or by throwing a
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
name- the chemical name to be converted
prefixMode- true if prefix mode should be used. If
isPrefixModeSupported()returns false, this parameter is guaranteed to be false and can be safely ignored.
- the Molecule object corresponding to the name, or
nullif the name is not recognized.
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.
isPrefixModeSupporteddefault boolean isPrefixModeSupported()Returns true if prefix mode is supported.
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. In prefix mode, 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.
The default implementation of this method returns true. If a converter only accepts names without whitespace characters, then it is always safe to return true. Otherwise, you should implement prefix mode support or override this method to return false.
- true if prefix mode is supported, false otherwise.