// add prefix to this word assuming conditions hold
std::string PfxEntry::add(constchar* word, size_t len) {
std::string result; if ((len > strip.size() || (len == 0 && pmyMgr->get_fullstrip())) &&
(len >= numconds) && test_condition(word) &&
(strip.empty() ||
(len >= strip.size() && strncmp(word, strip.c_str(), strip.size()) == 0))) { /* we have a match so add prefix */
result.assign(appnd);
result.append(word + strip.size());
} return result;
}
inlinechar* PfxEntry::nextchar(char* p) { if (p) {
p++; if (opts & aeLONGCOND) { // jump to the 2nd part of the condition if (p == c.conds + MAXCONDLEN_1) return c.l.conds2; // end of the MAXCONDLEN length condition
} elseif (p == c.conds + MAXCONDLEN) return nullptr; return *p ? p : nullptr;
} return nullptr;
}
inlineint PfxEntry::test_condition(const std::string& s) {
size_t st = 0;
size_t pos = std::string::npos; // group with pos input position bool neg = false; // complementer bool ingroup = false; // character in the group if (numconds == 0) return1; char* p = c.conds; while (true) { switch (*p) { case'\0': return1; case'[': {
neg = false;
ingroup = false;
p = nextchar(p);
pos = st; break;
} case'^': {
p = nextchar(p);
neg = true; break;
} case']': { if (bool(neg) == bool(ingroup)) return0;
pos = std::string::npos;
p = nextchar(p); // skip the next character if (!ingroup && st < s.size()) {
++st; while ((opts & aeUTF8) && st < s.size() && (s[st] & 0xc0) == 0x80)
++st;
} if (st == s.size() && p) return0; // word <= condition break;
} case'.': if (pos == std::string::npos) { // dots are not metacharacters in groups: [.]
p = nextchar(p); // skip the next character
++st; while ((opts & aeUTF8) && st < s.size() && (s[st] & 0xc0) == 0x80)
++st; if (st == s.size() && p) return0; // word <= condition break;
} /* FALLTHROUGH */ default: { if (st < s.size() && s[st] == *p) {
++st;
p = nextchar(p); if ((opts & aeUTF8) && (s[st - 1] & 0x80)) { // multibyte while (p && (*p & 0xc0) == 0x80) { // character if (st >= s.size() || *p != s[st]) { if (pos == std::string::npos) return0;
st = pos; break;
}
p = nextchar(p);
++st;
} if (pos != std::string::npos && st != pos) {
ingroup = true; while (p && *p != ']' && ((p = nextchar(p)) != nullptr)) {
}
}
} elseif (pos != std::string::npos) {
ingroup = true; while (p && *p != ']' && ((p = nextchar(p)) != nullptr)) {
}
}
} elseif (pos != std::string::npos) { // group
p = nextchar(p);
} else return0;
}
} if (!p) return1;
}
}
// check if this prefix entry matches struct hentry* PfxEntry::checkword(const std::string& word, int start, int len, char in_compound, const FLAG needflag) { struct hentry* he; // hash entry of root word or NULL
// on entry prefix is 0 length or already matches the beginning of the word. // So if the remaining root word has positive length // and if there are enough chars in root word and added back strip chars // to meet the number of characters conditions, then test it
int tmpl = len - appnd.size(); // length of tmpword
if (tmpl > 0 || (tmpl == 0 && pmyMgr->get_fullstrip())) { // generate new root word by removing prefix and adding // back any characters that would have been stripped
// now make sure all of the conditions on characters // are met. Please see the appendix at the end of // this file for more info on exactly what is being // tested
// if all conditions are met then check if resulting // root word in the dictionary
if (test_condition(tmpword)) {
tmpl += strip.size(); if ((he = pmyMgr->lookup(tmpword.c_str(), tmpword.size())) != nullptr) { do { if (TESTAFF(he->astr, aflag, he->alen) && // forbid single prefixes with needaffix flag
!TESTAFF(contclass, pmyMgr->get_needaffix(), contclasslen) && // needflag
((!needflag) || TESTAFF(he->astr, needflag, he->alen) ||
(contclass && TESTAFF(contclass, needflag, contclasslen)))) return he;
he = he->next_homonym; // check homonyms
} while (he);
}
// prefix matched but no root word was found // if aeXPRODUCT is allowed, try again but now // ross checked combined with a suffix
// if ((opts & aeXPRODUCT) && in_compound) { if ((opts & aeXPRODUCT)) {
he = pmyMgr->suffix_check(tmpword, 0, tmpl, aeXPRODUCT, this,
FLAG_NULL, needflag, in_compound); if (he) return he;
}
}
} return nullptr;
}
// check if this prefix entry matches struct hentry* PfxEntry::check_twosfx(const std::string& word, int start, int len, char in_compound, const FLAG needflag) { // on entry prefix is 0 length or already matches the beginning of the word. // So if the remaining root word has positive length // and if there are enough chars in root word and added back strip chars // to meet the number of characters conditions, then test it
int tmpl = len - appnd.size(); // length of tmpword
if ((tmpl > 0 || (tmpl == 0 && pmyMgr->get_fullstrip())) &&
(tmpl + strip.size() >= numconds)) { // generate new root word by removing prefix and adding // back any characters that would have been stripped
// now make sure all of the conditions on characters // are met. Please see the appendix at the end of // this file for more info on exactly what is being // tested
// if all conditions are met then check if resulting // root word in the dictionary
if (test_condition(tmpword)) {
tmpl += strip.size();
// prefix matched but no root word was found // if aeXPRODUCT is allowed, try again but now // cross checked combined with a suffix
if ((opts & aeXPRODUCT) && (in_compound != IN_CPD_BEGIN)) { // hash entry of root word or NULL struct hentry* he = pmyMgr->suffix_check_twosfx(tmpword, 0, tmpl, aeXPRODUCT, this,
needflag); if (he) return he;
}
}
} return nullptr;
}
// check if this prefix entry matches
std::string PfxEntry::check_twosfx_morph(const std::string& word, int start, int len, char in_compound, const FLAG needflag) {
std::string result; // on entry prefix is 0 length or already matches the beginning of the word. // So if the remaining root word has positive length // and if there are enough chars in root word and added back strip chars // to meet the number of characters conditions, then test it int tmpl = len - appnd.size(); // length of tmpword
if ((tmpl > 0 || (tmpl == 0 && pmyMgr->get_fullstrip())) &&
(tmpl + strip.size() >= numconds)) { // generate new root word by removing prefix and adding // back any characters that would have been stripped
// now make sure all of the conditions on characters // are met. Please see the appendix at the end of // this file for more info on exactly what is being // tested
// if all conditions are met then check if resulting // root word in the dictionary
if (test_condition(tmpword)) {
tmpl += strip.size();
// prefix matched but no root word was found // if aeXPRODUCT is allowed, try again but now // ross checked combined with a suffix
// check if this prefix entry matches
std::string PfxEntry::check_morph(const std::string& word, int start, int len, char in_compound, const FLAG needflag) {
std::string result;
// on entry prefix is 0 length or already matches the beginning of the word. // So if the remaining root word has positive length // and if there are enough chars in root word and added back strip chars // to meet the number of characters conditions, then test it
int tmpl = len - appnd.size(); // length of tmpword
if ((tmpl > 0 || (tmpl == 0 && pmyMgr->get_fullstrip())) &&
(tmpl + strip.size() >= numconds)) { // generate new root word by removing prefix and adding // back any characters that would have been stripped
// now make sure all of the conditions on characters // are met. Please see the appendix at the end of // this file for more info on exactly what is being // tested
// if all conditions are met then check if resulting // root word in the dictionary
if (test_condition(tmpword)) {
tmpl += strip.size(); struct hentry* he; // hash entry of root word or NULL if ((he = pmyMgr->lookup(tmpword.c_str(), tmpword.size())) != nullptr) { do { if (TESTAFF(he->astr, aflag, he->alen) && // forbid single prefixes with needaffix flag
!TESTAFF(contclass, pmyMgr->get_needaffix(), contclasslen) && // needflag
((!needflag) || TESTAFF(he->astr, needflag, he->alen) ||
(contclass && TESTAFF(contclass, needflag, contclasslen)))) { if (morphcode) {
result.push_back(MSEP_FLD);
result.append(morphcode);
} else
result.append(getKey()); if (!HENTRY_FIND(he, MORPH_STEM)) {
result.push_back(MSEP_FLD);
result.append(MORPH_STEM);
result.append(HENTRY_WORD(he));
} // store the pointer of the hash entry if (HENTRY_DATA(he)) {
result.push_back(MSEP_FLD);
result.append(HENTRY_DATA2(he));
} else { // return with debug information
std::string flag = pmyMgr->encode_flag(getFlag());
result.push_back(MSEP_FLD);
result.append(MORPH_FLAG);
result.append(flag);
}
result.push_back(MSEP_REC);
}
he = he->next_homonym;
} while (he);
}
// prefix matched but no root word was found // if aeXPRODUCT is allowed, try again but now // ross checked combined with a suffix
if ((opts & aeXPRODUCT) && (in_compound != IN_CPD_BEGIN)) {
std::string st = pmyMgr->suffix_check_morph(tmpword, 0, tmpl, aeXPRODUCT, this,
FLAG_NULL, needflag); if (!st.empty()) {
result.append(st);
}
}
}
}
// add suffix to this word assuming conditions hold
std::string SfxEntry::add(constchar* word, size_t len) {
std::string result; /* make sure all conditions match */ if ((len > strip.size() || (len == 0 && pmyMgr->get_fullstrip())) &&
(len >= numconds) && test_condition(word + len, word) &&
(strip.empty() ||
(len >= strip.size() && strcmp(word + len - strip.size(), strip.c_str()) == 0))) {
result.assign(word, len); /* we have a match so add suffix */
result.replace(len - strip.size(), std::string::npos, appnd);
} return result;
}
inlinechar* SfxEntry::nextchar(char* p) { if (p) {
p++; if (opts & aeLONGCOND) { // jump to the 2nd part of the condition if (p == c.l.conds1 + MAXCONDLEN_1) return c.l.conds2; // end of the MAXCONDLEN length condition
} elseif (p == c.conds + MAXCONDLEN) return nullptr; return *p ? p : nullptr;
} return nullptr;
}
inlineint SfxEntry::test_condition(constchar* st, constchar* beg) { constchar* pos = nullptr; // group with pos input position bool neg = false; // complementer bool ingroup = false; // character in the group if (numconds == 0) return1; char* p = c.conds;
st--; int i = 1; while (true) { switch (*p) { case'\0': return1; case'[':
p = nextchar(p);
pos = st; break; case'^':
p = nextchar(p);
neg = true; break; case']': if (!neg && !ingroup) return0;
i++; // skip the next character if (!ingroup) { for (; (opts & aeUTF8) && (st >= beg) && (*st & 0xc0) == 0x80; st--)
;
st--;
}
pos = nullptr;
neg = false;
ingroup = false;
p = nextchar(p); if (st < beg && p) return0; // word <= condition break; case'.': if (!pos) { // dots are not metacharacters in groups: [.]
p = nextchar(p); // skip the next character for (st--; (opts & aeUTF8) && (st >= beg) && (*st & 0xc0) == 0x80;
st--)
; if (st < beg) { // word <= condition if (p) return0; else return1;
} if ((opts & aeUTF8) && (*st & 0x80)) { // head of the UTF-8 character
st--; if (st < beg) { // word <= condition if (p) return0; else return1;
}
} break;
} /* FALLTHROUGH */ default: { if (*st == *p) {
p = nextchar(p); if ((opts & aeUTF8) && (*st & 0x80)) {
st--; while (p && (st >= beg)) { if (*p != *st) { if (!pos) return0;
st = pos; break;
} // first byte of the UTF-8 multibyte character if ((*p & 0xc0) != 0x80) break;
p = nextchar(p);
st--;
} if (pos && st != pos) { if (neg) return0; elseif (i == numconds) return1;
ingroup = true; while (p && *p != ']' && ((p = nextchar(p)) != nullptr)) {
}
st--;
} if (p && *p != ']')
p = nextchar(p);
} elseif (pos) { if (neg) return0; elseif (i == numconds) return1;
ingroup = true; while (p && *p != ']' && ((p = nextchar(p)) != nullptr)) {
} // if (p && *p != ']') p = nextchar(p);
st--;
} if (!pos) {
i++;
st--;
} if (st < beg && p && *p != ']') return0; // word <= condition
} elseif (pos) { // group
p = nextchar(p);
} else return0;
}
} if (!p) return1;
}
}
// see if this suffix is present in the word struct hentry* SfxEntry::checkword(const std::string& word, int start, int len, int optflags,
PfxEntry* ppfx, const FLAG cclass, const FLAG needflag, const FLAG badflag) { struct hentry* he; // hash entry pointer
PfxEntry* ep = ppfx;
// if this suffix is being cross checked with a prefix // but it does not support cross products skip it
// upon entry suffix is 0 length or already matches the end of the word. // So if the remaining root word has positive length // and if there are enough chars in root word and added back strip chars // to meet the number of characters conditions, then test it
int tmpl = len - appnd.size(); // length of tmpword // the second condition is not enough for UTF-8 strings // it checked in test_condition()
if ((tmpl > 0 || (tmpl == 0 && pmyMgr->get_fullstrip())) &&
(tmpl + strip.size() >= numconds)) { // generate new root word by removing suffix and adding // back any characters that would have been stripped or // or null terminating the shorter string
std::string tmpstring(word, start, tmpl); if (!strip.empty()) {
tmpstring.append(strip);
}
// now make sure all of the conditions on characters // are met. Please see the appendix at the end of // this file for more info on exactly what is being // tested
// if all conditions are met then check if resulting // root word in the dictionary
// see if two-level suffix is present in the word struct hentry* SfxEntry::check_twosfx(const std::string& word, int start, int len, int optflags,
PfxEntry* ppfx, const FLAG needflag) {
PfxEntry* ep = ppfx;
// if this suffix is being cross checked with a prefix // but it does not support cross products skip it
// upon entry suffix is 0 length or already matches the end of the word. // So if the remaining root word has positive length // and if there are enough chars in root word and added back strip chars // to meet the number of characters conditions, then test it
int tmpl = len - appnd.size(); // length of tmpword
if ((tmpl > 0 || (tmpl == 0 && pmyMgr->get_fullstrip())) &&
(tmpl + strip.size() >= numconds)) { // generate new root word by removing suffix and adding // back any characters that would have been stripped or // or null terminating the shorter string
constchar* beg = tmpword.c_str(); constchar* end = beg + tmpl;
// now make sure all of the conditions on characters // are met. Please see the appendix at the end of // this file for more info on exactly what is being // tested
// if all conditions are met then recall suffix_check
if (test_condition(end, beg)) { struct hentry* he; // hash entry pointer if (ppfx) { // handle conditional suffix if ((contclass) && TESTAFF(contclass, ep->getFlag(), contclasslen))
he = pmyMgr->suffix_check(tmpword, 0, tmpl, 0, nullptr, (FLAG)aflag, needflag, IN_CPD_NOT); else
he = pmyMgr->suffix_check(tmpword, 0, tmpl, optflags, ppfx,
(FLAG)aflag, needflag, IN_CPD_NOT);
} else {
he = pmyMgr->suffix_check(tmpword, 0, tmpl, 0, nullptr, (FLAG)aflag, needflag, IN_CPD_NOT);
} if (he) return he;
}
} return nullptr;
}
// see if two-level suffix is present in the word
std::string SfxEntry::check_twosfx_morph(const std::string& word, int start, int len, int optflags,
PfxEntry* ppfx, const FLAG needflag) {
PfxEntry* ep = ppfx;
std::string result;
// if this suffix is being cross checked with a prefix // but it does not support cross products skip it
// upon entry suffix is 0 length or already matches the end of the word. // So if the remaining root word has positive length // and if there are enough chars in root word and added back strip chars // to meet the number of characters conditions, then test it
int tmpl = len - appnd.size(); // length of tmpword
if ((tmpl > 0 || (tmpl == 0 && pmyMgr->get_fullstrip())) &&
(tmpl + strip.size() >= numconds)) { // generate new root word by removing suffix and adding // back any characters that would have been stripped or // or null terminating the shorter string
constchar* beg = tmpword.c_str(); constchar* end = beg + tmpl;
// now make sure all of the conditions on characters // are met. Please see the appendix at the end of // this file for more info on exactly what is being // tested
// if all conditions are met then recall suffix_check
if (test_condition(end, beg)) { if (ppfx) { // handle conditional suffix if ((contclass) && TESTAFF(contclass, ep->getFlag(), contclasslen)) {
std::string st = pmyMgr->suffix_check_morph(tmpword, 0, tmpl, 0, nullptr, aflag, needflag); if (!st.empty()) { if (ppfx->getMorph()) {
result.append(ppfx->getMorph());
result.push_back(MSEP_FLD);
}
result.append(st);
mychomp(result);
}
} else {
std::string st = pmyMgr->suffix_check_morph(tmpword, 0, tmpl, optflags, ppfx, aflag,
needflag); if (!st.empty()) {
result.append(st);
mychomp(result);
}
}
} else {
std::string st = pmyMgr->suffix_check_morph(tmpword, 0, tmpl, 0, nullptr, aflag, needflag); if (!st.empty()) {
result.append(st);
mychomp(result);
}
}
}
} return result;
}
// get next homonym with same affix struct hentry* SfxEntry::get_next_homonym(struct hentry* he, int optflags,
PfxEntry* ppfx, const FLAG cclass, const FLAG needflag) {
PfxEntry* ep = ppfx;
FLAG eFlag = ep ? ep->getFlag() : FLAG_NULL;
An affix is either a prefix or a suffix attached to root words to make
other words.
Basically a Prefix or a Suffix is set of AffEntry objects
which store information about the prefix or suffix along
with supporting routines to check if a word has a particular
prefix or suffix or a combination.
The structure affentry is defined as follows:
struct affentry
{ unsignedshort aflag; // ID used to represent the affix
std::string strip; // string to strip before adding affix
std::string appnd; // the affix string to add char numconds; // the number of conditions that must be met char opts; // flag: aeXPRODUCT- combine both prefix and suffix char conds[SETSIZE]; // array which encodes the conditions to be met
};
Here is a suffix borrowed from the en_US.aff file. This file
is whitespace delimited.
SFX D Y 4
SFX D 0 e d
SFX D y ied [^aeiou]y
SFX D 0 ed [^ey]
SFX D 0 ed [aeiou]y
This information can be interpreted as follows:
In the first line has 4 fields
Field
----- 1 SFX - indicates this is a suffix 2 D - is the name of the character flag which represents this suffix 3 Y - indicates it can be combined with prefixes (cross product) 44 - indicates that sequence of 4 affentry structures are needed to
properly store the affix information
The remaining lines describe the unique information for the 4 SfxEntry
objects that make up this affix. Each line can be interpreted
as follows: (note fields 1and2 are as a check against line 1 info)
Field
----- 1 SFX - indicates this is a suffix 2 D - is the name of the character flag forthis affix 3 y - the string of chars to strip off before adding affix
(a 0 here indicates the NULL string) 4 ied - the string of affix characters to add 5 [^aeiou]y - the conditions which must be met before the affix
can be applied
Field 5 is interesting. Since this is a suffix, field 5 tells us that
there are 2 conditions that must be met. The first condition is that
the next to the last character in the word must *NOT* be any of the
following "a", "e", "i", "o"or"u". The second condition is that
the last character of the word must end in "y".
So how can we encode this information concisely and be able to
test for both conditions in a fast manner? The answer is found
but studying the wonderful ispell code of Geoff Kuenning, et.al.
(now available under a normal BSD license).
If we set up a conds array of 256 bytes indexed (0 to 255) and access it using a character (cast to an unsignedchar) of a string, we have 8 bits
of information we can store about that character. Specifically we
could use each bit to say if that character is allowed in any of the
last (or first for prefixes) 8 characters of the word.
Basically, each character at one end of the word (up to the number
of conditions) is used to index into the conds array and the resulting
value found there says whether the that character is valid for a
specific character position in the word.
For prefixes, it does this by setting bit 0if that char is valid
in the first position, bit 1if valid in the second position, and so on.
If a bit is not set, then that char is not valid for that postion in the
word.
If working with suffixes bit 0 is used for the character closest
to the front, bit 1for the next character towards the end, ...,
with bit numconds-1 representing the last char at the end of the string.
Note: since entries in the conds[] are 8 bits, only 8 conditions
(read that only 8 character positions) can be examined at one
end of a word (the beginning for prefixes and the end for suffixes.
So to make this clearer, lets encode the conds array values for the
first two affentries for the suffix D described earlier.
For the first affentry:
numconds = 1 (only examine the last character)
conds['e'] = (1 << 0) (the word must end in an E)
all others are all 0
For the second affentry:
numconds = 2 (only examine the last two characters)
conds[X] = conds[X] | (1 << 0) (aeiou are not allowed)
where X is all characters *but* a, e, i, o, or u
conds['y'] = (1 << 1) (the last char must be a y)
all other bits for all other entries in the conds array are zero
#endif
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.31 Sekunden
(vorverarbeitet am 2026-09-30)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.