//================================================================

// ===== COM Test Example for Dialing Lemmatizer (www.aot.ru) ==

// ===== Author: Alexey Sokirko, sokirko@yandex.ru, 2005 =======

//================================================================

 

program MorphTest;

 

{$APPTYPE CONSOLE}

 

uses

  SysUtils,

  ActiveX,

//Unit LEMMATIZERLib_TLB.pas is generated by $Rml/Bin/Lemmatizer.dll. In Delphi 6 one should use menu "Project/Import Type Library".

  LEMMATIZERLib_TLB in '..\..\..\..\Program Files\Borland\Delphi6\Imports\LEMMATIZERLib_TLB.pas',

//Unit AGRAMTABLib_TLB.pas is generated by $Rml/Bin/Agramtab.dll. In Delphi 6 one should use menu "Project/Import Type Library".

  AGRAMTABLib_TLB in '..\..\..\..\Program Files\Borland\Delphi6\Imports\AGRAMTABLib_TLB.pas';

 

procedure TestRusLemmatizer(word : string);

var  RusLemmatizer : ILemmatizer;

     ParadigmCollection : IParadigmCollection;

     Paradigm : IParadigm;

     RusGramTab :    IGramTab;

     OneAncode, SrcAncodes : string;

     i,j : integer;

 

begin

    // loading morphological dicitonary

    RusLemmatizer := CoLemmatizerRussian.Create;

    if  (RusLemmatizer = nil) then

    begin

        writeln('cannot load lemmatizer');

        halt(1);

    end;

    RusLemmatizer.LoadDictionariesRegistry();

    // loading table of gram-codes

    RusGramTab := CoRusGramTab.Create;

    if  (RusGramTab = nil) then

    begin

        writeln('cannot load table for grammatical codes');

        halt(1);

    end;

    RusGramTab.Load;

 

 

    ParadigmCollection := RusLemmatizer.CreateParadigmCollectionFromForm(word, 1, 1);

    if (ParadigmCollection.Count = 0) then

    begin

        writeln('not found');

        exit;

    end;

    writeln('характеристики слова "',word, '":');

    for j:=0 to ParadigmCollection.Count-1 do

      begin

        Paradigm := ParadigmCollection.Item[j];

        writeln(' {');

        writeln('   лемма = ',Paradigm.Norm);

        writeln('   Id = ',Paradigm.ParadigmID);

        write('   граммемы = ');

        i:=1;

        SrcAncodes := Paradigm.SrcAncode;

        while  i < Length(SrcAncodes) do

        begin

            OneAncode := Copy(SrcAncodes,i,2);

            write(RusGramTab.GetPartOfSpeechStr( RusGramTab.GetPartOfSpeech(OneAncode) ));

            write(' ');

            write(RusGramTab.GrammemsToStr( RusGramTab.GetGrammems(OneAncode) ));

            write('; ');

            inc (i, 2);

        end;

        writeln;

        writeln(' }');

      end

end;

 

var   hr :  HRESULT;

begin

try

    hr := CoInitialize(nil);

    if (hr <> S_OK) then

    begin

        writeln('cannot load Component Object Model(COM) library');

        halt(1);

    end;

    TestRusLemmatizer('стать');

    CoUninitialize();

except

    writeln('an exception occurred!');

end;

 

 

end.