# Java Examples

This directory contains a few examples on how to use the Okapi library with your own Java programs.

The examples have been pre-compiled. You can execute them by running `run_examples.bat` (Windows) or `run_examples.sh` (Linux and Macintosh).

Make sure to have the examples in a directory where you have write-rights.

If you wish to modify and re-compile the examples:

- Make sure you have Oracle Java or an OpenJDK compiler (v1.6 or later) installed.
- Run `build_examples.bat` (Windows) or `build_examples.sh` (Linux and Macintosh).

## Example01

This example shows how to create and execute a pipeline with three or four steps:

- The first step converts a given input document into a set of filter events, using the appropriate filter for the given input document.
- The second step pseudo-translate the translatable text of the input document.
- The third step converts all letters of the translatable text into uppercase.
- The fourth step re-create the original document with the modified text.

You can choose to run both middle steps or just one of them from the command-line option.

## Example02

This example takes a properties file or an OpenOffice.org document and print to the console all translatable text. The inline codes inside the text are displayed with generic markers such as: `<1>`...`</1>`, `<2/>`.

## Example03

This example takes a file `test.xml` (complied into the jar, but you can see it in the `src` directory) and runs a pipeline with four steps:

- The first step takes the input document and processes it with a first XSLT template that just re-create the input to an output.

- The second step takes the output f the first one, and processes with a second XSLT template that removes `<b>` nodes.

- The third step takes the output of the second one and converts the document into filter events, using the XML filter.

- The fourth step takes the filter events sent by the third step and create an output stream. Then that output is displayed on the standard output.

## Example04

This example shows some of the functionality provided by the segmenter included in the Okapi Library. It uses the `myRules.srx` SRX file included in the sample files to segment some example text.

## Example05

This example shows how to use some of the TM and MT query connectors that are provided with the Okapi Library. The first part demonstrates the Apertium MT server. The second part shows how to query the Amagama TM server. Both have public servers that should be accessible to everyone running the demo.