Skip to content

Write code

You write rules and scripts using Studio programming languages.

Rules and scripts are to be written inside text files with specific extensions: rules files must have the .cr extension, script files must have the .jr extension.

Both types of files are kept in the rules folder of the project structure.

Default code

Studio project modules initially contain the code of a sample text intelligence engine. Albeit minimal, this engine is already capable of categorization and extraction.
Three files are automatically created inside the rules folder:

  1. a rules file containing sample declarations of sections, segments and extraction templates.
  2. a rules file containing an IMPORT statement—it incorporates the file at runtime—and two simple rules, one for categorization and the other for extraction.
  3. main.jr: a script containing empty event handling functions.

The project also has a pre-defined sample taxonomy inside the taxonomy.xml file. The sample categorization rule in the file refers to a category defined in that taxonomy file.

Replace the default code with your own.

Main files is the main rules file.
You must write all your rules inside it or have your rules split in several .cr files provided that you use the IMPORT statement to include those files in the file.
Inclusion can be recursive. For example, you can make main.jr include files and, then have include and so on.
Please refer to the IMPORT statement documentation. is a convenient place to write project-wide definitions and options. In the event your project does not require these, the file can be removed.

main.jr is the main script file. The default file already contains the definitions of the event handlers.
You can put your scripting code in that file or use other files, but, in that case, you must structure the code in those files as modules and use the require statement to use their code in main.jr.
For example:

var regexcleaner = require('modules/regexcleaner');


The modules of a script are not to be confused with the modules of a project. The modules of a project are independent sub-projects, each of which corresponds to a text intelligence engine. The modules of a script are sub-programs that you can use in the script.


If you decide to divide your rules and your scripts among multiple files, you can organize these files as you wish in sub-folders of the rules directory.

Find more information in the article about creating and managing files and folders.

Code writing tools

The following articles in this section of this manual illustrate the main tools available for writing rules and scripts.

You can write rules from scratch using the Rules language or you can start from rule templates.

Smart completion helps you write code faster and without errors.

Whenever you need to specify syncons or lemmas in your statements, you can use the Knowledge Graph and the Knowledge Graph Search tool windows.
If you want to check syncons and lemmas that are already in the code, use the knowledge graph lookup commands. You can also get quick information on a syncon indicated in the code.

IntelliJ IDEA, the platform on which Studio is based, provides powerful search-and-replace features.


Add comments to your code. The experience of many programmers teaches that the time spent commenting the code is largely saved when the program has to be maintained. Read the article about this topic to learn how to do it.

As you write code, these features can also help:

Code selection

Studio provides several useful ways to select code. Discover them in the article dedicated to this topic.

Add and delete lines

  • To add a line after the current one, press Shift+Enter.

  • To add a line before the current one, press Ctrl+Alt+Enter.

  • To duplicate a line, press Ctrl+D.

  • To delete a line, press Ctrl+Y.


Studio automatically saves files as a consequence of these actions:

  • Build
  • Analysis & debug
  • Version control operations
  • Closing a file or a project
  • Quitting the IDE

To change the auto-save behavior:

  1. Select File > Settings > Appearance and Behavior > System Settings.
  2. Review the auto-save settings in the Autosave area.


To save all the changed files at once whenever you want:

  • Select File > Save All on the main menu.


  • Press Ctrl+S.

Undo and redo changes

To undo changes:

  • Press Ctrl-Z


  • Select Edit > Undo Action on the main menu.

To redo changes:

  • Press Ctrl-Shift-Z


  • Select Edit > Redo Action on the main menu.


Action is the action type to undo or redo.

For more sophisticated change management, you can use the local history (see below) or a VCS.

Local history

Local history keeps track of file changes happening on the local computer without requiring a VCS.
This allows seeing the chronology of the changes for rules files and script files. It also allows rolling back a file to any previous stage.


Local history is limited in terms of time and size. By default, it is configured to store changes for the last five working days.

For more information on the local history functionality and the ways to compare and restore versions, see the IntelliJ IDEA documentation.

View a file's local history

  1. Open or select the file in the editor.

  2. Select VCS > VCS Operations > Show History on the main menu.


    Right-click inside the file tab or anywhere inside the file and choose Local History > Show History.


  1. In the Project tool window, right-click the file and choose Local History > Show History.

Selection history

It is possible to see the history of a part of a file.

  1. Open the file or select it in the editor.
  2. Select the part to inspect.
  3. Right-click the selection and choose Local History > Show History for Selection.