Class PatternParser
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.apache.lucene.analysis.compound.hyphenation.PatternParser
-
- All Implemented Interfaces:
PatternConsumer,ContentHandler,DTDHandler,EntityResolver,ErrorHandler
public class PatternParser extends DefaultHandler implements PatternConsumer
A SAX document handler to read and parse hyphenation patterns from a XML file. This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
-
-
Constructor Summary
Constructors Constructor Description PatternParser()PatternParser(PatternConsumer consumer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddClass(String c)Add a character class.voidaddException(String w, ArrayList<Object> e)Add a hyphenation exception.voidaddPattern(String p, String v)Add hyphenation patterns.voidcharacters(char[] ch, int start, int length)voidendElement(String uri, String local, String raw)protected StringgetExceptionWord(ArrayList<?> ex)protected static StringgetInterletterValues(String pat)protected static StringgetPattern(String word)static voidmain(String[] args)protected ArrayList<Object>normalizeException(ArrayList<?> ex)voidparse(File file)Parses a hyphenation pattern file.voidparse(String filename)Parses a hyphenation pattern file.voidparse(InputSource source)Parses a hyphenation pattern file.protected StringreadToken(StringBuffer chars)InputSourceresolveEntity(String publicId, String systemId)voidsetConsumer(PatternConsumer consumer)voidstartElement(String uri, String local, String raw, Attributes attrs)-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
-
-
-
-
Constructor Detail
-
PatternParser
public PatternParser() throws HyphenationException- Throws:
HyphenationException
-
PatternParser
public PatternParser(PatternConsumer consumer) throws HyphenationException
- Throws:
HyphenationException
-
-
Method Detail
-
setConsumer
public void setConsumer(PatternConsumer consumer)
-
parse
public void parse(String filename) throws HyphenationException
Parses a hyphenation pattern file.- Parameters:
filename- the filename- Throws:
HyphenationException- In case of an exception while parsing
-
parse
public void parse(File file) throws HyphenationException
Parses a hyphenation pattern file.- Parameters:
file- the pattern file- Throws:
HyphenationException- In case of an exception while parsing
-
parse
public void parse(InputSource source) throws HyphenationException
Parses a hyphenation pattern file.- Parameters:
source- the InputSource for the file- Throws:
HyphenationException- In case of an exception while parsing
-
readToken
protected String readToken(StringBuffer chars)
-
resolveEntity
public InputSource resolveEntity(String publicId, String systemId)
- Specified by:
resolveEntityin interfaceEntityResolver- Overrides:
resolveEntityin classDefaultHandler
-
startElement
public void startElement(String uri, String local, String raw, Attributes attrs)
- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
-
endElement
public void endElement(String uri, String local, String raw)
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
-
characters
public void characters(char[] ch, int start, int length)- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- See Also:
ContentHandler.characters(char[], int, int)
-
addClass
public void addClass(String c)
Description copied from interface:PatternConsumerAdd a character class. A character class defines characters that are considered equivalent for the purpose of hyphenation (e.g. "aA"). It usually means to ignore case.- Specified by:
addClassin interfacePatternConsumer- Parameters:
c- character group
-
addException
public void addException(String w, ArrayList<Object> e)
Description copied from interface:PatternConsumerAdd a hyphenation exception. An exception replaces the result obtained by the algorithm for cases for which this fails or the user wants to provide his own hyphenation. A hyphenatedword is a vector of alternating String's andHypheninstances- Specified by:
addExceptionin interfacePatternConsumer
-
addPattern
public void addPattern(String p, String v)
Description copied from interface:PatternConsumerAdd hyphenation patterns.- Specified by:
addPatternin interfacePatternConsumer- Parameters:
p- the patternv- interletter values expressed as a string of digit characters.
-
-