14. For a real-world grammar checker, up to one million words may be tagged with their respective parts of speech, which for a lone programmer may take many years to complete. As has been demonstrated the tagging is done with the Substitute function.
15. But there is a problem – and it isn’t with the Substitute function, which itself can list and tag a million words – the problem is with the Specify Calculation window, which has a limit of 30,000 characters. That means that the Substitute function in the editing area of the Specify Calculation window may only extend its listing to about 2,000 pairings, far short of the million words in the English language that can be tagged.
16. The way around this is by using the Custom Function utility available with FileMaker Pro Advanced. At first it may appear the problem persists as the Edit Custom Function window also has a limit of 30,000 characters. But there is a programming structure called “nesting” that allows multiple Substitute functions to be chained. To tag a million words will require defining about 500 custom functions with one Substitute function in each. Planning is required to create 500 alphabetical subdivisions of the words in the English language, one subdivision per Substitute function. For example, the first Substitute function may list pairs (words, and their corresponding parts of speech), from “a” to “adobe”; the second Substitute function in the second custom function may list words from “adopt” to “agile”.
17. It may be a good idea to name the first custom function Metadata1AToAdobe, the second Metadata2AdoptToAgile, and so on.
18. In the Edit Custom Function define Comment as the only parameter (a pointer to the Comment field).
19. In the list of functions (top right) double-click Substitute. Highlight the first parameter and double-click Comment from the parameter list (it should be the only parameter listed) then list the words from “a” to “adobe”, enclosing pairs in square brackets. The expression may look like this: Substitute ( Comment ; [“a” ; “ article indefinite “] ; [“aardvark” ; “noun singular”] ; [“aback” ; “adverb”] ; [“abacuses” ; “noun plural”] … ); better still abbreviate to: Substitute ( Comment ; [“a” ; “ai”] ; [“aardvark” ; “ns”] ; [“aback” ; “av”] ; [“abacuses” ; “np”] … ). Click OK.
20. When all 500 custom functions have been defined (probably 10 laborious years later), go back to the Field tab of the Define Database window (File, Define, Database). Click Options for the Metadata field to open the Specify Calculation window. Rid any contents in the editing area and from the function list (top right) double-click Metadata500ZanyToZygote; as this is the last custom function in the chain it will be the first to be inserted in the editing area.
21. Highlight the Comment parameter and then from the function list double-click Metadata499YachtToYuppie. The result is that Metadata499 has been nested in Metadata500.
22. Keep doing same till 499 custom functions have been nested. The innermost nesting of this monstrous piece of code will be Metadata1AToAdobe (Comment) and will be evaluated first to keep in line the chaining analogy. However, this is more an aesthetic issue and this ordering may be ignored. The important result is that we have overcome the 30,000-character limit of the Specify Calculation window to create a piece of code that references 500 custom functions that together oversee and translate a million words into their parts of speech. We are nearly finished – just one more task to go.
23. Click Options for the Feedback field to open the Specify Calculation window. Select from the function list (top right) the Case function. Now we put our knowledge of the grammar rules into practice. The Case function will look for error patterns in the Metadata field. There is but one function in FMPro that spots patterns better than any other and that is, yes, PatternCount. It will look for metadata that are a cause for concern. For example, say the user types erroneously “Dog have four legs” into the Comment field. The Metadata field will read “ns avp ap np”. What we want the Case function in the Feedback field to do is spot “ns avp” as possible rule breaking and then provide the message “A singular noun has been followed by a plural auxiliary verb; perhaps change one or the other to match”. The 30,000 character limit may or may not be sufficient for the Case function and the hundreds of nested PatternCount functions to detect all the possible error scenarios: if it is enough, create the Case function in the Specify Calculation window; if not, create Case functions as custom functions, but this time the Case functions are chained by their optional default result parameters.
This isn’t the end of the story. The layers involved in creating a real-world grammar checker increase. Because the Substitute function is case-sensitive two pairs of each word are required, one capitalised. Many words in the English language have two or more parts of speech – for example, “lead” (noun: metal; verb: to guide) and “read” (“to read”; “have read”) – and these need factoring in.
There are other exceptions to the rules that would require additional layering across all the modules. Furthermore, enhancements are possible: extracting and displaying the snippet of text in question and allowing the user to modify and re-insert it; and the possibility of increasing the coverage to include questionable word and phrase usage – for example, automatically correcting the tautology, “revert back to”, to “revert to”.