IMPORT statement includes rules contained in another source file.
The syntax is:
file is the corresponding path of a rules file.
The file path must be written between quotation marks.
When a build is performed, the
IMPORT statement is replaced by the contents of the referenced rules file, so essentially, it is as if the file containing the
IMPORT statement and the referenced file merged into one large file, which is the sum of the two files put together.
The advantage of using
IMPORT is that you can divide the rules of a project into multiple files which are easier to interpret and manage as opposed to just a single large file.
If your project is complex, with many categories or template-field pairs and a lot of rules,
IMPORT will provide a structure in which the rules can be kept in order.
For example, in a categorization project, it is advisable to have a different file for every branch of a taxonomy, or in some cases, for every category. Similarly, in an extraction project there should be a file for every template or even for every field, depending on the number of rules. This makes rules easier to find and manage.
If segments and sub-rules are used, they should be kept in separate files and they should be imported first (before the categorization and/or extraction rules). The proper order will ensure that the rules which reference the segments or sub-rules are processed after the definition of these two elements.
IMPORT "subrules.cr" IMPORT "segments.cr" IMPORT "category1.cr" IMPORT "category2.cr"
The same file cannot be imported more than once and circular imports are not permitted (where file A imports file B and file B imports file A).
The import file path can include sub-folders, such as this example:
In this way, rules can be divided among multiple files and these files can be organized into folders and sub-folders, if further structuring of the project is deemed necessary.
IMPORT starts to check the source files from the relative path in which the importing
.cr file is placed. That means the import starts first from the subfolder and then from the rules folder.
For example, in case where the
rugby.cr file is inside a subfolder
sport and a
oval.cr source file is created in the same subfolder, the correct
IMPORT syntax in
When the path includes sub-folder, please note that the slash character (
/) is compatible with both Linux and Windows production environments, while backslash (
\) can be used only in Windows.