background image
C H A P T E R 1 0
Recognition: Advanced Topics
10-26
Using Advanced Topics in Recognition
symbol
'custom
as its argument, which specifies that the new dictionary is for
this application's use only.
Note
Although the token returned by the
NewDictionary
function
currently evaluates to an integer in the NTK Inspector, the type of
value returned by this function may change on future Newton
devices. Do not rely on the
NewDictionary
function returning
an integer.
Adding Words to RAM-Based Dictionaries
10
Once you have created a blank dictionary, you need to populate it with your
dictionary items. You can use the
AddWordToDictionary
function to add a
specified string to a specified RAM-based dictionary.
The first argument to this function is the identifier of the dictionary to which the
string is to be added; this identifier is returned by the
NewDictionary
function. The
previous code example stored this identifier in the
mySpecialDictionary
slot.
The second argument to this function is the string to be added to the dictionary. If
this argument is not a string, the
AddWordToDictionary
function throws an
exception. If the word is added successfully, this function returns
true
. If the
specified word cannot be added, this function returns
nil
.
The
AddWordToDictionary
function may return
nil
when the word to be
added is already present in the specified dictionary, or it may return
nil
because of
resource limitations. It is possible to run out of system memory for dictionaries,
with potentially serious consequences. Do not rely on a specific number of
dictionary entries as the maximum amount that may be added safely. It is strongly
recommended that you use custom dictionaries sparingly and keep them as small as
possible, taking into account the possibility that other applications may require
system memory for their own dictionaries or for other uses.
To populate the dictionary, you need to call the
AddWordToDictionary
function once for each item to be added. There are many ways to call a function
iteratively; the best approach for your needs is an application-specific detail that
cannot be anticipated here. The following code example shows one way to populate
a blank dictionary.
myAdder:= func()
begin
local element;
// items slot contains an array of dictionary strings
foreach element in items do
AddWordToDictionary(mySpecialDictionary, element);
end
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна