StringTools[PatternDictionary][Create] - construct the dictionary
StringTools[PatternDictionary][Search] - search a string for occurrences of patterns in the dictionary
StringTools[PatternDictionary][Size] - return the number of patterns in the dictionary
StringTools[PatternDictionary][Get] - retrieve a pattern from the dictionary
StringTools[PatternDictionary][Factors] - factor a string over the dictionary
|
Calling Sequence
|
|
Create( patlist )
Search( dict, text )
Get( dict, id )
Size( dict )
Factors( s, dict )
type( expr, dictionary )
|
|
Parameters
|
|
dict
|
-
|
dictionary; dictionary object returned by Create
|
text
|
-
|
string; text to be searched
|
patlist
|
-
|
list of strings or the name builtin; patterns to search for
|
s
|
-
|
string; string to be factored
|
id
|
-
|
positive integer; index
|
expr
|
-
|
anything; Maple expression
|
|
|
|
|
Description
|
|
•
|
The PatternDictionary subpackage of the StringTools package provides for persistent multiple pattern matching. It maintains a search data structure for multiple patterns (called the dictionary), against which text strings may be searched. This allows you to handle the missing case in StringTools[Search] where there are multiple patterns and multiple texts. The PatternDictionary subpackage provides facilities for managing this list of patterns.
|
•
|
Five procedures are provided for managing and using the search patterns.
|
|
Create
|
|
|
The Create(patlist) command constructs the dictionary. The single argument patlist must be a list of strings, or the special name builtin. When invoked with the argument builtin, a small list of English and Maple words is used. This is intended primarily for system use, but is also available to users.
|
|
Note: The sets of patterns are not allowed as arguments to Create. This is because each pattern is associated with an unique ID that is used to identify it by its position in the pattern list. Thus, pattern lists are inherently ordered.
|
|
|
Search
|
|
|
When a dictionary is created, an external search data structure is created and used for subsequent searches using Search. The storage used for the search automaton is released when the dictionary object to which it is associated is garbage collected, a restart command is issued, or when the Maple process is terminated.
|
|
The Search(dict, text) command searchs a string text for occurrences of patterns in the dictionary dict. It returns an expression sequence of pairs of the form , where offset is positive integer giving the offset into text of the match it represents, and id is the index of the matching pattern in the current pattern list.
|
|
|
Size
|
|
|
The Size(dict) command returns the number of patterns in the dictionary dict as a Maple integer.
|
|
|
Get
|
|
|
Each pattern in a dictionary dict is associated with a unique, positive integral ID that identifies it uniquely within that dictionary. The pattern whose ID is id can be retrieved from the dictionary by using the Get(dict, id) command.
|
|
|
Factors
|
|
|
A string s can be factored over a dictionary dict by using the Factors(s, dict) command. It determines a sequence of strings in the dictionary that, when concatenated, form the input string s. Note that multiple factorizations are possible.
|
|
|
|
Examples
|
|
>
|
|
>
|
|
>
|
|
>
|
|
| (1) |
>
|
|
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
>
|
|
>
|
|
| (7) |
>
|
|
| (8) |
>
|
|
| (9) |
>
|
|
| (10) |
>
|
|
You can replace the small built-in dictionary with a better word list.
>
|
|
>
|
|
>
|
|
>
|
|
| (11) |
Of course, many applications will not use English words.
>
|
|
>
|
|
>
|
|
| (12) |
>
|
|
| (13) |
|
|