Package opennlp.tools.util.normalizer
Class UnicodeDash
java.lang.Object
opennlp.tools.util.normalizer.UnicodeDash
Reference data for Unicode dashes, plus O(1) membership lookups.
This is a static, immutable table of every code point that carries the Unicode Dash
property (Unicode Character Database, PropList.txt). The set is broader than the
Pd (dash punctuation) general category: it also includes the swung dash (Po)
and the mathematical minus signs (Sm). Java offers no Dash predicate and
\p{Pd} would miss the Sm and Po members, which is why the set is kept
here explicitly.
Two distinctions matter for normalization:
- The three mathematical minus signs (
U+207B,U+208B,U+2212, all categorySm) are excluded fromdefaultDashCodePoints()because flattening them toU+002Dcan change mathematical meaning. They remain available throughcodePoints()for callers that opt in. U+00ADSOFT HYPHEN is deliberately absent: it is a format character (White_Space=no,Dash=no), an invisible line-break hint, and must not be turned into a visible hyphen.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe Unicode general category of a dash code point.static final recordOne Unicode dash code point and its reference attributes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe canonical ASCII dash that dashes are normalized to:U+002DHYPHEN-MINUS. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<UnicodeDash.DashCharacter> all()Returns all Unicode dash characters, in ascending code point order.static Optional<UnicodeDash.DashCharacter> byCodePoint(int codePoint) Looks up the reference entry for a dash code point.static int[]Returns all dash code points, in ascending order, including the mathematical minus signs.static int[]Returns the dash code points used for normalization by default, in ascending order.static booleanisDash(int codePoint) Tests whether a code point carries the UnicodeDashproperty.static List<UnicodeDash.DashCharacter> Returns the mathematical minus signs, excluded from the default normalization set.
-
Field Details
-
HYPHEN_MINUS
public static final int HYPHEN_MINUSThe canonical ASCII dash that dashes are normalized to:U+002DHYPHEN-MINUS.- See Also:
-
-
Method Details
-
isDash
public static boolean isDash(int codePoint) Tests whether a code point carries the UnicodeDashproperty.- Parameters:
codePoint- The code point to test. Out-of-range values returnfalse.- Returns:
trueif the code point is one of the Unicode dash characters.
-
byCodePoint
Looks up the reference entry for a dash code point.- Parameters:
codePoint- The code point.- Returns:
- The
UnicodeDash.DashCharacter, orOptional.empty()if it is not a dash.
-
all
Returns all Unicode dash characters, in ascending code point order.- Returns:
- all Unicode dash characters, in ascending code point order
-
mathematical
Returns the mathematical minus signs, excluded from the default normalization set.- Returns:
- the mathematical minus signs, excluded from the default normalization set
-
codePoints
public static int[] codePoints()Returns all dash code points, in ascending order, including the mathematical minus signs.- Returns:
- all dash code points, in ascending order, including the mathematical minus signs
-
defaultDashCodePoints
public static int[] defaultDashCodePoints()Returns the dash code points used for normalization by default, in ascending order.This is every dash except the mathematical minus signs, so flattening to
HYPHEN_MINUSdoes not silently rewrite mathematics.- Returns:
- the dash code points used for normalization by default, in ascending order
-