TITANIC: Beginnings of TTvocab getSuffixedWord

This commit is contained in:
Paul Gilbert 2016-05-19 19:03:35 -04:00
parent 6fa65bbf0a
commit c858190c54
4 changed files with 54 additions and 5 deletions

View File

@ -139,4 +139,22 @@ int TTstring::deletePrefix(int count) {
return 1;
}
int TTstring::deleteSuffix(int count) {
int strSize = size();
if (count > strSize)
count = strSize;
CString newStr(_data->_string.c_str(), _data->_string.c_str() + strSize - count);
if (_data->_referenceCount == 1) {
// No other references to this string, so we can just directly modify it
_data->_string = newStr;
} else {
// Detach string from current shared data, and create a new one with the substring
_data->_referenceCount--;
_data = new TTstringData(newStr);
}
return 1;
}
} // End of namespace Titanic

View File

@ -156,6 +156,12 @@ public:
* Delets a specififed number of characters from the start of the string
*/
int deletePrefix(int count);
/**
* Delets a specififed number of characters from the end of the string
*/
int deleteSuffix(int count);
};
} // End of namespace Titanic

View File

@ -180,7 +180,7 @@ TTword *TTvocab::getWord(TTstring &str, TTword **srcWord) const {
if (!word) {
TTstring tempStr(str);
if (tempStr.size() > 2) {
word = getPluralizedWord(tempStr);
word = getSuffixedWord(tempStr);
if (!word)
word = getPrefixedWord(tempStr);
@ -224,7 +224,32 @@ TTword *TTvocab::getPrimeWord(TTstring &str, TTword **srcWord) const {
return newWord;
}
TTword *TTvocab::getPluralizedWord(TTstring &str) const {
TTword *TTvocab::getSuffixedWord(TTstring &str) const {
TTstring tempStr(str);
TTword *word = nullptr;
if (tempStr.hasSuffix("s")) {
tempStr.deleteSuffix(1);
word = getPrimeWord(tempStr);
if (!word) {
if (!tempStr.hasSuffix("e")) {
tempStr = str;
} else {
tempStr.deleteLastChar();
word = getPrimeWord(tempStr);
}
}
} else if (tempStr.hasSuffix("ing")) {
tempStr.deleteSuffix(3);
word = getPrimeWord(tempStr);
if (word) {
}
}
// TODO
return nullptr;
}

View File

@ -65,12 +65,12 @@ private:
TTword *getPrimeWord(TTstring &str, TTword **srcWord = nullptr) const;
/**
* Checks the passed word for common pluralization, and if present checks
* for a word match for the base singular word
* Checks the passed word for common suffixes, like 's', 'ing', etc. and, if found,
* checks for a word match for the base word without the suffix.
* @param str Word to check
* @returns New word instance for found match, or nullptr otherwise
*/
TTword *getPluralizedWord(TTstring &str) const;
TTword *getSuffixedWord(TTstring &str) const;
/**
* Checks the passed word for common prefixes, and checks for a word