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.