in reply to using Word dictionary in Perl

Hi, ashok

This is how you can use the MSWord SynonymInfo method from perl using Win32::OLE. Need I say that it is not portable, so you'll have to find another way to do it on *nix boxes :)
#!/usr/bin/perl -w # Uses use strict; use Win32::OLE; use Win32::OLE::Const; # Create MSWord object and load constants my $MSWord = Win32::OLE->new('Word.Application', 'Quit') or die "Could not load MS Word\n"; my $wd=Win32::OLE::Const->Load($MSWord); # Word and language to search for my $word="big"; my $language=$wd->{wdEnglishUS}; # Get antonyms from MSWord my $antonyms=$MSWord->SynonymInfo( {Word => $word, LanguageID => $language})->AntonymList; # Print them out... foreach (@{ $antonyms }) { print $_."\n" };
Anoter way might be to use LWP and search an online dictionary (like Lexical FreeNet) and parse the returned page. The url to get the antonyms for "big" on lexfn is http://www.lexfn.com/l/lexfn-cuff.cgi?sWord=big&tWord=&query=show&maxReach=2&Aant=on

/brother t0mas

Replies are listed 'Best First'.
Re: Re: using Word dictionary in Perl
by Anonymous Monk on Dec 02, 2000 at 23:01 UTC
    Hi , It's great. It really helped me a lot. Can you pl. give me the code for finding Synonym also? I tried to use your code but I failed. I thought it will be like this
    # Get synonyms from MSWord my $synonyms=$MSWord->SynonymInfo( {Word => $word, LanguageID => $language})->SynonymList; # Print them out... foreach (@{ $synonyms }) { print $_."\n" };
    But it did not work. Thanks Ashok
      Your'e just (1) from correct. :)
      #!/usr/bin/perl -w # Uses use strict; use Win32::OLE; use Win32::OLE::Const; # Create MSWord object and load constants my $MSWord = Win32::OLE->new('Word.Application', 'Quit') or die "Could not load MS Word\n"; my $wd=Win32::OLE::Const->Load($MSWord); # Word and language to search for my $word="big"; my $language=$wd->{wdEnglishUS}; # Get synonyms from MSWord my $synonyms=$MSWord->SynonymInfo( {Word => $word, LanguageID => $language})->SynonymList(1); # Print them out... foreach (@{ $synonyms }) { print $_."\n" };
      The (1) returns the synonymlist for the first meaning of the word. If you have a word that can mean many things, you could end up with many synonymlists. You'll then have to check the MeaningCount property and loop all the synonymlists for each meaning.

      /brother t0mas
        Hi, I could run this program on my PC installed with WIN 98 os(With Active Perl). But the same not working on WIN NT. I am using Indigo PERL on WIN NT. The error is
        Win32::OLE::Const->Load: No or invalid type library name at test.pl li +ne #some no# Win32::OLE(0.13): GetOleTypeLibObject() Not a Win32::OLETypeLib object + at e:/perl56i/site/lib/Win32/OLE/Const.pm line 34.
        Is there any problem with library module Const.pm or it does not work on WIN NT. I appreciate your help. I thoughtof cutting and pasting the error. I used perl test.pl > error.txt. But the above error is not copied to error.txt. I also need how to redirect error to a file on Win NT. There are no buttons to cut and paste. I am trying this program at MS Dos command Prompt. Thanks Ashok