Chapter 4. Using An Gramadóir as a library

There are two senses in which An Gramadóir can be used as a library. The first, and most powerful, is to write your code in Perl and use the module Lingua::XX::Gramadoir via the handful of methods it exports (for segmentation, tokenization, tagging, etc. in addition to grammar checking). These methods are reasonably well-documented; see for example the POD documentation that comes bundled with the Irish version.

The second way to use An Gramadóir as a library is via the command line option --api to the script gram-xx.pl. This approach requires that you do a system call or equivalent from your program to pass the input text to the script. When the --api option is specified, the output is well-formed XML that can be parsed and processed appropriately by your program. One drawback is that this is only an API for grammar checking and there is no way to extract additional information (e.g. part-of-speech tags) from the output. On the other hand, the syntax of the output has been standardized after extensive discussions with developers of other open source grammar checking engines, and will hopefully be used as a standard interface for grammar checking in OpenOffice.org and KDE. So, by writing a bit of code to parse the --api output, your program will be able to work seamlessly with An Gramadóir as well as any other grammar checkers conforming to this standard, such as LanguageTool. Here is a DTD for reference purposes.