Number of N-grams in database

C/C++:

int sol_CountNGrams( HGREN hEngine, int Type, int Order, unsigned int * Hi, unsigned int * Lo )

C#:

int sol_CountNGrams( IntPtr hEngine, int Type, int Order, out UInt32 Hi, out UInt32 Lo )

UInt64 sol_CountNGramsFX( IntPtr hEngine, int Type, int Order )

Delphi:

function sol_CountNGrams( hEngine: PInteger; Flags: Integer; Order: Integer; Hi: PInteger; Lo: PInteger ): Integer;

function sol_CountNGrams64( hEngine: PInteger; Flags: Integer; Order: Integer ): Int64;

Parameters:

hEngine - grammatical dictionary instance handle.

Type - 0 for literal, 1 for lemmatized patterns.

Order - N-gram order, 1 to 5.

Lo - Pointer to 32 bit integer for storing the low half of 64 bit result.

Hi - Pointer to 32 bit integer for storing the high half of 64 bit result.

Return value:

1 for success, 0 if an error has occured.

Remarks

Helper function sol_CountNGramsFX is a wrapper for sol_CountNGrams. It returns the 64-bit counter.

The following functions can be used to get the frequency of particular N-gram: sol_Seek1Grams, sol_Seek2Grams, sol_Seek3Grams, sol_Seek4Grams, sol_Seek5Grams.

C++ sample code:

#include "solarix_grammar_engine.h"

unsigned int Hi=0, Lo=0;
int rc = sol_CountNGrams(hEngine,0,3,&Hi,&Lo);
__int64 Freq = (__int64(Hi)<<32) | (unsigned __int64)Lo;
 
// ...

C# sample code:

 IntPtr hEngine = GrammarEngine.sol_CreateGrammarEngineW("..\\..\\..\\..\\..\\..\\..\\bin-windows\\dictionary.xml");
  
 UInt64 ngram_count1 = GrammarEngine.sol_CountNGramsFX( hEngine, 1, 1 );
 UInt64 ngram_count2 = GrammarEngine.sol_CountNGramsFX( hEngine, 1, 2 );
 UInt64 ngram_count3 = GrammarEngine.sol_CountNGramsFX( hEngine, 1, 3 );
 UInt64 ngram_count4 = GrammarEngine.sol_CountNGramsFX( hEngine, 1, 4 );
 UInt64 ngram_count5 = GrammarEngine.sol_CountNGramsFX( hEngine, 1, 5 );

Delphi sample:

uses SysUtils, Windows,
  _sg_api in '..\..\..\..\..\include\lem\solarix\pro\_sg_api.pas',
  GrammarEngineApi in '..\..\..\..\..\include\lem\solarix\GrammarEngineApi.pas';

var hEngine: PInteger;
var ngram_count1, ngram_count2, ngram_count3, ngram_count4, ngram_count5: Int64;
begin

 hEngine := sol_CreateGrammarEngineA( '..\..\..\..\..\bin-windows\dictionary.xml' );

 ngram_count1 := sol_CountNGrams64( hEngine, 1, 1 );
 ngram_count2 := sol_CountNGrams64( hEngine, 1, 2 );
 ngram_count3 := sol_CountNGrams64( hEngine, 1, 3 );
 ngram_count4 := sol_CountNGrams64( hEngine, 1, 4 );
 ngram_count5 := sol_CountNGrams64( hEngine, 1, 5 );

 { ... }

 sol_DeleteGrammarEngine(hEngine);

end.

Navigation

Purchase the Grammatical Dictionary SDK

Russian version of this page

N-grams database assembler

API layer C++ source code: grammar_engine_api.cpp

Back to API functions list

  © Козиев Илья 2019
last change 04-Apr-11