Nysiis class
Encodes a string using The New York State Identification and Intelligence System (NYSIIS) algorithm. It is basically a more modern alternative to the original Soundex. It was intended to match names and surnames so it may not perform as well on dictionary words.
This implementation follows the "original" and "modified" algorithms as documented in the USDA reference below (Appendix B). Each algorithm is very specific but many of the other implementations that were reviewed did not seem to produce the same results. This implementation aims to reproduce the algorithm exactly as stated in the USDA reference, whereas others have taken some liberties with their implementations, which seems to be the cause of many of the discrepancies.
Some examples of discrepancies discovered in other implementations:
- The "dropby.com" original algorithm includes duplicates in the first character position, but this should be removed in step 6 of the step 4-5-6 loop. Also, their "modified" version is not the same as the USDA "modified" version (e.g., SH, SCH, YW).
- Some implementations seem to get the logic wrong for an H or W encoding at the beginning of a string because they operate on a substring starting at the second character instead of using a pointer based approach as specified in the original algorithm. So they miss the preceding character that a pointer based approach would have picked up if the algorithm is followed as stated.
If you want (or need) to understand more details, here are some good references that help explain the history and variants:
- https://naldc.nal.usda.gov/download/27833/PDF (also in curated references)
- http://www.dropby.com/NYSIIS.html (does not follow the USDA algorithms).
- Implemented types
Constructors
- Nysiis()
-
Gets the originalEncoder instance of the encoder.
factory
- Nysiis.withOptions({int maxLength = defaultOriginalMaxLength, bool enableModified = false})
-
Creates an instance with a custom
maxLength
andenableModified
. The defaults are consistent with the originalEncoder.factory
Properties
- enableModified → bool
-
Indicates if the "modified" rules should be applied when encoding.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxLength → int
-
Maximum length of the encoding, where
0
indicates no maximum.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
encode(
String input) → PhoneticEncoding? -
Encodes a string using the NYSIIS algorithm as configured. This encoder
does not produce any PhoneticEncoding.alternates values.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- modifiedEncoder → Nysiis
-
An instance that uses defaultModifiedMaxLength for maxLength and sets
enableModified to
true
to replicate the modified NYSIIS algorithm.final - originalEncoder → Nysiis
-
An instance that uses defaultOriginalMaxLength for maxLength and sets
enableModified to
false
to replicate the original NYSIIS algorithm.final
Constants
- defaultModifiedMaxLength → const int
- Default encoding length to use for the modified algorithm.
- defaultOriginalMaxLength → const int
- Default encoding length to use for the original algorithm.