|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xml.sax.helpers.DefaultHandler au.id.pbw.hyfo.hyph.HyphenationTreeBuilder
public class HyphenationTreeBuilder
Builds a HyphenationTree
from an input pattern file.
Nested Class Summary | |
---|---|
static class |
HyphenationTreeBuilder.Element
An enum of the elements n a resource file. |
Constructor Summary | |
---|---|
HyphenationTreeBuilder()
Creates a new instance of HyphenationTreeBuilder |
Method Summary | |
---|---|
protected TernaryTree |
build_tree(Map<String,HyphenBreak[]> map,
HyphenDataCache data_cache)
Builds and returns a TernaryTree mapping string keys to arrays of
HyphenBreak s. |
void |
characters(char[] ch,
int start,
int length)
Processes a node of characters from the resource file. |
void |
endElement(String uri,
String localName,
String qName)
Process an end element from the resource file. |
HyphenationTree |
get_hyphenation_tree(File resource_file)
Builds and returns a TernaryTree from the resource file
provided. |
protected HyphenBreak |
get_mod_ref(ModifierReference ref,
InstanceType context)
Gets the HyphenBreak corresponding
to the Modifier named by this ModifierReference , in the named
context. |
protected Modifier |
get_modifier(String id)
Gets a known Modifier with a
given id, which is generally the no-break string. |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Processes ignorable white space from the resource file. |
protected HyphenBreak |
obtain_hyphen_break(HyphenBreak hyph_break)
Returns a HyphenBreak equal to
the given argument. |
protected void |
process_instance(InstanceType type,
List<PatternElement> list,
Alphabet alphabet,
Map<String,HyphenBreak[]> map)
Process a pattern instance, adding it to the given map. |
protected void |
process_text_element(StringBuilder text_chars_as_classes,
TextElement text_el,
InstanceType type)
Process a text element from an exception or hyphenation pattern. |
protected void |
process_text_instance(InstanceType type,
TextElement text_el,
Alphabet alphabet,
Map<String,HyphenBreak[]> map)
Process a text instance, adding it to the given map. |
void |
startElement(String uri,
String localName,
String qName,
Attributes attributes)
Process a start element from the resource file. |
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
---|
endDocument, endPrefixMapping, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected AlphabetBuilder alpha_builder
AlphabetBuilder
used to construct the Alphabet
instance
for use with this tree.
protected Alphabet alphabet
Alphabet
for the tree being constructed. All of the text to
be hyphenated by the tree is expressed in this alphabet. Text in any
codepoints not in this Alphabet
cannot be hyphenated by the
HyphenationTree
being constructed.
protected int hyphen_char
Alphabet
of the
HyphenationTree
being built.
protected Map<String,Modifier> modifiers
protected TernaryTree exceptions
protected HyphenDataCache exception_data
TernaryTreeDataStore
associated with the exceptions tree.
protected TernaryTree patterns
protected HyphenDataCache pattern_data
TernaryTreeDataStore
associated with the patterns tree.
protected HashMap<String,HyphenBreak> hyphen_breaks
HyphenBreak
objects used in constructing the tree.
protected boolean start_seen
process_text_element(java.lang.StringBuilder, au.id.pbw.hyfo.hyph.TextElement, au.id.pbw.hyfo.hyph.InstanceType)
.
protected boolean end_seen
process_text_element(java.lang.StringBuilder, au.id.pbw.hyfo.hyph.TextElement, au.id.pbw.hyfo.hyph.InstanceType)
.
protected ArrayList<HyphenBreak> weights
process_text_element(java.lang.StringBuilder, au.id.pbw.hyfo.hyph.TextElement, au.id.pbw.hyfo.hyph.InstanceType)
.
Constructor Detail |
---|
public HyphenationTreeBuilder()
Method Detail |
---|
public HyphenationTree get_hyphenation_tree(File resource_file) throws SAXException, IOException, ParserConfigurationException
TernaryTree
from the resource file
provided.
resource_file
- the resource file.
TernaryTree
.
SAXException
- if an error occurs during the SAX parsing of the input file.
IOException
- if an error occurs during the reading of the resource file.
ParserConfigurationException
- if an error occurs during the configuration of the SAX parser.public void ignorableWhitespace(char[] ch, int start, int length)
ignorableWhitespace
in interface ContentHandler
ignorableWhitespace
in class DefaultHandler
ch
- An array of chars.start
- the start point of the white space in the ch
array.length
- the length of the white space in the ch
array.public void characters(char[] ch, int start, int length)
characters
in interface ContentHandler
characters
in class DefaultHandler
ch
- an array of char
.start
- the start point of the @code characters} in the ch
array.length
- the length of the @code characters} in the ch
array.public void endElement(String uri, String localName, String qName)
endElement
in interface ContentHandler
endElement
in class DefaultHandler
uri
- the namespace URI of the element.localName
- the local name fo the element.qName
- the qualified name of the element.public void startElement(String uri, String localName, String qName, Attributes attributes)
startElement
in interface ContentHandler
startElement
in class DefaultHandler
uri
- the namespace URI of the element.localName
- the local name fo the element.qName
- the qualified name of the element.attributes
- the attributes defiend on the element.protected Modifier get_modifier(String id)
Modifier
with a
given id, which is generally the no-break string.
id
- the unique name of the modifier.
protected HyphenBreak obtain_hyphen_break(HyphenBreak hyph_break)
HyphenBreak
equal to
the given argument. The purpose is to reduce the object count in the
hyphenation tables.
If a HyphenBreak
with a key equal to the argument is not already
present in the Map
hyphen_breaks, the argument is
inserted into the map and returned; else the matching element from the
map is returned.
hyph_break
- the required HyphenBreak
.
HyphenBreak
.protected HyphenBreak get_mod_ref(ModifierReference ref, InstanceType context) throws HyphenationException
HyphenBreak
corresponding
to the Modifier
named by this ModifierReference
, in the named
context. ModifierReference
s occur in either exception
or pattern set contexts. The context is used only to provide a
more meaningful log message, if required.
ref
- the ModifierReference
.context
- a String
naming the context.
HyphenBreak
.
HyphenationException
- if the XML data is
invalid.protected TernaryTree build_tree(Map<String,HyphenBreak[]> map, HyphenDataCache data_cache) throws HyphenationException
TernaryTree
mapping string keys to arrays of
HyphenBreak
s.
data_cache
- the HyphenDataCache
managing the data for the tree.map
- a map from a string key to a HyphenBreak
array value.
TernaryTree
.
HyphenationException
- is an error occurs while
building te tree.protected void process_instance(InstanceType type, List<PatternElement> list, Alphabet alphabet, Map<String,HyphenBreak[]> map) throws HyphenationException
ModifierReference
s, the PatternElement
s
are passed in a list.
list
- the List
containing the PatternElement
s making up this
instance.type
- the type of instance.alphabet
- the Alphabet
for
the instance.map
- the map to which the instance details are added.
HyphenationException
- if the XML data is
invalid.protected void process_text_instance(InstanceType type, TextElement text_el, Alphabet alphabet, Map<String,HyphenBreak[]> map) throws HyphenationException
ModifierReference
s, so its is simpler to process
than a pattern instance, which may contain such references.
type
- the type of instance.text_el
- the TextElement
being added to the tree.alphabet
- the Alphabet
for
the instance.map
- the map to which the instance details are added.
HyphenationException
- if the XML data is
invalid.protected void process_text_element(StringBuilder text_chars_as_classes, TextElement text_el, InstanceType type) throws HyphenationException
process_instance(au.id.pbw.hyfo.hyph.InstanceType, java.util.List, au.id.pbw.hyfo.hyph.Alphabet, java.util.Map)
and process_text_instance(au.id.pbw.hyfo.hyph.InstanceType, au.id.pbw.hyfo.hyph.TextElement, au.id.pbw.hyfo.hyph.Alphabet, java.util.Map)
.
text_chars_as_classes
- Stringbuilder
to construct the string from the
text element with the original characters mapped to character classes.text_el
- the text element to process.type
- of element - exception or pattern.
HyphenationException
- if any errors are
detected in the format or content of the text of
the exception or pattern.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |