Hi all,
Caveat: ABSOLUTE, COMPLETE n00b to perl. I'm only using it because it has the wonderful WordNet::Similarity module that I need for some textual analysis.
The problem:
I am running the aforementioned WordNet::Similarity module through a VBA script to calculate a ton of semantic relatedness formulas on documents in an excel sheet (they need to stay in an excel sheet, too, so I can't try mysql or anything like that).
The perl module works fine, except that it loads the massive WordNet lexicon every single time it runs, which would take too long to be practical for the literally hundreds of thousands of times that I need to run the module.
I need the absolute simplest way to keep the WordNet lexicon loaded as a perl variable while the Similarity module runs all the queries and calculates the formulae. I have been trying to follow a procedure that I found mentioned
here, but to pretty much no avail. It boots me with a message of "Can't use an undefined value as a HASH reference in DBM/Deep/Hash.pm line 33."
Here are my scripts, can you offer any help? Again, I just need the absolute simplest, most sure-fire method for doing this. I just need read-only access to the lexicon, and only for about a minute or two while the other scripts run the formulas. I've seen modperl, but would prefer to not use a server, as its too much to configure for just this purpose.
Initialize script (to supposedly load the WordNet lexicon into a DBM::Deep-readable database):
use WordNet::QueryData;
my $x= WordNet::QueryData->new();
delete $x->{data_fh};
use DBM::Deep;
my $h=DBM::Deep->new("wordnet.db");
$h->{foo}=$x;
And the script to actually run the queries:
#! C:\Perl\bin -w
use strict;
use warnings;
# Sample Perl program, showing how to use the
# WordNet::Similarity measures.
# WordNet::QueryData is required by all the
# relatedness modules.
use WordNet::QueryData;
# 'use' each module that you wish to use.
use WordNet::Similarity::wup;
# Get the concepts.
my $wps1 = shift;
my $wps2 = shift;
# Load WordNet::QueryData
use DBM::Deep;
my $h = DBM::Deep->new("wordnet.db")->{foo};
#convert the top level to regular hash
my $wn = {}; %$wn=%$h;
delete $wn->{data_fh};
#restore contents of $wn->{data_fh}
bless $wn, 'WordNet::QueryData';
$wn->openData;
# Create an object for each of the measures of
# semantic relatedness.
my $wup = WordNet::Similarity::wup->new($wn, "/config-files/config-wup
+.conf");
# Find the relatedness of the concepts using each of
# the measures.
my $value = $wup->getRelatedness($wps1, $wps2);
The "WordNet::QueryData" module is the one that loads the lexicon.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.