ScummVM API documentation
Sci::Vocabulary Class Reference

Public Member Functions

 Vocabulary (ResourceManager *resMan, bool foreign)
 
void reset ()
 
const char * getAnyWordFromGroup (int group)
 
void lookupWord (ResultWordList &retval, const char *word, int word_len)
 
void lookupWordPrefix (ResultWordListList &parent_retval, ResultWordList &retval, const char *word, int word_len)
 
bool lookupSpecificPrefixWithMeaning (ResultWordListList &parent_retval, ResultWordList &retval, const char *word, int word_len, unsigned char prefix, const char *meaning)
 
bool lookupVerbPrefix (ResultWordListList &parent_retval, ResultWordList &retval, Common::String word, int word_len, Common::String prefix)
 
bool tokenizeString (ResultWordListList &retval, const char *sentence, char **error)
 
int parseGNF (const ResultWordListList &words, bool verbose=false)
 
bool storePronounReference ()
 
void replacePronouns (ResultWordListList &words)
 
ParseRuleList * buildGNF (bool verbose=false)
 
void debugDecipherSaidBlock (const SciSpan< const byte > &data)
 
void printSuffixes () const
 
void printParserWords () const
 
uint getParserBranchesSize () const
 
const parse_tree_branch_tgetParseTreeBranch (int number) const
 
void addSynonym (synonym_t syn)
 
void clearSynonyms ()
 
void synonymizeTokens (ResultWordListList &words)
 
void printParserNodes (int num)
 
void dumpParseTree ()
 
int parseNodes (int *i, int *pos, int type, int nr, int argc, const char **argv)
 
bool checkAltInput (Common::String &text, uint16 &cursorPos)
 
void saveLoadWithSerializer (Common::Serializer &ser)
 

Public Attributes

ParseTreeNode _parserNodes [500]
 
reg_t parser_event
 
bool parserIsValid
 

Member Function Documentation

◆ getAnyWordFromGroup()

const char* Sci::Vocabulary::getAnyWordFromGroup ( int  group)

Gets any word from the specified group. For debugging only.

Parameters
groupGroup number

◆ lookupWord()

void Sci::Vocabulary::lookupWord ( ResultWordList retval,
const char *  word,
int  word_len 
)

Looks up a single word in the words and suffixes list.

Parameters
retvalthe list of matches
wordpointer to the word to look up
word_lenlength of the word to look up

◆ lookupWordPrefix()

void Sci::Vocabulary::lookupWordPrefix ( ResultWordListList parent_retval,
ResultWordList retval,
const char *  word,
int  word_len 
)

Looks up a single word in the words list, taking into account suffixes, and updating parent_retval if a matching prefix is found Note: there is no equivalent in Sierra SCI, added to support specific languages translations For other languages, it does nothing

Parameters
parent_retvalparent's function list of matches
retvalthe list of matches
wordpointer to the word to look up
word_lenlength of the word to look up

◆ lookupSpecificPrefixWithMeaning()

bool Sci::Vocabulary::lookupSpecificPrefixWithMeaning ( ResultWordListList parent_retval,
ResultWordList retval,
const char *  word,
int  word_len,
unsigned char  prefix,
const char *  meaning 
)

Helper function for lookupWordPrefix, checking specific prefix for match Intended for nouns and prepositions, and the prefix has meaning as another word

Parameters
parent_retvallookupWordPrefix's parent's function list of matches
retvallookupWordPrefix's list of matches
wordpointer to the word to look up
word_lenlength of the word to look up
prefixthe prefix to look for in the word
meaningthe meaning of that prefix
Returns
true on prefix match, false on prefix not matching

◆ lookupVerbPrefix()

bool Sci::Vocabulary::lookupVerbPrefix ( ResultWordListList parent_retval,
ResultWordList retval,
Common::String  word,
int  word_len,
Common::String  prefix 
)

Helper function for lookupWordPrefix, checking specific prefix for match Intended for verbs, and the prefix doesn't have any meaning

Parameters
parent_retvallookupWordPrefix's parent's function list of matches
retvallookupWordPrefix's list of matches
wordpointer to the word to look up
word_lenlength of the word to look up
prefixthe prefix to look for in the word
Returns
true on prefix match, false on prefix not matching

◆ tokenizeString()

bool Sci::Vocabulary::tokenizeString ( ResultWordListList retval,
const char *  sentence,
char **  error 
)

Tokenizes a string and compiles it into word_ts.

Parameters
[in]retvalA list of words which will be set to the result
[out]sentenceThe sentence to examine
[out]errorPoints to a malloc'd copy of the offending text or to NULL on error
Returns
true on success, false on failure

On error, false is returned. If *error is NULL, the sentence did not contain any useful words; if not, *error points to a malloc'd copy of the offending word. The returned list may contain anywords.

◆ parseGNF()

int Sci::Vocabulary::parseGNF ( const ResultWordListList words,
bool  verbose = false 
)

Builds a parse tree from a list of words, using a set of Greibach Normal Form rules.

Parameters
wordsThe words to build the tree from
verboseSet to true for debugging
Returns
0 on success, 1 if the tree couldn't be built in VOCAB_TREE_NODES nodes or if the sentence structure in 'words' is not part of the language described by the grammar passed in 'rules'.

◆ storePronounReference()

bool Sci::Vocabulary::storePronounReference ( )

Find and store reference for future pronouns

◆ replacePronouns()

void Sci::Vocabulary::replacePronouns ( ResultWordListList words)

Replace pronouns by stored reference

◆ buildGNF()

ParseRuleList* Sci::Vocabulary::buildGNF ( bool  verbose = false)

Constructs the Greibach Normal Form of the grammar supplied in 'branches'.

Parameters
verboseSet to true for debugging. If true, the list is freed before the function ends
Returns
Pointer to a list of singly linked GNF rules describing the same language that was described by 'branches'

The original SCI rules are in almost-CNF (Chomsky Normal Form). Note that branch[0] is used only for a few magical incantations, as it is treated specially by the SCI parser.

◆ debugDecipherSaidBlock()

void Sci::Vocabulary::debugDecipherSaidBlock ( const SciSpan< const byte > &  data)

Deciphers a said block and dumps its content via debugN. For debugging only.

Parameters
pospointer to the data to dump

◆ printSuffixes()

void Sci::Vocabulary::printSuffixes ( ) const

Prints the parser suffixes to the debug console.

◆ printParserWords()

void Sci::Vocabulary::printParserWords ( ) const

Prints the parser words to the debug console.

◆ addSynonym()

void Sci::Vocabulary::addSynonym ( synonym_t  syn)
inline

Adds a new synonym to the list

◆ clearSynonyms()

void Sci::Vocabulary::clearSynonyms ( )
inline

Clears the list of synonyms

◆ synonymizeTokens()

void Sci::Vocabulary::synonymizeTokens ( ResultWordListList words)

Synonymizes a token list Parameters: (ResultWordListList &) words: The word list to synonymize

◆ checkAltInput()

bool Sci::Vocabulary::checkAltInput ( Common::String text,
uint16 &  cursorPos 
)

Check text input against alternative inputs.

Parameters
textThe text to process. It will be modified in-place
cursorPosThe cursor position
Returns
true if anything changed

◆ saveLoadWithSerializer()

void Sci::Vocabulary::saveLoadWithSerializer ( Common::Serializer ser)

Save/load vocabulary data

Member Data Documentation

◆ _parserNodes

ParseTreeNode Sci::Vocabulary::_parserNodes[500]

The parse tree

◆ parser_event

reg_t Sci::Vocabulary::parser_event

The event passed to Parse() and later used by Said()

◆ parserIsValid

bool Sci::Vocabulary::parserIsValid

If something has been correctly parsed


The documentation for this class was generated from the following file: