public class HyphenationPattern extends Object
HyphenationPattern
is a pattern that acts as rule for a hyphenation algorithm. patterns
is
extracted. To allow correct results with a reasonable small set of patterns, these patterns form a chain of positive
rules and exceptions. Therefore a pattern can rank
a potential
hyphenation-position with a number from 1
to 9
. If two patterns apply for a hyphenation-position the
higher number wins. Odd numbers indicate a hyphenation while even values indicate an exception that should NOT be
hyphenated. The character '.' is used at the beginning and/or end of a pattern to indicate that it should only match
at the beginning/end of the word to hyphenate. patterns
are checked if they match (please note that the order of the patterns is
important!). Matching means that the pattern stripped from digits is a substring of the word at this start-index. If
the pattern matches the hyphenation-positions
are applied. "Computer"
will be transformed to ".computer."
that matches the following patterns:
co4m5pu2t3er
so the hyphenated input String is finally "Com-put-er"
. The
challenge is to implement this algorithm in an efficient way.Modifier and Type | Field and Description |
---|---|
private HyphenationPatternPosition[] |
hyphenationPositions |
static char |
TERMINATOR
The word-terminator representing start end end of a word.
|
private String |
wordPart
The
pattern without digits. |
private int |
wordPartHash |
Constructor and Description |
---|
HyphenationPattern(String pattern,
StringHasher hasher)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
protected HyphenationPatternPosition[] |
getHyphenationPositions()
This method gets the
hyphenation-positions of the pattern. |
String |
getPattern()
This method gets the original pattern (
word-part with hyphenation-points ). |
String |
getWordPart()
This method gets the word-part, that is the
pattern without digits. |
int |
getWordPartHash()
This method gets the pre-calculated hash of
word-part . |
String |
toString()
This method gets the original pattern.
|
private final int wordPartHash
private final HyphenationPatternPosition[] hyphenationPositions
public static final char TERMINATOR
public HyphenationPattern(String pattern, StringHasher hasher)
pattern
- is the raw pattern
.hasher
- is the hash-algorithm
to use for the word-part-hash
.protected HyphenationPatternPosition[] getHyphenationPositions()
hyphenation-positions
of the pattern.HyphenationPatternPosition
s.public String getWordPart()
pattern
without digits. If the
word-part is a substring of the word to hyphenate (enclosed with '.'), the hyphenation-points
are applied to the HyphenationState
.HyphenationState.apply(HyphenationPattern)
public int getWordPartHash()
word-part
. hash-code
of word-part
. A
specific hash algorithm is used that allows efficient calculation of shifting substrings.public String getPattern()
word-part
with hyphenation-points
). Copyright © 2001–2016 mmm-Team. All rights reserved.