Eduction 23.4

# Standalone API Usage

This section describes the basic structure of a standalone application using the API. See the source referenced in Example Programs. Typically, your application takes the following actions:

1. Load the EDK library.

   Copy

       System.loadLibrary("edkjni");

2. Create an `EDKFactory` instance of a `TextExtractionFactory`, supplying a valid license key.

   Copy

       try ( TextExtractionFactory<EDKMatch> factory = EDKFactory.fromLicenseKey("...") ) {
           // use try-with-resources to automatically cleanup factory once finished or if an exception occurs
           // rest of the processing code goes here ...
       }

3. Use the factory to create an instance of a `TextExtractionEngine`.

   Copy

       try ( TextExtractionEngine<EDKMatch> engine = factory.createEngineFromConfigFile(Paths.get("path", "to", "config.cfg")) ) {
           // use try-with-resources to automatically cleanup engine once finished or if an exception occurs
           // rest of the processing code goes here ...
       }

   You can specify the options, grammar files, and entities to use in the configuration file. Alternatively the SDK provides functions for setting options programmatically (see the `FromSettings.java` example).

4. Decide whether to push data to the engine when it becomes available, or have the engine read from a stream when it needs more data. The data must be UTF-8 encoded. The following example demonstrates how to read from a stream. The stream is passed to an `EDKJNIInputStream` object which reads the stream when required.

   Copy

       try ( FileInputStream in = new FileInputStream("input.txt") ) {
           ReadableInputStream stream = new EDKJNIInputStream(in);
           // ...
       }

   Pass the `EDKJNIInputStream` to a `TextExtractionSession` object, which maintains the state of the matching process. If your application is multi-threaded then each thread should use its own `TextExtractionSession`.

   Copy

       try ( TextExtractionSession<EDKMatch> session = engine.createSession() ) {
           session.setInputStream(stream);
           // ...
       }

5. Begin matching.

   Copy

       for (EDKMatch match : session) {
           System.out.println(match.getText());
       }

   NOTE: If you create your Eduction engine from a configuration file that includes post-processing tasks, the post-processing tasks automatically run as part of `EDKMatch` and you do not need to run them separately.

6. Release resources when done.

Copyright 2013-2023 Open Text
Version 23.4 | Last updated September 2023

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to swpdl.idoldocsfeedback@microfocus.com.

We appreciate your feedback!

Product: IDOL Eduction 23.4

Topic Title: Standalone API Usage