IMPORTANT NOTICE - Apr-30-2009:
This .NET implementation of Okapi is no longer actively developed.
Instead, a NEW JAVA IMPLEMENTATION IS AVAILABLE and is being actively developed.

The material on this Web site is for archive propose. Some applications of the old .NET implementation (e.g. Olifant) will be maintained to some degree until they have a replacement in the Java project.

Filters

See the Example 1 for a code sample on how to use one of the filters in a script.

Utility Sets

See the Example 2 for a code sample on how to use one of the utility in a script.

Libraries

In addition to the high-level filters and utilities, a wide set of .NET library modules are also available:

Module           Description
Okapi.Library.Base.dll   Base library. Provides a class implementing ILog.
Okapi.Library.EDocument.dll   Support classes for Extracted documents.
Okapi.Library.Filters.dll   Support classes for the filters. Provides a class implementing IFilterItem.
Okapi.Library.TM.dll   Support classes for translation memory services.
Okapi.Library.UI.dll   Support classes for UI-based applications.
Okapi.Library.Utility.dll   Support classes for the utilities. Provides a base-class implementing IUtilitySet.
Okapi.Library.MT.dll   Support classes for machine translation services.
Okapi.Library.Segmentation.dll   Support classes for segmentation. Provides a class implementing ISegmenter.
Okapi.Library.WordProofReading   Support classes for Proof reading with MSWord.
Okapi.MT.Google.dll   Support library for Google MT access. Provides a class implementing IMTQuery.
Okapi.MT.WorldLingo.dll   Support library for WorldLingo MT access. Provides a class implementing IMTQuery.
Okapi.TM.Manager.dll   Support classes for translation memory management.

Note that low-level libraries may not always be accessible through COM.

Examples

You can use the Okapi components from within any applications that supports either .NET or COM. For example, in JavaScript, Microsoft Word or Excel, in Visual Basic, etc. The utilities components can also be launch by Tikal, a common-line tool ready to be used.

Example 1

This first example shows how to use a filter component (here the PO Filter) in a JavaScript function to output a simple output text file all text items of a PO input file. Each item being written on a separate line.

The function uses three Okapi components: the Log (the Log variable), the PO Filter (the Flt variable), and a Filter Item object (the FI variable).

function DoExtraction ()
{
 try
 {
  var sInputPath = "myInput.po";
  var sOutputPath = "myExtractedPOFile.txt";
  var sLang = "en-us";
  var sEncoding = "windows-1252";

  var Log = new ActiveXObject("Okapi.Library.Base.Log");
  var Flt = new ActiveXObject("Okapi.Format.PO.Filter");
  var FI;
  var lRes = 0;

  // Initialize the filter object
  Flt.Initialize(Log);
  // Start the log/feedback
  Log.BeginProcess ("Extraction Example");
  // Display the log
  Log.Show();

  // Open the input file
  if ( !Flt.OpenInputFile(sInputPath, sLang, sEncoding) )
  {
   alert("Error: Cannot open " + sInputPath);
   return;
  }

  // Create the output text file
  var Fso = new ActiveXObject("Scripting.FileSystemObject");
  var Out = Fso.CreateTextFile(sOutputPath, true, true);

  // Process the input file
  do
  {
   lRes = Flt.ReadItem(); // Read the next item in the input file
   if ( lRes == 3 ) // If it's a text item: extract it
   {
    // Get the filter item object
    FI = Flt.GetItem();
    // Use the GetText(8) for outputting the text in its original format
    // Use GetText(0) for coded-text, etc.
    Out.WriteLine(FI.GetText(8)); 
   }
  }
  while ( lRes > 2 );
  // Continue until ReadItem() returns an error (lRes=0), or the user cancel
  // the process (lRes=1), or the end of the input is reached (lRes=2)

  Out.Close();
  // Close the input file
  Flt.CloseInput();
  alert("Done.");
 }
 catch ( Excp )
 {
  alert("Exception error. " + Excp.Message );
 }
 finally
 {
  Log.EndProcess("");
 }
}

The exact same program could be used with filters, supporting other file formats.

Example 2

The second example demonstrate how to use one of the Okapi utilities (Text Extraction) from a Word Basic program.

The sub-routine uses two Okapi components: the Log (the Log variable) and the Utility Set 01 (the Utl variable). Once the utility set is loaded and initialized, the SetCurrentUtility() method is used to activate proper the utility through its identifier ("extraction"). The EditOptions() method allows the user to select the options of the utility (here, we select the RTF output format). The next step is to specify the common parameters for this utility: the methods SetLanguages(), SetRoot(), AddInput() and AddOutput() are called for this purpose. Then the Execute() method start the extraction process.

Sub OkapiMakeRTF()

Dim Log As Object
Set Log = CreateObject("Okapi.Library.Base.Log")
Dim Utl As Object
Set Utl = CreateObject("Okapi.Utilities.Set01.UtilitySet")
Utl.Initialize Log

Log.BeginProcess ("RTF Example")
Utl.SetCurrentUtility ("extraction")

' Here the opions for the Text Extraction utility are presented to the user.
' He/she needs to select the RTF format for the output.
If (Not Utl.EditOptions(True)) Then
   Log.Warning ("Edit options cancelled.")
   GoTo TheEnd
End If

Utl.SetLanguages "en", "fr"
Utl.SetRoot 0, ActiveDocument.Path
Utl.AddInput 0, ActiveDocument.Path + "\Test01.po", "okf_po", "windows-1252"
Utl.AddOutput Nothing, "windows-1252"

Utl.Execute True

Dim sOutFile As String
sOutFile = Utl.GetLastOutputFolder() + "\Work\Test01.po.rtf"
Documents.Open (sOutFile)

TheEnd:

Log.EndProcess ("")
If (Log.GetErrorAndWarningCount() > 0) Then
   Log.Show
End If

End Sub