Package opennlp.tools.util.normalizer
Class Confusables
java.lang.Object
opennlp.tools.util.normalizer.Confusables
Computes the Unicode confusable skeleton of text, following the skeleton algorithm
defined in UTS #39 (Unicode Security
Mechanisms). Two
strings are confusable, for example Latin
"paypal" and a version using Cyrillic
lookalikes, exactly when their skeletons are equal.
The mapping is loaded once from the confusables.txt resource of the Unicode security
data. The skeleton of a string is NFD(map(NFD(s))): decompose, replace each code point
with its prototype, and decompose again. This changes length and offsets, so it is a
matching-only comparison form, not an offset-preserving transform.
This implements only the UTS #39 skeleton transform and the confusable-detection test built on skeleton equality. The other mechanisms defined in the report, such as identifier restriction levels, mixed-script and whole-script confusable detection, and the bidirectional skeleton, are out of scope.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanconfusable(CharSequence left, CharSequence right) Returns whetherleftandrightare confusable.static Stringskeleton(CharSequence text) Returns the confusable skeleton oftext:NFD(map(NFD(text)))wheremapreplaces each code point with its UTS #39 prototype.
-
Method Details
-
skeleton
Returns the confusable skeleton oftext:NFD(map(NFD(text)))wheremapreplaces each code point with its UTS #39 prototype. The skeleton is for comparison only; it is not human-readable text and does not preserve offsets.- Parameters:
text- The text to reduce.- Returns:
- The skeleton.
- Throws:
IllegalArgumentException- Thrown iftextisnull.
-
confusable
- Parameters:
left- The first string.right- The second string.- Returns:
- whether
leftandrightare confusable - Throws:
IllegalArgumentException- Thrown ifleftorrightisnull.
-