2006-03-23 00:54:12 +00:00
|
|
|
/**
|
|
|
|
*******************************************************************************
|
2014-05-17 00:44:39 +00:00
|
|
|
* Copyright (C) 2006-2014, International Business Machines Corporation *
|
2011-05-04 13:25:37 +00:00
|
|
|
* and others. All Rights Reserved. *
|
2006-03-23 00:54:12 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DICTBE_H
|
|
|
|
#define DICTBE_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uniset.h"
|
2006-04-22 05:29:27 +00:00
|
|
|
#include "unicode/utext.h"
|
|
|
|
|
2006-03-23 00:54:12 +00:00
|
|
|
#include "brkeng.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2012-08-16 23:01:49 +00:00
|
|
|
class DictionaryMatcher;
|
2014-05-17 00:44:39 +00:00
|
|
|
class Normalizer2;
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* DictionaryBreakEngine
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>DictionaryBreakEngine is a kind of LanguageBreakEngine that uses a
|
|
|
|
* dictionary to determine language-specific breaks.</p>
|
|
|
|
*
|
|
|
|
* <p>After it is constructed a DictionaryBreakEngine may be shared between
|
|
|
|
* threads without synchronization.</p>
|
|
|
|
*/
|
2006-04-08 08:34:52 +00:00
|
|
|
class DictionaryBreakEngine : public LanguageBreakEngine {
|
2006-03-23 00:54:12 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* The set of characters handled by this engine
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
|
|
|
|
UnicodeSet fSet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The set of break types handled by this engine
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t fTypes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Default constructor.</p>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
DictionaryBreakEngine();
|
|
|
|
|
2006-05-26 00:57:09 +00:00
|
|
|
public:
|
|
|
|
|
2006-03-23 00:54:12 +00:00
|
|
|
/**
|
|
|
|
* <p>Constructor setting the break types handled.</p>
|
|
|
|
*
|
|
|
|
* @param breakTypes A bitmap of types handled by the engine.
|
|
|
|
*/
|
|
|
|
DictionaryBreakEngine( uint32_t breakTypes );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~DictionaryBreakEngine();
|
|
|
|
|
2012-08-16 23:01:49 +00:00
|
|
|
/**
|
|
|
|
* <p>Indicate whether this engine handles a particular character for
|
|
|
|
* a particular kind of break.</p>
|
|
|
|
*
|
|
|
|
* @param c A character which begins a run that the engine might handle
|
|
|
|
* @param breakType The type of text break which the caller wants to determine
|
|
|
|
* @return TRUE if this engine handles the particular character and break
|
|
|
|
* type.
|
|
|
|
*/
|
2006-03-23 00:54:12 +00:00
|
|
|
virtual UBool handles( UChar32 c, int32_t breakType ) const;
|
|
|
|
|
2012-08-16 23:01:49 +00:00
|
|
|
/**
|
|
|
|
* <p>Find any breaks within a run in the supplied text.</p>
|
|
|
|
*
|
|
|
|
* @param text A UText representing the text. The iterator is left at
|
|
|
|
* the end of the run of characters which the engine is capable of handling
|
|
|
|
* that starts from the first (or last) character in the range.
|
|
|
|
* @param startPos The start of the run within the supplied text.
|
|
|
|
* @param endPos The end of the run within the supplied text.
|
|
|
|
* @param reverse Whether the caller is looking for breaks in a reverse
|
|
|
|
* direction.
|
|
|
|
* @param breakType The type of break desired, or -1.
|
|
|
|
* @param foundBreaks An allocated C array of the breaks found, if any
|
|
|
|
* @return The number of breaks found.
|
|
|
|
*/
|
2006-04-22 05:29:27 +00:00
|
|
|
virtual int32_t findBreaks( UText *text,
|
2006-03-23 00:54:12 +00:00
|
|
|
int32_t startPos,
|
|
|
|
int32_t endPos,
|
|
|
|
UBool reverse,
|
|
|
|
int32_t breakType,
|
|
|
|
UStack &foundBreaks ) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Set the character set handled by this engine.</p>
|
|
|
|
*
|
|
|
|
* @param set A UnicodeSet of the set of characters handled by the engine
|
|
|
|
*/
|
2006-09-30 00:37:45 +00:00
|
|
|
virtual void setCharacters( const UnicodeSet &set );
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Set the break types handled by this engine.</p>
|
|
|
|
*
|
|
|
|
* @param breakTypes A bitmap of types handled by the engine.
|
|
|
|
*/
|
2006-05-26 00:57:09 +00:00
|
|
|
// virtual void setBreakTypes( uint32_t breakTypes );
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
/**
|
2012-08-16 23:01:49 +00:00
|
|
|
* <p>Divide up a range of known dictionary characters handled by this break engine.</p>
|
2006-03-23 00:54:12 +00:00
|
|
|
*
|
2006-04-22 05:29:27 +00:00
|
|
|
* @param text A UText representing the text
|
2006-03-23 00:54:12 +00:00
|
|
|
* @param rangeStart The start of the range of dictionary characters
|
|
|
|
* @param rangeEnd The end of the range of dictionary characters
|
|
|
|
* @param foundBreaks Output of C array of int32_t break positions, or 0
|
|
|
|
* @return The number of breaks found
|
|
|
|
*/
|
2006-04-22 05:29:27 +00:00
|
|
|
virtual int32_t divideUpDictionaryRange( UText *text,
|
2006-03-23 00:54:12 +00:00
|
|
|
int32_t rangeStart,
|
|
|
|
int32_t rangeEnd,
|
|
|
|
UStack &foundBreaks ) const = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* ThaiBreakEngine
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>ThaiBreakEngine is a kind of DictionaryBreakEngine that uses a
|
2012-08-16 23:01:49 +00:00
|
|
|
* dictionary and heuristics to determine Thai-specific breaks.</p>
|
2006-03-23 00:54:12 +00:00
|
|
|
*
|
|
|
|
* <p>After it is constructed a ThaiBreakEngine may be shared between
|
|
|
|
* threads without synchronization.</p>
|
|
|
|
*/
|
2006-04-08 08:34:52 +00:00
|
|
|
class ThaiBreakEngine : public DictionaryBreakEngine {
|
2006-03-23 00:54:12 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* The set of characters handled by this engine
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
|
|
|
|
UnicodeSet fThaiWordSet;
|
|
|
|
UnicodeSet fEndWordSet;
|
|
|
|
UnicodeSet fBeginWordSet;
|
|
|
|
UnicodeSet fSuffixSet;
|
|
|
|
UnicodeSet fMarkSet;
|
2012-08-16 23:01:49 +00:00
|
|
|
DictionaryMatcher *fDictionary;
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Default constructor.</p>
|
|
|
|
*
|
2012-08-16 23:01:49 +00:00
|
|
|
* @param adoptDictionary A DictionaryMatcher to adopt. Deleted when the
|
2006-03-23 00:54:12 +00:00
|
|
|
* engine is deleted.
|
|
|
|
*/
|
2012-08-16 23:01:49 +00:00
|
|
|
ThaiBreakEngine(DictionaryMatcher *adoptDictionary, UErrorCode &status);
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~ThaiBreakEngine();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
2012-08-16 23:01:49 +00:00
|
|
|
* <p>Divide up a range of known dictionary characters handled by this break engine.</p>
|
2006-03-23 00:54:12 +00:00
|
|
|
*
|
2006-04-22 05:29:27 +00:00
|
|
|
* @param text A UText representing the text
|
2006-03-23 00:54:12 +00:00
|
|
|
* @param rangeStart The start of the range of dictionary characters
|
|
|
|
* @param rangeEnd The end of the range of dictionary characters
|
|
|
|
* @param foundBreaks Output of C array of int32_t break positions, or 0
|
|
|
|
* @return The number of breaks found
|
|
|
|
*/
|
2006-04-22 05:29:27 +00:00
|
|
|
virtual int32_t divideUpDictionaryRange( UText *text,
|
2006-03-23 00:54:12 +00:00
|
|
|
int32_t rangeStart,
|
|
|
|
int32_t rangeEnd,
|
|
|
|
UStack &foundBreaks ) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-08-16 23:01:49 +00:00
|
|
|
/*******************************************************************
|
2013-09-06 23:43:13 +00:00
|
|
|
* LaoBreakEngine
|
2012-08-16 23:01:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-09-06 23:43:13 +00:00
|
|
|
* <p>LaoBreakEngine is a kind of DictionaryBreakEngine that uses a
|
|
|
|
* dictionary and heuristics to determine Lao-specific breaks.</p>
|
|
|
|
*
|
|
|
|
* <p>After it is constructed a LaoBreakEngine may be shared between
|
|
|
|
* threads without synchronization.</p>
|
2012-08-16 23:01:49 +00:00
|
|
|
*/
|
2013-09-06 23:43:13 +00:00
|
|
|
class LaoBreakEngine : public DictionaryBreakEngine {
|
|
|
|
private:
|
2012-08-16 23:01:49 +00:00
|
|
|
/**
|
|
|
|
* The set of characters handled by this engine
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
|
2013-09-06 23:43:13 +00:00
|
|
|
UnicodeSet fLaoWordSet;
|
|
|
|
UnicodeSet fEndWordSet;
|
|
|
|
UnicodeSet fBeginWordSet;
|
|
|
|
UnicodeSet fMarkSet;
|
2012-08-16 23:01:49 +00:00
|
|
|
DictionaryMatcher *fDictionary;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-09-06 23:43:13 +00:00
|
|
|
/**
|
|
|
|
* <p>Default constructor.</p>
|
|
|
|
*
|
|
|
|
* @param adoptDictionary A DictionaryMatcher to adopt. Deleted when the
|
|
|
|
* engine is deleted.
|
|
|
|
*/
|
|
|
|
LaoBreakEngine(DictionaryMatcher *adoptDictionary, UErrorCode &status);
|
2012-08-16 23:01:49 +00:00
|
|
|
|
2013-09-06 23:43:13 +00:00
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~LaoBreakEngine();
|
2012-08-16 23:01:49 +00:00
|
|
|
|
|
|
|
protected:
|
2013-09-06 23:43:13 +00:00
|
|
|
/**
|
|
|
|
* <p>Divide up a range of known dictionary characters handled by this break engine.</p>
|
|
|
|
*
|
|
|
|
* @param text A UText representing the text
|
|
|
|
* @param rangeStart The start of the range of dictionary characters
|
|
|
|
* @param rangeEnd The end of the range of dictionary characters
|
|
|
|
* @param foundBreaks Output of C array of int32_t break positions, or 0
|
|
|
|
* @return The number of breaks found
|
|
|
|
*/
|
2012-08-16 23:01:49 +00:00
|
|
|
virtual int32_t divideUpDictionaryRange( UText *text,
|
2013-09-06 23:43:13 +00:00
|
|
|
int32_t rangeStart,
|
|
|
|
int32_t rangeEnd,
|
|
|
|
UStack &foundBreaks ) const;
|
2012-08-16 23:01:49 +00:00
|
|
|
|
|
|
|
};
|
2006-03-23 00:54:12 +00:00
|
|
|
|
2014-09-08 22:16:21 +00:00
|
|
|
/*******************************************************************
|
|
|
|
* BurmeseBreakEngine
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>BurmeseBreakEngine is a kind of DictionaryBreakEngine that uses a
|
|
|
|
* DictionaryMatcher and heuristics to determine Burmese-specific breaks.</p>
|
|
|
|
*
|
|
|
|
* <p>After it is constructed a BurmeseBreakEngine may be shared between
|
|
|
|
* threads without synchronization.</p>
|
|
|
|
*/
|
|
|
|
class BurmeseBreakEngine : public DictionaryBreakEngine {
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* The set of characters handled by this engine
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
|
|
|
|
UnicodeSet fBurmeseWordSet;
|
|
|
|
UnicodeSet fEndWordSet;
|
|
|
|
UnicodeSet fBeginWordSet;
|
|
|
|
UnicodeSet fMarkSet;
|
|
|
|
DictionaryMatcher *fDictionary;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Default constructor.</p>
|
|
|
|
*
|
|
|
|
* @param adoptDictionary A DictionaryMatcher to adopt. Deleted when the
|
|
|
|
* engine is deleted.
|
|
|
|
*/
|
|
|
|
BurmeseBreakEngine(DictionaryMatcher *adoptDictionary, UErrorCode &status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~BurmeseBreakEngine();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* <p>Divide up a range of known dictionary characters.</p>
|
|
|
|
*
|
|
|
|
* @param text A UText representing the text
|
|
|
|
* @param rangeStart The start of the range of dictionary characters
|
|
|
|
* @param rangeEnd The end of the range of dictionary characters
|
|
|
|
* @param foundBreaks Output of C array of int32_t break positions, or 0
|
|
|
|
* @return The number of breaks found
|
|
|
|
*/
|
|
|
|
virtual int32_t divideUpDictionaryRange( UText *text,
|
|
|
|
int32_t rangeStart,
|
|
|
|
int32_t rangeEnd,
|
|
|
|
UStack &foundBreaks ) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-05-04 13:25:37 +00:00
|
|
|
/*******************************************************************
|
|
|
|
* KhmerBreakEngine
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>KhmerBreakEngine is a kind of DictionaryBreakEngine that uses a
|
2012-09-04 20:05:20 +00:00
|
|
|
* DictionaryMatcher and heuristics to determine Khmer-specific breaks.</p>
|
2011-05-04 13:25:37 +00:00
|
|
|
*
|
|
|
|
* <p>After it is constructed a KhmerBreakEngine may be shared between
|
|
|
|
* threads without synchronization.</p>
|
|
|
|
*/
|
|
|
|
class KhmerBreakEngine : public DictionaryBreakEngine {
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* The set of characters handled by this engine
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
|
|
|
|
UnicodeSet fKhmerWordSet;
|
|
|
|
UnicodeSet fEndWordSet;
|
|
|
|
UnicodeSet fBeginWordSet;
|
|
|
|
UnicodeSet fMarkSet;
|
2012-08-16 23:01:49 +00:00
|
|
|
DictionaryMatcher *fDictionary;
|
2011-05-04 13:25:37 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Default constructor.</p>
|
|
|
|
*
|
2012-09-04 20:05:20 +00:00
|
|
|
* @param adoptDictionary A DictionaryMatcher to adopt. Deleted when the
|
2011-05-04 13:25:37 +00:00
|
|
|
* engine is deleted.
|
|
|
|
*/
|
2012-08-16 23:01:49 +00:00
|
|
|
KhmerBreakEngine(DictionaryMatcher *adoptDictionary, UErrorCode &status);
|
2011-05-04 13:25:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~KhmerBreakEngine();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* <p>Divide up a range of known dictionary characters.</p>
|
|
|
|
*
|
|
|
|
* @param text A UText representing the text
|
|
|
|
* @param rangeStart The start of the range of dictionary characters
|
|
|
|
* @param rangeEnd The end of the range of dictionary characters
|
|
|
|
* @param foundBreaks Output of C array of int32_t break positions, or 0
|
|
|
|
* @return The number of breaks found
|
|
|
|
*/
|
|
|
|
virtual int32_t divideUpDictionaryRange( UText *text,
|
|
|
|
int32_t rangeStart,
|
|
|
|
int32_t rangeEnd,
|
|
|
|
UStack &foundBreaks ) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-09-06 23:43:13 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* CjkBreakEngine
|
|
|
|
*/
|
|
|
|
|
|
|
|
//indicates language/script that the CjkBreakEngine will handle
|
|
|
|
enum LanguageType {
|
|
|
|
kKorean,
|
|
|
|
kChineseJapanese
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>CjkBreakEngine is a kind of DictionaryBreakEngine that uses a
|
|
|
|
* dictionary with costs associated with each word and
|
|
|
|
* Viterbi decoding to determine CJK-specific breaks.</p>
|
|
|
|
*/
|
|
|
|
class CjkBreakEngine : public DictionaryBreakEngine {
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* The set of characters handled by this engine
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
UnicodeSet fHangulWordSet;
|
|
|
|
UnicodeSet fHanWordSet;
|
|
|
|
UnicodeSet fKatakanaWordSet;
|
|
|
|
UnicodeSet fHiraganaWordSet;
|
|
|
|
|
2014-05-17 00:44:39 +00:00
|
|
|
DictionaryMatcher *fDictionary;
|
|
|
|
const Normalizer2 *nfkcNorm2;
|
2013-09-06 23:43:13 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Default constructor.</p>
|
|
|
|
*
|
|
|
|
* @param adoptDictionary A DictionaryMatcher to adopt. Deleted when the
|
|
|
|
* engine is deleted. The DictionaryMatcher must contain costs for each word
|
|
|
|
* in order for the dictionary to work properly.
|
|
|
|
*/
|
|
|
|
CjkBreakEngine(DictionaryMatcher *adoptDictionary, LanguageType type, UErrorCode &status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~CjkBreakEngine();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* <p>Divide up a range of known dictionary characters handled by this break engine.</p>
|
|
|
|
*
|
|
|
|
* @param text A UText representing the text
|
|
|
|
* @param rangeStart The start of the range of dictionary characters
|
|
|
|
* @param rangeEnd The end of the range of dictionary characters
|
|
|
|
* @param foundBreaks Output of C array of int32_t break positions, or 0
|
|
|
|
* @return The number of breaks found
|
|
|
|
*/
|
|
|
|
virtual int32_t divideUpDictionaryRange( UText *text,
|
|
|
|
int32_t rangeStart,
|
|
|
|
int32_t rangeEnd,
|
|
|
|
UStack &foundBreaks ) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-03-23 00:54:12 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
/* DICTBE_H */
|
|
|
|
#endif
|