File Coverage

blib/lib/Word2vec/Interface.pm
Criterion Covered Total %
statement 25 27 92.5
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 34 36 94.4


line stmt bran cond sub pod time code
1             #!usr/bin/perl
2            
3             ######################################################################################
4             # #
5             # Author: Clint Cuffy #
6             # Date: 06/16/2016 #
7             # Revised: 11/14/2017 #
8             # UMLS Similarity Word2Vec Package Interface Module #
9             # #
10             ######################################################################################
11             # #
12             # Description: #
13             # ============ #
14             # Perl "word2vec" package interface for UMLS Similarity #
15             # #
16             ######################################################################################
17            
18            
19             package Word2vec::Interface;
20            
21 3     3   131682 use strict;
  3         24  
  3         78  
22 3     3   13 use warnings;
  3         6  
  3         62  
23            
24             # Standard Package(s)
25 3     3   12 use Cwd;
  3         4  
  3         130  
26 3     3   1055 use File::Type;
  3         37572  
  3         148  
27 3     3   1454 use Sys::CpuAffinity;
  3         155236  
  3         112  
28            
29             # Word2Vec Utility Package(s)
30 3     3   1111 use Word2vec::Spearmans;
  3         7  
  3         78  
31 3     3   1789 use Word2vec::Word2vec;
  3         10  
  3         178  
32 3     3   1364 use Word2vec::Word2phrase;
  3         7  
  3         82  
33 3     3   1504 use Word2vec::Xmltow2v;
  0            
  0            
34             use Word2vec::Wsddata;
35             use Word2vec::Util;
36            
37            
38             use vars qw($VERSION);
39            
40             $VERSION = '0.037';
41            
42            
43             ######################################################################################
44             # Constructor
45             ######################################################################################
46            
47             BEGIN
48             {
49             # CONSTRUCTOR : DO SOMETHING HERE
50             }
51            
52            
53             ######################################################################################
54             # Deconstructor
55             ######################################################################################
56            
57             END
58             {
59             # DECONSTRUCTOR : DO SOMETHING HERE
60             }
61            
62            
63             ######################################################################################
64             # new Class Operator
65             ######################################################################################
66            
67             sub new
68             {
69             my $class = shift;
70             my $self = {
71             # Private Member Variables
72             _word2vecDir => shift, # String (word2vec package program directory)
73             _debugLog => shift, # Boolean (Binary): 0 = False, 1 = True
74             _writeLog => shift, # Boolean (Binary): 0 = False, 1 = True
75             _ignoreCompileErrors => shift, # Boolean (Binary): 0 = False, 1 = True
76             _ignoreFileChecks => shift, # Boolean (Binary): 0 = False, 1 = True
77             _exitFlag => shift, # Boolean (Binary): 0 = False, 1 = True
78             _workingDir => shift, # String (current working directory)
79             _spearmans => shift, # "Word2vec::Spearmans" module object
80             _word2vec => shift, # "Word2vec::Word2vec" module object
81             _word2phrase => shift, # "Word2vec::Word2phrase" module object
82             _xmltow2v => shift, # "Word2vec::Xmltow2v" module object
83             _util => shift, # "Word2vec::Util" module object
84            
85             # Word Sense Disambiguation Variables
86             _instanceAry => shift, # Array Of 'Word2vec::Wsddata' Elements
87             _senseAry => shift, # Array Of 'Word2vec::Wsddata' Elements
88             _instanceCount => shift, # Integer
89             _senseCount => shift, # Integer
90             };
91            
92             # Set Variable Default If Not Defined
93             $self->{ _debugLog } = 0 if !defined ( $self->{ _debugLog } );
94             $self->{ _writeLog } = 0 if !defined ( $self->{ _writeLog } );
95             $self->{ _ignoreCompileErrors } = 1 if !defined ( $self->{ _ignoreCompileErrors } );
96             $self->{ _ignoreFileChecks } = 0 if !defined ( $self->{ _ignoreFileChecks } );
97             $self->{ _exitFlag } = 0 if !defined ( $self->{ _exitFlag } );
98            
99             @{ $self->{ _instanceAry } } = () if !defined ( $self->{ _instanceAry } );
100             @{ $self->{ _instanceAry } } = @{ $self->{ _instanceAry } } if defined ( $self->{ _instanceAry } );
101            
102             @{ $self->{ _senseAry } } = () if !defined ( $self->{ _senseAry } );
103             @{ $self->{ _senseAry } } = @{ $self->{ _instanceAry } } if defined ( $self->{ _senseAry } );
104            
105             $self->{ _instanceCount } = 0 if !defined ( $self->{ _instanceCount } );
106             $self->{ _senseCount } = 0 if !defined ( $self->{ _senseCount } );
107            
108             # Open File Handler if checked variable is true
109             if( $self->{ _writeLog } )
110             {
111             open( $self->{ _fileHandle }, '>:utf8', 'InterfaceLog.txt' );
112             $self->{ _fileHandle }->autoflush( 1 ); # Auto-flushes writes to log file
113             }
114             else
115             {
116             $self->{ _fileHandle } = undef;
117             }
118            
119             bless $self, $class;
120            
121             $self->WriteLog( "New - Debug On" );
122             $self->WriteLog( "New - No Working Directory Specified - Using Current Directory" ) if !defined( $self->{ _workingDir } );
123             $self->{ _workingDir } = Cwd::getcwd() if !defined( $self->{ _workingDir } );
124             $self->WriteLog( "New - Setting Working Directory To: \"" . $self->{ _workingDir } . "\"" ) if defined( $self->{ _workingDir } );
125            
126             if( !defined( $self->{ _word2vecDir } ) )
127             {
128             $self->WriteLog( "New - No Word2Vec Directory Specified / Searching For Word2Vec Directory" );
129            
130             for my $dir ( @INC )
131             {
132             $self->{ _word2vecDir } = "$dir/External/Word2vec" if ( -e "$dir/External/Word2vec" ); # Test Directory
133             $self->{ _word2vecDir } = "$dir/../External/Word2vec" if ( -e "$dir/../External/Word2vec" ); # Dev Directory
134             $self->{ _word2vecDir } = "$dir/../../External/Word2vec" if ( -e "$dir/../../External/Word2vec" ); # Dev Directory
135             $self->{ _word2vecDir } = "$dir/Word2vec/External/Word2vec" if ( -e "$dir/Word2vec/External/Word2vec" ); # Release Directory
136             }
137            
138             $self->WriteLog( "New - Word2Vec Executable Directory Found" ) if defined( $self->{ _word2vecDir } );
139             $self->WriteLog( "New - Setting Word2Vec Executable Directory To: \"" . $self->{ _word2vecDir } . "\"" ) if defined( $self->{ _word2vecDir } );
140             }
141            
142             # Initialize "Word2vec::Word2vec", "Word2vec::Word2phrase", "Word2vec::Xmltow2v" and "Word2vec::Util" modules
143             my $debugLog = $self->{ _debugLog };
144             my $writeLog = $self->{ _writeLog };
145             $self->{ _spearmans } = Word2vec::Spearmans->new( $debugLog, $writeLog ) if !defined ( $self->{ _spearmans } );
146             $self->{ _word2vec } = Word2vec::Word2vec->new( $debugLog, $writeLog ) if !defined ( $self->{ _word2vec } );
147             $self->{ _word2phrase } = Word2vec::Word2phrase->new( $debugLog, $writeLog ) if !defined ( $self->{ _word2phrase } );
148             $self->{ _xmltow2v } = Word2vec::Xmltow2v->new( $debugLog, $writeLog, 1, 1, 1, 1, 1, 2 ) if !defined ( $self->{ _xmltow2v } );
149             $self->{ _util } = Word2vec::Util->new( $debugLog, $writeLog ) if !defined ( $self->{ _util } );
150            
151             # Set word2vec Directory In Respective Objects
152             $self->{ _word2vec }->SetWord2VecExeDir( $self->{ _word2vecDir } );
153             $self->{ _word2phrase }->SetWord2PhraseExeDir( $self->{ _word2vecDir } );
154            
155             # Run Word2Vec Package Executable/Source File Checks
156             my $result = $self->RunFileChecks( $self->{ _word2vecDir } );
157            
158             # Set Exit Flag
159             $self->WriteLog( "New - Warning: An Error Has Occurred / Exit Flag Set" ) if $result == 0;
160             $self->{ _exitFlag } = $result;
161            
162             return $self;
163             }
164            
165            
166             ######################################################################################
167             # DESTROY
168             ######################################################################################
169            
170             sub DESTROY
171             {
172             my ( $self ) = @_;
173            
174             # Close FileHandle
175             close( $self->{ _fileHandle } ) if( $self->{ _fileHandle } );
176             }
177            
178            
179             ######################################################################################
180             # Module Functions
181             ######################################################################################
182            
183             sub RunFileChecks
184             {
185             my ( $self ) = shift;
186             my $dir = shift;
187             my $result = 0;
188            
189             if ( $self->GetIgnoreFileChecks() == 1 )
190             {
191             $self->WriteLog( "RunFileChecks - Warning: Ignore File Checks = TRUE / Skipping File Checks" );
192             return 1;
193             }
194            
195             # Check(s)
196             $self->WriteLog( "RunFileChecks - Error: Directory Not Defined" ) if !defined( $dir );
197             return 0 if !defined( $dir );
198            
199             $self->WriteLog( "RunFileChecks - Error: Directory Does Not Exist" ) if !( -e $dir );
200             return 0 if !( -e $dir );
201            
202             # OS Check - Ignore Compile Errors If Operating System Is Windows
203             $self->SetIgnoreCompileErrors( 1 ) if ( $self->GetOSType() eq "MSWin32" );
204            
205             $self->WriteLog( "RunFileChecks - Running Module Check(s)" );
206             $self->WriteLog( "RunFileChecks - Word2Vec Dir: $dir" );
207             $self->WriteLog( "RunFileChecks - Word2Vec Directory Exists? Y" ) if ( -e "$dir" );
208             $self->WriteLog( "RunFileChecks - Error - Word2Vec Directory Exists? N" ) if !( -e "$dir" );
209             return 0 if !( -e "$dir" );
210            
211             # List of executable files to check for
212             my @fileNameVtr = qw( compute-accuracy distance word2phrase word2vec word-analogy );
213            
214             for my $fileName ( @fileNameVtr )
215             {
216             # Run file checks
217             if( $self->_CheckIfExecutableFileExists( $dir, $fileName ) == 0 )
218             {
219             $result = $self->_CheckIfSourceFileExists( $dir, $fileName );
220             $result = $self->_ModifyWord2VecSourceForWindows() if ( $result == 1 && $self->GetOSType() eq "MSWin32" );
221             $result = $self->_CompileSourceFile( $dir, $fileName ) if( $result == 1 );
222             $result = $self->_CheckIfExecutableFileExists( $dir, $fileName ) if( $result == 1 || $self->GetIgnoreCompileErrors() == 1 );
223             $self->_RemoveWord2VecSourceModification() if ( $result == 1 && $self->GetOSType() eq "MSWin32" );
224             }
225             else
226             {
227             $result = 1;
228             }
229            
230             $self->WriteLog( "RunFileChecks - Failed Word2Vec File Checks" ) if $result == 0;
231             return 0 if $result == 0;
232             }
233            
234             $self->WriteLog( "RunFileChecks - Passed Word2Vec File Checks" );
235             return $result;
236             }
237            
238             sub _CheckIfExecutableFileExists
239             {
240             my ( $self, $dir, $fileName ) = @_;
241            
242             # OS Check
243             $fileName .= ".exe" if ( $self->GetOSType() eq "MSWin32" );
244            
245             my $filePath = $dir . "/" . $fileName;
246             my $result = 0;
247            
248             $self->WriteLog( "_CheckIfExecutableFileExists - Checking For \"$fileName\" Executable File" );
249            
250             # Check if the directory exists
251             $result = 1 if ( -e "$dir" );
252            
253             # Continue if directory found
254             if ( $result == 1 )
255             {
256             # Check for executable file
257             $result = 0 if !( -e "$filePath" );
258             $result = 1 if ( -e "$filePath" );
259            
260             # Check file type
261             my $fileType = "";
262             $fileType = $self->GetFileType( $filePath ) if $result == 1;
263            
264             $result = 1 if $fileType eq "application/x-executable-file";
265             $self->WriteLog( "_CheckIfExecutableFileExists - Executable File Found" ) if $result == 1;
266             $self->WriteLog( "_CheckIfExecutableFileExists - Warning: Executable File Not Found" ) if $result == 0;
267             return $result;
268             }
269             else
270             {
271             $self->WriteLog( "_CheckIfExecutableFileExists - Specified Directory Does Not Exist" );
272             }
273            
274             return 0;
275             }
276            
277             sub _CheckIfSourceFileExists
278             {
279             my ( $self, $dir, $fileName ) = @_;
280             my $filePath = $dir . "/" . $fileName . ".c";
281             my $result = 0;
282            
283             $self->WriteLog( "_CheckIfSourceFileExists - Checking For \"$fileName.c\" Source File" );
284            
285             # Check if the file/directory exists
286             $result = 1 if ( -e "$filePath" );
287             $self->WriteLog( "_CheckIfSourceFileExists - Warning: File Does Not Exist" ) if $result == 0;
288             return 0 if $result == 0;
289            
290             # Check file type
291             my $fileType = $self->GetFileType( $filePath );
292            
293             $result = 1 if $fileType eq "text/cpp";
294            
295             $self->WriteLog( "_CheckIfSourceFileExists - File Exists" ) if $result == 1;
296            
297             return $result;
298             }
299            
300             sub _CompileSourceFile
301             {
302             my ( $self, $dir, $fileName ) = @_;
303             my $executablePath = $dir . "/" . $fileName;
304            
305             # Check if OS is Windows and adjust accordingly
306             $executablePath .= ".exe" if ( $self->GetOSType eq "MSWin32" );
307            
308             $self->WriteLog( "_CompileSourceFile - Compiling Source File \"$fileName.c\"" );
309            
310             my $sourceName = "/" . $fileName . ".c";
311             $dir .= $sourceName;
312            
313             my $result = 0;
314            
315             # Execute External System Command To Compile "word2vec.c" Source File
316             # Execute command without capturing program output
317             system( "gcc \"$dir\" -o \"$executablePath\" -lm -pthread -O3 -march=native -funroll-loops -Wno-unused-result -Wno-int-to-pointer-cast" ) if $self->GetIgnoreCompileErrors() == 1;
318             system( "gcc \"$dir\" -o \"$executablePath\" -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result" ) if $self->GetIgnoreCompileErrors() == 0;
319             $result = 1 if ( $self->GetOSType() ne "MSWin32" && -e "$executablePath" && $self->GetFileType( $executablePath ) eq "application/x-executable-file" );
320             $result = 1 if ( $self->GetOSType() eq "MSWin32" && -e "$executablePath" && $self->GetFileType( $executablePath ) eq "application/x-ms-dos-executable" );
321            
322             $self->WriteLog( "_CompileSourceFile - Compile Failed" ) if $result == 0;
323             $self->WriteLog( "_CompileSourceFile - Compiled Successfully") if $result == 1;
324            
325             return $result;
326             }
327            
328             sub GetFileType
329             {
330             my ( $self, $filePath ) = @_;
331             my $ft = File::Type->new();
332             my $fileType = $ft->checktype_filename( "$filePath" );
333             undef( $ft );
334            
335             return $fileType;
336             }
337            
338             sub GetOSType
339             {
340             my ( $self ) = @_;
341             return $^O;
342             }
343            
344             sub _ModifyWord2VecSourceForWindows
345             {
346             my ( $self ) = @_;
347            
348             my $result = 1;
349             my $tempStr = "";
350             my $modifiedCode = "#define posix_memalign(p, a, s) (((*(p)) = _aligned_malloc((s), (a))), *(p) ?0 :errno)\n";
351             my $workingDir = $self->GetWord2VecDir();
352            
353             # Open "word2vec.c" and add $modifiedCode to list of #define statements
354             open( my $fileHandle, "<:", "$workingDir/word2vec.c" ) or $result = 0;
355            
356             $self->WriteLog( "_ModifyWord2VecSourceForWindows - Error Opening \"word2vec.c\"" ) if $result == 0;
357             exit if $result == 0;
358            
359             while( my $line = <$fileHandle> )
360             {
361             $tempStr .= "$line";
362             $tempStr .= $modifiedCode if ( index( $line, "#define MAX_CODE_LENGTH " ) != -1 );
363             }
364            
365             close( $fileHandle );
366            
367             # Write overwrite old file with modified file
368             open( $fileHandle, ">:", "$workingDir/word2vec.c" ) or die $self->WriteLog( "_ModifyWord2VecSourceForWindows - Error creating or writing file: \"word2vec.c\"" );
369             print $fileHandle $tempStr;
370             close( $fileHandle );
371            
372             $tempStr = "";
373            
374             return $result;
375             }
376            
377             sub _RemoveWord2VecSourceModification
378             {
379             my ( $self ) = @_;
380            
381             my $result = 1;
382             my $tempStr = "";
383             my $modifiedCode = "#define posix_memalign(p, a, s) (((*(p)) = _aligned_malloc((s), (a))), *(p) ?0 :errno)\n";
384             my $workingDir = $self->GetWord2VecDir();
385            
386             # Open "word2vec.c" and remove $modifiedCode to list of #define statements
387             open( my $fileHandle, "<:", "$workingDir/word2vec.c" ) or $result = 0;
388            
389             $self->WriteLog( "_RemoveWord2VecSourceModification - Error Opening \"word2vec.c\"" ) if $result == 0;
390             exit if $result == 0;
391            
392             while( my $line = <$fileHandle> )
393             {
394             $tempStr .= "$line" if $line ne $modifiedCode;
395             }
396            
397             close( $fileHandle );
398            
399             # Write overwrite modified file with original file
400             open( $fileHandle, ">:", "$workingDir/word2vec.c" ) or die $self->WriteLog( "_RemoveWord2VecSourceModification - Error creating or writing file: \"word2vec.c\"" );
401             print $fileHandle $tempStr;
402             close( $fileHandle );
403            
404             $tempStr = "";
405            
406             return $result;
407             }
408            
409            
410             ######################################################################################
411             # Interface Driver Module Functions
412             ######################################################################################
413            
414             sub CLComputeCosineSimilarity
415             {
416             my ( $self, $vectorBinaryFile, $wordA, $wordB ) = @_;
417            
418             # Check(s)
419             $self->WriteLog( "CLComputeCosineSimilarity - Vector Data File Not Specified" ) if !defined( $vectorBinaryFile );
420             print( "Error: Vector Data File Does Not Exist\n" ) if !( -e "$vectorBinaryFile" ) && $self->GetDebugLog() == 0;
421             $self->WriteLog( "CLComputeCosineSimilarity - Vector Data File: \"$vectorBinaryFile\" Does Not Exist" ) if !( -e "$vectorBinaryFile" );
422             $self->WriteLog( "CLComputeCosineSimilarity - Two Words Required To Compute Cosine Similarity" ) if !defined( $wordA ) || !defined( $wordB );
423             return -1 if !defined( $vectorBinaryFile ) || !( -e "$vectorBinaryFile" ) || !defined( $wordA ) || !defined( $wordB );
424            
425             $self->WriteLog( "CLComputeCosineSimilarity - Preparing To Compute Cosine Similarity Of Word Vectors: \"$wordA\" and \"$wordB\"" );
426            
427             # Word2Vec Module Object
428             my $word2vec = $self->GetWord2VecHandler();
429            
430             # Load vector data file (Binary/Text Data)
431             my $dataLoaded = $word2vec->ReadTrainedVectorDataFromFile( $vectorBinaryFile );
432            
433             $self->WriteLog( "CLComputeCosineSimilarity - Unable To Load Vector Data From File: \"$vectorBinaryFile\"" ) if $dataLoaded == -1;
434             return -1 if $dataLoaded == -1;
435            
436             my $value = $word2vec->ComputeCosineSimilarity( $wordA, $wordB );
437            
438             $self->WriteLog( "CLComputeCosineSimilarity - Computed Cosine Similarity: $value" ) if defined( $value );
439             $self->WriteLog( "CLComputeCosineSimilarity - Error Computing Cosine Similarity" ) if !defined( $value );
440            
441             # Clear Vector Data From Memory
442             $word2vec->ClearVocabularyHash();
443            
444             return $value;
445             }
446            
447             sub CLComputeMultiWordCosineSimilarity
448             {
449             my ( $self, $vectorBinaryFile, $wordA, $wordB ) = @_;
450            
451             # Check(s)
452             $self->WriteLog( "CLComputeMultiWordCosineSimilarity - Vector Data File Not Specified" ) if !defined( $vectorBinaryFile );
453             print( "Error: Vector Data File Does Not Exist\n" ) if !( -e "$vectorBinaryFile" ) && $self->GetDebugLog() == 0;
454             $self->WriteLog( "CLComputeMultiWordCosineSimilarity - Vector Data File: \"$vectorBinaryFile\" Does Not Exist" ) if !( -e "$vectorBinaryFile" );
455             $self->WriteLog( "CLComputeMultiWordCosineSimilarity - Two Words Required To Compute Cosine Similarity" ) if !defined( $wordA ) || !defined( $wordB );
456             return -1 if !defined( $vectorBinaryFile ) || !( -e "$vectorBinaryFile" ) || !defined( $wordA ) || !defined( $wordB );
457            
458             # Replace ':' With Space
459             $wordA =~ s/:/ /g;
460             $wordB =~ s/:/ /g;
461            
462             $self->WriteLog( "CLComputeMultiWordCosineSimilarity - Preparing To Compute Cosine Similarity Of Word Vectors: \"$wordA\" and \"$wordB\"" );
463            
464             # Word2Vec Module Object
465             my $word2vec = $self->GetWord2VecHandler();
466            
467             # Load vector data file (Binary/Text Data)
468             my $dataLoaded = $word2vec->ReadTrainedVectorDataFromFile( $vectorBinaryFile );
469            
470             $self->WriteLog( "CLComputeMultiWordCosineSimilarity - Unable To Load Vector Data From File: \"$vectorBinaryFile\"" ) if $dataLoaded == -1;
471             return -1 if $dataLoaded == -1;
472            
473             my $value = $word2vec->ComputeMultiWordCosineSimilarity( $wordA, $wordB );
474            
475             $self->WriteLog( "CLComputeMultiWordCosineSimilarity - Computed Multi-Word Cosine Similarity: $value" ) if defined( $value );
476             $self->WriteLog( "CLComputeMultiWordCosineSimilarity - Error Computing Cosine Similarity" ) if !defined( $value );
477            
478             # Clear Vector Data From Memory
479             $word2vec->ClearVocabularyHash();
480            
481             return $value;
482             }
483            
484             sub CLComputeAvgOfWordsCosineSimilarity
485             {
486             my ( $self, $vectorBinaryFile, $wordA, $wordB ) = @_;
487            
488             # Check(s)
489             $self->WriteLog( "CLComputeAvgOfWordsCosineSimilarity - Vector Data File Not Specified" ) if !defined( $vectorBinaryFile );
490             print( "Error: Vector Data File Does Not Exist\n" ) if !( -e "$vectorBinaryFile" ) && $self->GetDebugLog() == 0;
491             $self->WriteLog( "CLComputeAvgOfWordsCosineSimilarity - Vector Data File: \"$vectorBinaryFile\" Does Not Exist" ) if !( -e "$vectorBinaryFile" );
492             $self->WriteLog( "CLComputeAvgOfWordsCosineSimilarity - Two Words Required To Compute Cosine Similarity" ) if !defined( $wordA ) || !defined( $wordB );
493             return -1 if !defined( $vectorBinaryFile ) || !( -e "$vectorBinaryFile" ) || !defined( $wordA ) || !defined( $wordB );
494            
495             # Replace ':' With Space
496             $wordA =~ s/:/ /g;
497             $wordB =~ s/:/ /g;
498            
499             $self->WriteLog( "CLComputeAvgOfWordsCosineSimilarity - Preparing To Compute Cosine Similarity Of Word Vectors: \"$wordA\" and \"$wordB\"" );
500            
501             # Word2Vec Module Object
502             my $word2vec = $self->GetWord2VecHandler();
503            
504             # Load vector data file (Binary/Text Data)
505             my $dataLoaded = $word2vec->ReadTrainedVectorDataFromFile( $vectorBinaryFile );
506            
507             $self->WriteLog( "CLComputeAvgOfWordsCosineSimilarity - Unable To Load Vector Data From File: \"$vectorBinaryFile\"" ) if $dataLoaded == -1;
508             return -1 if $dataLoaded == -1;
509            
510             my $value = $word2vec->ComputeAvgOfWordsCosineSimilarity( $wordA, $wordB ) if ( defined( $wordA ) && defined( $wordB ) );
511            
512             $self->WriteLog( "CLComputeAvgOfWordsCosineSimilarity - Computed Average Cosine Similarity: $value" ) if defined( $value );
513             $self->WriteLog( "CLComputeAvgOfWordsCosineSimilarity - Error Computing Cosine Similarity" ) if !defined( $value );
514            
515             # Clear Vector Data From Memory
516             $word2vec->ClearVocabularyHash();
517            
518             return $value;
519             }
520            
521             sub CLMultiWordCosSimWithUserInput
522             {
523             my ( $self, $vectorBinaryFile ) = @_;
524            
525             # Check(s)
526             return -1 if !defined( $vectorBinaryFile );
527            
528             my $word2vec = $self->GetWord2VecHandler();
529             $word2vec->ReadTrainedVectorDataFromFile( $vectorBinaryFile );
530            
531             print "Error Loading \"$vectorBinaryFile\"\n" if $word2vec->IsVectorDataInMemory() == 0;
532             $self->WriteLog( "CLMultiWordCosSimWithUserInput - Error Loading \"$vectorBinaryFile\"" ) if $word2vec->IsVectorDataInMemory() == 0;
533             return -1 if $word2vec->IsVectorDataInMemory() == 0;
534            
535             $word2vec->MultiWordCosSimWithUserInput();
536            
537             # Clear Vector Data From Memory
538             $word2vec->ClearVocabularyHash();
539            
540             return 0;
541             }
542            
543             sub CLAddTwoWordVectors
544             {
545             my ( $self, $vectorDataFilePath, $wordA, $wordB ) = @_;
546            
547             # Check(s)
548             $self->WriteLog( "CLAddTwoWordVectors - Error: Word Vector A Not Defined" ) if !defined( $wordA );
549             return undef if !defined( $wordA );
550            
551             $self->WriteLog( "CLAddTwoWordVectors - Error: Word Vector B Not Defined" ) if !defined( $wordB );
552             return undef if !defined( $wordB );
553            
554             $self->WriteLog( "CLAddTwoWordVectors - Preparing To Add Two Word Vectors: \"$wordA\" and \"$wordB\"" );
555            
556             $self->GetWord2VecHandler()->ReadTrainedVectorDataFromFile( $vectorDataFilePath );
557             $wordA = $self->GetWord2VecHandler()->GetWordVector( $wordA );
558             $wordB = $self->GetWord2VecHandler()->GetWordVector( $wordB );
559            
560             $self->WriteLog( "CLAddTwoWordVectors - Error: Locating Word In Dictionary" ) if !defined( $wordA );
561             $self->WriteLog( "CLAddTwoWordVectors - Error: Locating Word In Dictionary" ) if !defined( $wordB );
562             return undef if ( !defined( $wordA ) || !defined( $wordB ) );
563            
564             # Clear Vector Data From Memory
565             $self->GetWord2VecHandler()->ClearVocabularyHash();
566            
567             # Removing Words From Vector Data Array
568             my @wordAry = split( ' ', $wordA, 2 );
569             my $firstWord = shift( @wordAry );
570             $wordA = $wordAry[0];
571            
572             @wordAry = split( ' ', $wordB, 2 );
573             my $secondWord = shift( @wordAry );
574             $wordB = $wordAry[0];
575            
576             undef( @wordAry );
577            
578             $self->WriteLog( "CLAddTwoWordVectors - Adding Two Word Vectors: \n\n$firstWord: $wordA\n\n$secondWord: $wordB\n" ) if ( defined( $wordA ) && defined( $wordB ) );
579            
580             return $self->GetWord2VecHandler()->AddTwoWordVectors( $wordA, $wordB ) if ( defined( $wordA ) && defined( $wordB ) );
581             return undef;
582             }
583            
584             sub CLSubtractTwoWordVectors
585             {
586             my ( $self, $vectorDataFilePath, $wordA, $wordB ) = @_;
587            
588             # Check(s)
589             $self->WriteLog( "CLSubtractTwoWordVectors - Error: Word Vector A Not Defined" ) if !defined( $wordA );
590             return undef if !defined( $wordA );
591            
592             $self->WriteLog( "CLSubtractTwoWordVectors - Error: Word Vector B Not Defined" ) if !defined( $wordB );
593             return undef if !defined( $wordB );
594            
595             $self->WriteLog( "CLSubtractTwoWordVectors - Preparing To Subtract Two Word Vectors: \"$wordA\" and \"$wordB\"" );
596            
597             $self->GetWord2VecHandler()->ReadTrainedVectorDataFromFile( $vectorDataFilePath );
598             $wordA = $self->GetWord2VecHandler()->GetWordVector( $wordA );
599             $wordB = $self->GetWord2VecHandler()->GetWordVector( $wordB );
600            
601             $self->WriteLog( "CLSubtractTwoWordVectors - Error: Locating Word In Dictionary" ) if !defined( $wordA );
602             $self->WriteLog( "CLSubtractTwoWordVectors - Error: Locating Word In Dictionary" ) if !defined( $wordB );
603             return undef if ( !defined( $wordA ) || !defined( $wordB ) );
604            
605             # Clear Vector Data From Memory
606             $self->GetWord2VecHandler()->ClearVocabularyHash();
607            
608             # Removing Words From Vector Data Array
609             my @wordAry = split( ' ', $wordA, 2 );
610             my $firstWord = shift( @wordAry );
611             $wordA = $wordAry[0];
612            
613             @wordAry = split( ' ', $wordB, 2 );
614             my $secondWord = shift( @wordAry );
615             $wordB = $wordAry[0];
616            
617             undef( @wordAry );
618            
619             $self->WriteLog( "CLSubtractTwoWordVectors - Subtracting Two Word Vectors: \n\n$firstWord: $wordA\n\n$secondWord: $wordB\n" ) if ( defined( $wordA ) && defined( $wordB ) );
620            
621             return $self->GetWord2VecHandler()->SubtractTwoWordVectors( $wordA, $wordB ) if ( defined( $wordA ) && defined( $wordB ) );
622             return undef;
623             }
624            
625             sub CLStartWord2VecTraining
626             {
627             my ( $self, $optionsHashRef ) = @_;
628            
629             my %options = %{ $optionsHashRef };
630            
631             # Word2Vec Module Object
632             my $word2vec = $self->GetWord2VecHandler();
633            
634             # Parse and Set Word2Vec Options
635             for my $option ( keys %options )
636             {
637             $word2vec->SetTrainFilePath( $options{$option} ) if $option eq "-trainfile";
638             $word2vec->SetOutputFilePath( $options{$option} ) if $option eq "-outputfile";
639             $word2vec->SetWordVecSize( $options{$option} ) if $option eq "-size";
640             $word2vec->SetWindowSize( $options{$option} ) if $option eq "-window";
641             $word2vec->SetSample( $options{$option} ) if $option eq "-sample";
642             $word2vec->SetNegative( $options{$option} ) if $option eq "-negative";
643             $word2vec->SetHSoftMax( $options{$option} ) if $option eq "-hs";
644             $word2vec->SetBinaryOutput( $options{$option} ) if $option eq "-binary";
645             $word2vec->SetNumOfThreads( $options{$option} ) if $option eq "-threads";
646             $word2vec->SetNumOfIterations( $options{$option} ) if $option eq "-iter";
647             $word2vec->SetUseCBOW( $options{$option} ) if $option eq "-cbow";
648             $word2vec->SetClasses( $options{$option} ) if $option eq "-classes";
649             $word2vec->SetReadVocabFilePath( $options{$option} ) if $option eq "-read-vocab";
650             $word2vec->SetSaveVocabFilePath( $options{$option} ) if $option eq "-save-vocab";
651             $word2vec->SetDebugTraining( $options{$option} ) if $option eq "-debug";
652             $word2vec->SetOverwriteOldFile( $options{$option} ) if $option eq "-overwrite";
653             }
654            
655             # Check(s)
656             my $trainFile = $word2vec->GetTrainFilePath();
657             my $outputFile = $word2vec->GetOutputFilePath();
658             $self->WriteLog( "CLStartWord2VecTraining - Error: No Training File Specified" ) if !defined( $trainFile ) || $trainFile eq "";
659             return -1 if !defined( $trainFile ) || $trainFile eq "";
660             $self->WriteLog( "CLStartWord2VecTraining - Error: Training File: \"$trainFile\" Does Not Exist" ) if !( -e "$trainFile" );
661             return -1 if !( -e "$trainFile" );
662             $self->WriteLog( "CLStartWord2VecTraining - Error: Training File Exists But Has No Data / File Size = 0 bytes" ) if ( -z "$trainFile" );
663             return -1 if ( -z "$trainFile" );
664             $self->WriteLog( "CLStartWord2VecTraining - Error: No Output File/Directory Specified" ) if !defined( $outputFile ) || $outputFile eq "";
665             return -1 if !defined( $outputFile ) || $outputFile eq "";
666             $self->WriteLog( "CLStartWord2VecTraining - Warning: No Word2Vec Options Specified - Using Default Options" ) if ( keys %options ) == 2;
667            
668             $self->WriteLog( "CLStartWord2VecTraining - Starting Word2Vec Training" );
669             my $result = $word2vec->ExecuteTraining();
670             $self->WriteLog( "CLStartWord2VecTraining - Word2Vec Training Successful" ) if $result == 0;
671             $self->WriteLog( "CLStartWord2VecTraining - Word2Vec Training Not Successful" ) if $result != 0;
672             $self->WriteLog( "CLStartWord2VecTraining - See \"Word2vecLog.txt\" For Details" ) if $result != 0;
673             return $result;
674             }
675            
676             sub CLStartWord2PhraseTraining
677             {
678             my ( $self, $optionsHashRef ) = @_;
679            
680             my %options = %{ $optionsHashRef };
681            
682             # Word2Vec Module Object
683             my $word2phrase = $self->GetWord2PhraseHandler();
684            
685             # Parse and Set Word2Vec Options
686             for my $option ( keys %options )
687             {
688             $word2phrase->SetTrainFilePath( $options{$option} ) if $option eq "-trainfile";
689             $word2phrase->SetOutputFilePath( $options{$option} ) if $option eq "-outputfile";
690             $word2phrase->SetMinCount( $options{$option} ) if $option eq "-min-count";
691             $word2phrase->SetThreshold( $options{$option} ) if $option eq "-threshold";
692             $word2phrase->SetW2PDebug( $options{$option} ) if $option eq "-debug";
693             $word2phrase->SetOverwriteOldFile( $options{$option} ) if $option eq "-overwrite";
694             }
695            
696             # Check(s)
697             my $trainFile = $word2phrase->GetTrainFilePath();
698             my $outputFile = $word2phrase->GetOutputFilePath();
699             $self->WriteLog( "CLStartWord2PhraseTraining - Error: No Training File Specified" ) if !defined( $trainFile ) || $trainFile eq "";
700             return -1 if !defined( $trainFile ) || $trainFile eq "";
701             $self->WriteLog( "CLStartWord2PhraseTraining - Error: Training File: \"$trainFile\" Does Not Exist" ) if !( -e "$trainFile" );
702             return -1 if !( -e "$trainFile" );
703             $self->WriteLog( "CLStartWord2PhraseTraining - Error: Training File Exists But Has No Data / File Size = 0 bytes" ) if ( -z "$trainFile" );
704             return -1 if ( -z "$trainFile" );
705             $self->WriteLog( "CLStartWord2PhraseTraining - Error: No Output File/Directory Specified" ) if !defined( $outputFile ) || $outputFile eq "";
706             return -1 if !defined( $outputFile ) || $outputFile eq "";
707             $self->WriteLog( "CLStartWord2PhraseTraining - Warning: No Word2Phrase Options Specified - Using Default Options" ) if ( keys %options ) == 2;
708            
709             $self->WriteLog( "CLStartWord2PhraseTraining - Starting Word2Phrase Training" );
710             my $result = $word2phrase->ExecuteTraining();
711             $self->WriteLog( "CLStartWord2PhraseTraining - Word2Phrase Training Successful" ) if $result == 0;
712             $self->WriteLog( "CLStartWord2PhraseTraining - Word2Phrase Training Not Successful" ) if $result != 0;
713             $self->WriteLog( "CLStartWord2PhraseTraining - See \"Word2phraseLog.txt\" For Details" ) if $result != 0;
714             return $result;
715             }
716            
717             sub CLCompileTextCorpus
718             {
719             my ( $self, $optionsHashRef ) = @_;
720            
721             my %options = %{ $optionsHashRef };
722            
723             # XMLToW2V Option Variables
724             my $workingDir = undef;
725             my $saveDir = undef;
726             my $startDate = undef;
727             my $endDate = undef;
728             my $storeTitle = undef;
729             my $storeAbstract = undef;
730             my $quickParse = undef;
731             my $compoundWordFile = undef;
732             my $storeAsSentencePerLine = undef;
733             my $numOfThreads = undef;
734             my $overwriteExistingFile = undef;
735            
736             # Parse and Set XMLToW2V Options
737             for my $option ( keys %options )
738             {
739             $workingDir = $options{$option} if $option eq "-workdir";
740             $saveDir = $options{$option} if $option eq "-savedir";
741             $startDate = $options{$option} if $option eq "-startdate";
742             $endDate = $options{$option} if $option eq "-enddate";
743             $storeTitle = $options{$option} if $option eq "-title";
744             $storeAbstract = $options{$option} if $option eq "-abstract";
745             $quickParse = $options{$option} if $option eq "-qparse";
746             $compoundWordFile = $options{$option} if $option eq "-compwordfile";
747             $storeAsSentencePerLine = $options{$option} if $option eq "-sentenceperline";
748             $numOfThreads = $options{$option} if $option eq "-threads";
749             $overwriteExistingFile = $options{$option} if $option eq "-overwrite";
750             }
751            
752             undef( $optionsHashRef );
753             undef( %options );
754            
755            
756             # Check(s)
757             $self->WriteLog( "CLCompileTextCorpus - Warning: Working Directory Not Defined - Using Default Directory" ) if !defined( $workingDir );
758             $workingDir =$self->GetWorkingDirectory() if !defined( $workingDir );
759             print( "Warning: Save Directory Not Defined - Using Working Directory / Saving To \"text.txt\"\n" ) if !defined( $saveDir ) && $self->GetDebugLog() == 0;
760             $self->WriteLog( "CLCompileTextCorpus - Warning: Save Directory Not Defined - Using Working Directory / Saving To \"text.txt\"" ) if !defined( $saveDir );
761             $saveDir = "text.txt" if !defined( $saveDir );
762             $self->WriteLog( "CLCompileTextCorpus - Warning: Start Date Not Defined - Using 00/00/0000 By Default" ) if !defined( $startDate );
763             $startDate = "00/00/0000" if !defined( $startDate );
764             $self->WriteLog( "CLCompileTextCorpus - Warning: End Date Not Defined - Using 99/99/9999 By Default" ) if !defined( $endDate );
765             $endDate = "99/99/9999" if !defined( $endDate );
766             $self->WriteLog( "CLCompileTextCorpus - Warning: Store Title Not Defined - Storing All Article Title By Default" ) if !defined( $storeTitle );
767             $storeTitle = 1 if !defined( $storeTitle );
768             $self->WriteLog( "CLCompileTextCorpus - Warning: Store Abstract Not Defined - Storing All Article Abstracts By Default" ) if !defined( $storeAbstract );
769             $storeAbstract = 1 if !defined( $storeAbstract );
770             $self->WriteLog( "CLCompileTextCorpus - Warning: Quick Parse Option Not Defined - Enabling Quick Parse By Default" ) if !defined( $quickParse );
771             $quickParse = 1 if !defined( $quickParse );
772             $self->WriteLog( "CLCompileTextCorpus - Warning: Compound Word File Not Defined - Compoundify Option Disabled" ) if !defined( $compoundWordFile );
773             $self->XTWSetCompoundifyText( 0 ) if !defined( $compoundWordFile );
774             $self->WriteLog( "CLCompileTextCorpus - Warning: Store As Sentence Per Line Not Defined - Store As Sentence Per Line Disabled" ) if !defined( $storeAsSentencePerLine );
775             $storeAsSentencePerLine = 0 if !defined( $storeAsSentencePerLine );
776             print "Warning: Number Of Working Threads Not Defined - Using 1 Thread Per CPU Core\n" if !defined( $numOfThreads ) && $self->GetDebugLog() == 0;
777             $self->WriteLog( "CLCompileTextCorpus - Warning: Number Of Working Threads Not Defined - Using 1 Thread Per CPU Core By Default / " . Sys::CpuAffinity::getNumCpus() . " Threads" ) if !defined( $numOfThreads );
778             $numOfThreads = Sys::CpuAffinity::getNumCpus() if !defined( $numOfThreads );
779             print( "Error: File \"$saveDir\" Exists And Overwrite Existing File Option Not Defined\n" ) if !defined( $overwriteExistingFile ) && ( -e "$saveDir" ) && $self->GetDebugLog() == 0;
780             $self->WriteLog( "CLCompileTextCorpus - Error: File \"$saveDir\" Exists And Overwrite Existing File Option Not Defined" ) if !defined( $overwriteExistingFile ) && ( -e "$saveDir" );
781             return -1 if !defined( $overwriteExistingFile ) && ( -e "$saveDir" );
782             $self->WriteLog( "CLCompileTextCorpus - Warning: Overwrite Existing File Option Not Defined - Default = 1 / YES" ) if !defined( $overwriteExistingFile ) && !( -e "$saveDir" );
783             $overwriteExistingFile = 1 if !defined( $overwriteExistingFile ) && !( -e "$saveDir" );
784             print( "Warning: Existing Save File Found / Appending To File\n" ) if defined( $overwriteExistingFile ) && $overwriteExistingFile == 0 && ( -e "$saveDir" ) && $self->GetDebugLog() == 0;
785             $self->WriteLog( "CLCompileTextCorpus - Warning: Existing Save File Found / Appending To File" ) if defined( $overwriteExistingFile ) && $overwriteExistingFile == 0 && ( -e "$saveDir" );
786             print( "Warning: Existing Save File Found / Overwriting File\n" ) if defined( $overwriteExistingFile ) && $overwriteExistingFile == 1 && ( -e "$saveDir" ) && $self->GetDebugLog() == 0;
787             $self->WriteLog( "CLCompileTextCorpus - Warning: Existing Save File Found / Overwriting File" ) if defined( $overwriteExistingFile ) && $overwriteExistingFile == 1 && ( -e "$saveDir" );
788            
789             $self->WriteLog( "CLCompileTextCorpus - Warning: Working Directory Is Blank - Using \".\" Directory" ) if ( $workingDir eq "" );
790             $workingDir = "." if ( $workingDir eq "" );
791             $self->WriteLog( "CLCompileTextCorpus - Error: Working Directory: \"$workingDir\" Does Not Exist" ) if !( -e "$workingDir" );
792             return -1 if !( -e "$workingDir" );
793            
794             $self->WriteLog( "CLCompileTextCorpus - Error: Compound Word File \"$compoundWordFile\" Does Not Exist - Disabling Compoundify Option" ) if $self->XTWGetCompoundifyText() == 1 && !( -e "$compoundWordFile" );
795             $self->XTWSetCompoundifyText( 0 ) if $self->XTWGetCompoundifyText() == 1 && !( -e "$compoundWordFile" );
796            
797             $self->WriteLog( "CLCompileTextCorpus - Printing Current Xmltow2v Settings" );
798             print "Printing Current Xmltow2v Setting(s)\n" if $self->GetDebugLog() == 0;
799            
800             # Print Status Messages In The Event Debug Logging Is Disabled
801             print "Working Directory: $workingDir\n" if $self->GetDebugLog() == 0;
802             print "Save Directory: $saveDir\n" if $self->GetDebugLog() == 0;
803             print "Start Date: $startDate\n" if $self->GetDebugLog() == 0;
804             print "End Date: $endDate\n" if $self->GetDebugLog() == 0;
805             print "Store Title: $storeTitle - ( 0=Disabled / 1=Enabled )\n" if $self->GetDebugLog() == 0;
806             print "Store Abstract: $storeAbstract - ( 0=Disabled / 1=Enabled )\n" if $self->GetDebugLog() == 0;
807             print "Quick Parse: $quickParse - ( 0=Disabled / 1=Enabled )\n" if $self->GetDebugLog() == 0;
808             print "Store As Sentence Per Line $storeAsSentencePerLine - ( 0=Disabled / 1=Enabled )\n" if $self->GetDebugLog() == 0 && $self->XTWGetStoreAsSentencePerLine() == 1;
809             print "Warning: No Compound Word File Specified - Compoundify Option Disabled\n" if $self->GetDebugLog() == 0 && $self->XTWGetCompoundifyText() == 0;
810             print "Compound Word File Specified - Compoundify Option Enabled\n" if $self->GetDebugLog() == 0 && $self->XTWGetCompoundifyText() == 1;
811             print "Compound Word File: $compoundWordFile\n" if $self->GetDebugLog() == 0 && $self->XTWGetCompoundifyText() == 1;
812            
813             $self->WriteLog( "CLCompileTextCorpus - Working Directory: \"$workingDir\"" );
814             $self->WriteLog( "CLCompileTextCorpus - Save Directory: \"$saveDir\"" );
815             $self->WriteLog( "CLCompileTextCorpus - Start Date: $startDate" );
816             $self->WriteLog( "CLCompileTextCorpus - End Date: $endDate" );
817             $self->WriteLog( "CLCompileTextCorpus - Store Title: $storeTitle" );
818             $self->WriteLog( "CLCompileTextCorpus - Store Abstract: $storeAbstract" );
819             $self->WriteLog( "CLCompileTextCorpus - Quick Parse: $quickParse" );
820             $self->WriteLog( "CLCompileTextCorpus - Number Of Working Threads: $numOfThreads" );
821             $self->WriteLog( "CLCompileTextCorpus - Overwrite Previous File: $overwriteExistingFile" );
822             $self->WriteLog( "CLCompileTextCorpus - Compoundifying Using File: \"$compoundWordFile\"" ) if $self->XTWGetCompoundifyText() == 1;
823             $self->WriteLog( "CLCompileTextCorpus - Store As Sentence Per Line: $storeAsSentencePerLine" );
824            
825             my @beginDateAry = split( '/', $startDate );
826             my @endDateAry = split( '/', $endDate );
827            
828             $self->WriteLog( "CLCompileTextCorpus - Error: Start Date Range In Wrong Format - XX/XX/XXXX" ) if @beginDateAry < 3;
829             return -1 if @beginDateAry < 3;
830            
831             $self->WriteLog( "CLCompileTextCorpus - Error: End Date Range In Wrong Format - XX/XX/XXXX" ) if @endDateAry < 3;
832             return -1 if @endDateAry < 3;
833            
834             undef( @beginDateAry );
835             undef( @endDateAry );
836            
837             my $result = 0;
838            
839             my $xmlconv = $self->GetXMLToW2VHandler();
840             $xmlconv->SetStoreTitle( $storeTitle );
841             $xmlconv->SetStoreAbstract( $storeAbstract );
842             $xmlconv->SetWorkingDir( "$workingDir" );
843             $xmlconv->SetSavePath( "$saveDir" );
844             $xmlconv->SetBeginDate( $startDate );
845             $xmlconv->SetEndDate( $endDate );
846             $xmlconv->SetQuickParse( $quickParse );
847             $xmlconv->SetNumOfThreads( $numOfThreads );
848             $xmlconv->SetOverwriteExistingFile( $overwriteExistingFile );
849             $xmlconv->SetStoreAsSentencePerLine( $storeAsSentencePerLine );
850            
851             if( defined( $compoundWordFile ) && ( -e "$compoundWordFile" ) )
852             {
853             $result = $xmlconv->ReadCompoundWordDataFromFile( "$compoundWordFile", 1 );
854            
855             # Check
856             $self->WriteLog( "CLCompileTextCorpus - Error Loading Compound Word File" ) if ( $result == -1 );
857             return -1 if ( $result == -1 );
858            
859             $result = $xmlconv->CreateCompoundWordBST() if ( $result == 0 );
860            
861             # Check
862             $self->WriteLog( "CLCompileTextCorpus - Error Creating Compound Word Binary Search Tree" ) if ( $result == -1 );
863             return -1 if ( $result == -1 );
864             }
865            
866             $result = $xmlconv->ConvertMedlineXMLToW2V( "$workingDir" );
867            
868             # Clean up
869             $xmlconv->ClearCompoundWordAry();
870             $xmlconv->ClearCompoundWordBST();
871            
872             return $result;
873             }
874            
875             sub CLConvertWord2VecVectorFileToText
876             {
877             my ( $self, $filePath, $savePath ) = @_;
878            
879             # Check(s)
880             $self->WriteLog( "CLConvertWord2VecVectorFileToText - Specified File: \"$filePath\" Not Defined" ) if !defined( $filePath );
881             return -1 if !defined( $filePath );
882            
883             $self->WriteLog( "CLConvertWord2VecVectorFileToText - Specified File: \"$filePath\" Does Not Exist" ) if !( -e $filePath );
884             return -1 if !( -e $filePath );
885            
886             $self->WriteLog( "CLConvertWord2VecVectorFileToText - No Save File Name Specified - Saving To \"convertedvectors.bin\"" ) if !defined( $savePath );
887             $savePath = "convertedvectors.bin" if !defined( $savePath );
888            
889             my $w2v = $self->GetWord2VecHandler();
890             my $previousSetting = $w2v->GetSparseVectorMode();
891             my $result = $w2v->ReadTrainedVectorDataFromFile( $filePath );
892            
893             # Check
894             $self->WriteLog( "CLConvertWord2VecVectorFileToText - Error Reading Vector Data File" ) if ( $result == -1 );
895             return -1 if ( $result == -1 );
896            
897             $result = $w2v->SaveTrainedVectorDataToFile( $savePath );
898            
899             # Check
900             $self->WriteLog( "CLConvertWord2VecVectorFileToText - Error Saving Vector Data To File" ) if ( $result == -1 );
901            
902             # Clean up
903             $w2v->ClearVocabularyHash();
904             $w2v->SetSparseVectorMode( $previousSetting );
905            
906             $self->WriteLog( "CLConvertWord2VecVectorFileToText - Finished Conversion" );
907             return $result;
908             }
909            
910             sub CLConvertWord2VecVectorFileToBinary
911             {
912             my ( $self, $filePath, $savePath ) = @_;
913            
914             # Check(s)
915             $self->WriteLog( "CLConvertWord2VecVectorFileToBinary - Specified File: \"$filePath\" Not Defined" ) if !defined( $filePath );
916             return -1 if !defined( $filePath );
917            
918             $self->WriteLog( "CLConvertWord2VecVectorFileToBinary - Specified File: \"$filePath\" Does Not Exist" ) if !( -e $filePath );
919             return -1 if !( -e $filePath );
920            
921             $self->WriteLog( "CLConvertWord2VecVectorFileToBinary - No Save File Name Specified - Saving To \"convertedvectors.bin\"" ) if !defined( $savePath );
922             $savePath = "convertedvectors.bin" if !defined( $savePath );
923            
924             my $w2v = $self->GetWord2VecHandler();
925             my $previousSetting = $w2v->GetSparseVectorMode();
926             my $result = $w2v->ReadTrainedVectorDataFromFile( $filePath );
927            
928             # Check
929             $self->WriteLog( "CLConvertWord2VecVectorFileToBinary - Error Reading Vector Data File" ) if ( $result == -1 );
930             return -1 if ( $result == -1 );
931            
932             $result = $w2v->SaveTrainedVectorDataToFile( $savePath, 1 );
933            
934             $self->WriteLog( "CLConvertWord2VecVectorFileToBinary - Error Saving Vector Data To File" ) if ( $result == -1 );
935            
936             # Clean up
937             $w2v->ClearVocabularyHash();
938             $w2v->SetSparseVectorMode( $previousSetting );
939            
940             $self->WriteLog( "CLConvertWord2VecVectorFileToBinary - Finished Conversion" );
941             return $result;
942             }
943            
944             sub CLConvertWord2VecVectorFileToSparse
945             {
946             my ( $self, $filePath, $savePath ) = @_;
947            
948             # Check(s)
949             $self->WriteLog( "CLConvertVectorsToSparseVectors - Specified File: \"$filePath\" Not Defined" ) if !defined( $filePath );
950             return -1 if !defined( $filePath );
951            
952             $self->WriteLog( "CLConvertVectorsToSparseVectors - Specified File: \"$filePath\" Does Not Exist" ) if !( -e $filePath );
953             return -1 if !( -e $filePath );
954            
955             $self->WriteLog( "CLConvertVectorsToSparseVectors - No Save File Name Specified - Saving To \"convertedvectors.bin\"" ) if !defined( $savePath );
956             $savePath = "convertedvectors.bin" if !defined( $savePath );
957            
958             my $w2v = $self->GetWord2VecHandler();
959             my $previousSetting = $w2v->GetSparseVectorMode();
960             my $result = $w2v->ReadTrainedVectorDataFromFile( $filePath );
961            
962             # Check
963             $self->WriteLog( "CLConvertVectorsToSparseVectors - Error Reading Vector Data File" ) if ( $result == -1 );
964             return -1 if ( $result == -1 );
965            
966             $result = $w2v->SaveTrainedVectorDataToFile( $savePath, 2 );
967            
968             $self->WriteLog( "CLConvertVectorsToSparseVectors - Error Saving Vector Data To File" ) if ( $result == -1 );
969            
970             # Clean up
971             $w2v->ClearVocabularyHash();
972             $w2v->SetSparseVectorMode( $previousSetting );
973            
974             $self->WriteLog( "CLConvertVectorsToSparseVectors - Finished Conversion" );
975             return $result;
976             }
977            
978             sub CLCompoundifyTextInFile
979             {
980             my ( $self, $filePath, $savePath, $compoundWordFile ) = @_;
981            
982             # Check(s)
983             $self->WriteLog( "CLCompoundifyTextInFile - No File Specified" ) if !defined( $filePath );
984             return -1 if !defined( $filePath );
985            
986             $self->WriteLog( "CLCompoundifyTextInFile - Save File Name Not Specified - Saving File To: \"comptext.txt\"" ) if !defined( $savePath );
987             $savePath = "comptext.txt" if !defined( $savePath );
988            
989             $self->WriteLog( "CLCompoundifyTextInFile - No Compound Word File Specified" ) if !defined( $compoundWordFile );
990             return -1 if !defined( $compoundWordFile );
991            
992             $self->WriteLog( "CLCompoundifyTextInFile - Specified File: \"$filePath\" Does Not Exist" ) if !( -e $filePath );
993             return -1 if !( -e $filePath );
994            
995             $self->WriteLog( "CLCompoundifyTextInFile - Specified File: \"$compoundWordFile\" Does Not Exist" ) if !( -e $compoundWordFile );
996             return -1 if !( -e $compoundWordFile );
997            
998            
999             $self->WriteLog( "CLCompoundifyTextInFile - Compoundifying File: \"$compoundWordFile\"" );
1000            
1001             my $text = "";
1002            
1003             open( my $fileHandle, "<:encoding(utf8)", "$filePath" ) or die "CLCompoundifyTextInFile - Error: Cannot Open Specified File";
1004            
1005             while( my $line = <$fileHandle> )
1006             {
1007             chomp( $line );
1008             $text .= $line;
1009             }
1010            
1011             close( $fileHandle );
1012            
1013             my $xmltow2v = $self->GetXMLToW2VHandler();
1014            
1015             $self->WriteLog( "CLCompoundifyTextInFile - Cleaning Text Data" );
1016             $text = $xmltow2v->RemoveSpecialCharactersFromString( $text );
1017            
1018             my $result = $xmltow2v->ReadCompoundWordDataFromFile( $compoundWordFile, 1 );
1019            
1020             $self->WriteLog( "CLCompoundifyTextInFile - An Error Has Occured While Loading Compound Word File" ) if $result == -1;
1021             return -1 if $result == -1;
1022            
1023             $xmltow2v->CreateCompoundWordBST();
1024            
1025             $self->WriteLog( "CLCompoundifyTextInFile - An Error Has Occured While Creating Compound Word BST" ) if $result == -1;
1026             return -1 if $result == -1;
1027            
1028             $text = $xmltow2v->CompoundifyString( $text );
1029            
1030             open( $fileHandle, ">:encoding(utf8)", "$savePath" ) or die "CLCompoundifyTextInFile - Error: Cannot Save File - \"$savePath\"";
1031             print $fileHandle "$text\n";
1032             close( $fileHandle );
1033             undef( $fileHandle );
1034            
1035             # Clean up
1036             $text = "";
1037             $xmltow2v->ClearCompoundWordAry();
1038             $xmltow2v->ClearCompoundWordBST();
1039            
1040             $self->WriteLog( "CLCompoundifyTextInFile - Finished Compoundify" );
1041            
1042             return 0;
1043             }
1044            
1045             sub CLSortVectorFile
1046             {
1047             my ( $self, $optionsHashRef ) = @_;
1048            
1049             my %options = %{ $optionsHashRef };
1050            
1051             # Check(s)
1052             $self->WriteLog( "CLSortVectorFile - Error: No Arguments Specified" ) if keys( %options ) == 0;
1053             return -1 if keys( %options ) == 0;
1054            
1055             my $vectorDataFilePath = $options{ "-filepath" };
1056             my $overwriteOldFile = $options{ "-overwrite" };
1057             undef( %options );
1058            
1059             # Check(s)
1060             $self->WriteLog( "CLSortVectorFile - Error: Vector Data File Path Not Specified" ) if !defined( $vectorDataFilePath );
1061             return -1 if !defined( $vectorDataFilePath );
1062            
1063             $self->WriteLog( "CLSortVectorFile - Error: Specified Vector Data File Not Found" ) if !( -e $vectorDataFilePath );
1064             return -1 if !( -e $vectorDataFilePath );
1065            
1066             # Check To See If File Is Already Sorted
1067             my $fileAlreadySorted = 0;
1068            
1069             open( my $fileHandle, "<:", $vectorDataFilePath );
1070            
1071             # Read Vector File Header
1072             my $headerLine = <$fileHandle>;
1073            
1074             # Check(s)
1075             $self->WriteLog( "CLSortVectorFile - Error: Header Not Defined" ) if !defined( $headerLine );
1076             return -1 if !defined( $headerLine );
1077            
1078             # Fetch Number Of Words And Vector Length From Header
1079             my @headerAry = split( ' ', $headerLine );
1080            
1081             # Check(s)
1082             $self->WriteLog( "CLSortVectorFile - Error: Invalid Header" ) if ( @headerAry < 2 );
1083             return -1 if ( @headerAry < 2 );
1084             my $numberOfWords = $headerAry[0];
1085             my $vectorLength = $headerAry[1];
1086            
1087             # Check Header String For Sorted Signature
1088             $fileAlreadySorted = 1 if ( defined( $headerLine ) && index( $headerLine, "#\$\@RTED#" ) != -1 );
1089             undef( $headerLine );
1090             undef( $fileHandle );
1091            
1092             $self->WriteLog( "CLSortVectorFile - Checking To See If File Has Been Previously Sorted?" );
1093             print( "Warning: Vector Data File Is Already Sorted\n" ) if ( $self->GetDebugLog() == 0 && $fileAlreadySorted == 1 );
1094             $self->WriteLog( "CLSortVectorFile - Warning: Vector Data File Is Already Sorted / Header Signed As Sorted" ) if ( $fileAlreadySorted == 1 );
1095             return 1 if ( $fileAlreadySorted == 1 );
1096            
1097             $self->WriteLog( "CLSortVectorFile - File Has Not Been Sorted" );
1098             $overwriteOldFile = 0 if !defined( $overwriteOldFile );
1099             $self->WriteLog( "CLSortVectorFile - Warning: Overwrite Old File Option Enabled" ) if ( $overwriteOldFile == 1 );
1100             $self->WriteLog( "CLSortVectorFile - Saving As New File: sortedvectors.bin" ) if ( $overwriteOldFile == 0 );
1101            
1102             $self->WriteLog( "CLSortVectorFile - Beginning Data Format Detection And Sort Routine" );
1103            
1104             # Check Vector File For Vector Data Format
1105             my $saveFormat = $self->W2VCheckWord2VecDataFileType( $vectorDataFilePath );
1106             $self->WriteLog( "CLSortVectorFile - Vector File Data Format Detected As: $saveFormat" );
1107            
1108             # Read Vector Data File In Memory
1109             $self->WriteLog( "CLSortVectorFile - Reading Vector Data File" );
1110             my $result = $self->W2VReadTrainedVectorDataFromFile( $vectorDataFilePath, 0 ) if defined( $saveFormat );
1111            
1112             # Modify Array Header To Include Sorted Signature
1113             $self->WriteLog( "CLSortVectorFile - Signing Header" );
1114             my $vocabularyHashRef = $self->W2VGetVocabularyHash();
1115             $vocabularyHashRef->{ $numberOfWords } = "$vectorLength #\$\@RTED#" if defined( $vocabularyHashRef->{ $numberOfWords } );
1116            
1117             # Save Array In Word2vec Object
1118             $self->W2VSetNumberOfWords( $numberOfWords );
1119             $self->W2VSetVectorLength( $vectorLength );
1120            
1121             # Set File Name If Overwrite Option Is Disabled
1122             $vectorDataFilePath = "sortedvectors.bin" if $overwriteOldFile == 0;
1123            
1124             # Set Save Format
1125             if( defined( $saveFormat ) )
1126             {
1127             $saveFormat = 0 if ( $saveFormat eq "text" );
1128             $saveFormat = 1 if ( $saveFormat eq "binary" );
1129             $saveFormat = 2 if ( $saveFormat eq "sparsetext" );
1130             }
1131            
1132             # Save Sorted Vector Data To File
1133             $self->WriteLog( "CLSortVectorFile - Saving New File As: \"$vectorDataFilePath\"" );
1134             $result = $self->W2VSaveTrainedVectorDataToFile( $vectorDataFilePath, $saveFormat );
1135            
1136             # Clean Up
1137             $self->W2VClearVocabularyHash();
1138            
1139             $self->WriteLog( "CLSortVectorFile - Complete" );
1140            
1141             return $result;
1142             }
1143            
1144             sub CLFindSimilarTerms
1145             {
1146             my ( $self, $term, $numberOfSimilarTerms ) = @_;
1147            
1148             # Check(s)
1149             $self->WriteLog( "CLFindSimilarTerms - Error: Term Not Defined" ) if !defined( $term );
1150             $self->WriteLog( "CLFindSImilarTerms - Error: Term Is Empty String" ) if defined( $term ) && $term eq "";
1151             return undef if !defined( $term ) || ( defined( $term ) && $term eq "" );
1152            
1153             $self->WriteLog( "CLFindSimilarTerms - Warning: Number Of Similar Terms Not Defined / Using Default = 10" ) if !defined( $numberOfSimilarTerms );
1154             $numberOfSimilarTerms = 10 if !defined( $numberOfSimilarTerms );
1155            
1156             $self->WriteLog( "CLFindSimilarTerms - Error: Vocabulary Is Empty / No Vector Data In Memory" ) if $self->W2VIsVectorDataInMemory() == 0;
1157             return undef if $self->W2VIsVectorDataInMemory() == 0;
1158            
1159             # Get Nearest Similar Neighbors
1160             my %similarWords = ();
1161             my @returnWords = ();
1162             my $vocabularyHash = $self->W2VGetVocabularyHash();
1163            
1164             # Check To See If The "$term" Parameters Exists Within The Vocabulary
1165             my $result = $vocabularyHash->{ $term };
1166            
1167             $self->WriteLog( "CLFindSimilarTerms - Error: \"$term\" Does Not Exist Within The Vocabulary" ) if !defined( $result );
1168             return undef if !defined( $result );
1169            
1170             for my $word ( keys %{ $vocabularyHash } )
1171             {
1172             # Skip Number Of Words and Vector Length Information
1173             next if ( $word eq $self->W2VGetNumberOfWords() );
1174            
1175             $result = $self->W2VComputeCosineSimilarity( $term, $word );
1176             $similarWords{ $result } = $word if defined( $result );
1177             }
1178            
1179             my @sortedValues = sort {$b <=> $a} keys( %similarWords );
1180            
1181             for( 0..$numberOfSimilarTerms )
1182             {
1183             push( @returnWords, $similarWords{ $sortedValues[ $_] } . " : " . $sortedValues[ $_ ] );
1184             }
1185            
1186             return \@returnWords;
1187             }
1188            
1189             sub CleanWord2VecDirectory
1190             {
1191             my ( $self ) = @_;
1192            
1193             # Check(s)
1194             my $directory = $self->GetWord2VecDir();
1195             $self->WriteLog( "CleanWord2VecDirectory - Word2Vec Directory: \"$directory\" Does Not Exist" ) if !( -e $directory );
1196             return -1 if !( -e $directory );
1197            
1198             $self->WriteLog( "CleanWord2VecDirectory - Cleaning Up Word2Vec Directory Files" );
1199            
1200             my $word2vec = $directory . "/word2vec";
1201             my $word2phrase = $directory . "/word2phrase";
1202             my $wordAnalogy = $directory . "/word-analogy";
1203             my $distance = $directory . "/distance";
1204             my $computeAccuracy = $directory . "/compute-accuracy";
1205            
1206             $self->WriteLog( "CleanWord2VecDirectory - Removing C Object Files" );
1207            
1208             unlink( "$word2vec.o" ) if ( -e "$word2vec.o" );
1209             unlink( "$word2phrase.o" ) if ( -e "$word2phrase.o" );
1210             unlink( "$wordAnalogy.o" ) if ( -e "$wordAnalogy.o" );
1211             unlink( "$distance.o" ) if ( -e "$distance.o" );
1212             unlink( "$computeAccuracy.o" ) if ( -e "$computeAccuracy.o" );
1213            
1214             $self->WriteLog( "CleanWord2VecDirectory - Removed C Object Files" );
1215             $self->WriteLog( "CleanWord2VecDirectory - Removing Word2Vec Executable Files" );
1216            
1217             if( $self->GetOSType() eq "MSWin32" )
1218             {
1219             unlink( "$word2vec.exe" ) if ( -e "$word2vec.exe" );
1220             unlink( "$word2phrase.exe" ) if ( -e "$word2phrase.exe" );
1221             unlink( "$wordAnalogy.exe" ) if ( -e "$wordAnalogy.exe" );
1222             unlink( "$distance.exe" ) if ( -e "$distance.exe" );
1223             unlink( "$computeAccuracy.exe" ) if ( -e "$computeAccuracy.exe" );
1224             }
1225             else
1226             {
1227             unlink( "$word2vec" ) if ( -e "$word2vec" );
1228             unlink( "$word2phrase" ) if ( -e "$word2phrase" );
1229             unlink( "$wordAnalogy" ) if ( -e "$wordAnalogy" );
1230             unlink( "$distance" ) if ( -e "$distance" );
1231             unlink( "$computeAccuracy" ) if ( -e "$computeAccuracy" );
1232             }
1233            
1234             print( "Cleaned Word2Vec Directory\n" ) if ( $self->GetDebugLog() == 0 );
1235            
1236             $self->WriteLog( "CleanWord2VecDirectory - Removed Word2Vec Executable Files" );
1237             return 0;
1238             }
1239            
1240             ######################################################################################
1241             # Similarity Functions
1242             ######################################################################################
1243            
1244             sub CLSimilarityAvg
1245             {
1246             my ( $self, $similarityFilePath ) = @_;
1247            
1248             my @dataAry = ();
1249            
1250             $self->WriteLog( "CLSimilarityAvg - Error: Specified File: \"$similarityFilePath\" Does Not Exist" ) if !( -e "$similarityFilePath" );
1251             return -1 if !( -e "$similarityFilePath" );
1252            
1253             $self->WriteLog( "CLSimilarityAvg - Error: No Vector Data In Memory" ) if $self->W2VIsVectorDataInMemory() == 0;
1254             return -1 if ( $self->W2VIsVectorDataInMemory() == 0 );
1255            
1256             $self->WriteLog( "CLSimilarityAvg - Reading Similarity File Data: $similarityFilePath" );
1257            
1258             open( my $fileHandle, "<:encoding(UTF-8)", "$similarityFilePath" );
1259            
1260             while( my $line = <$fileHandle> )
1261             {
1262             chomp( $line );
1263             push( @dataAry, $line );
1264             }
1265            
1266             close( $fileHandle );
1267             undef( $fileHandle );
1268            
1269             $self->WriteLog( "CLSimilarityAvg - Finished Reading Similarity File Data" );
1270             $self->WriteLog( "CLSimilarityAvg - Computing File Data Cosine Similarity" );
1271             print( "Generating Average Cosine Similarity File\n" ) if ( $self->GetDebugLog() == 0 );
1272            
1273             my @resultAry = ();
1274            
1275             for( my $i = 0; $i < @dataAry; $i++ )
1276             {
1277             my @searchWords = split( '<>', $dataAry[$i] );
1278            
1279             my $searchWord1 = $searchWords[@searchWords-2];
1280             my $searchWord2 = $searchWords[@searchWords-1];
1281            
1282             # Check(s)
1283             $self->WriteLog( "CLSimilarityAvg - Warning: Comparison Contains Less Than Two Words - Line Number: ". $i+1 . ", Line String: \"" . $dataAry[$i] . "\"" ) if @searchWords < 2;
1284             $self->WriteLog( "CLSimilarityAvg - Warning: Line Contains Empty Search Term - Line Number: ". $i+1 . ", Line String: \"" . $dataAry[$i] . "\"" )
1285             if ( defined( $searchWord1 ) && $searchWord1 eq "" ) || ( defined( $searchWord2 ) && $searchWord2 eq "" );
1286             $searchWord1 = undef if @searchWords - 2 < 0;
1287             $searchWord2 = undef if @searchWords - 1 < 0;
1288             $searchWord1 = undef if defined( $searchWord1 ) && length( $searchWord1 ) == 0;
1289             $searchWord2 = undef if defined( $searchWord2 ) && length( $searchWord2 ) == 0;
1290             my $result = -1 if !defined( $searchWord1 ) or !defined( $searchWord2 );
1291            
1292             $result = $self->W2VComputeAvgOfWordsCosineSimilarity( lc( $searchWord1 ), lc( $searchWord2 ) ) if !defined( $result );
1293             $result = -1 if !defined( $result );
1294             push( @resultAry, $result );
1295            
1296             $result = undef;
1297            
1298             if( @searchWords == 3 )
1299             {
1300             my $start = @searchWords - 2;
1301             my $end = @searchWords - 1;
1302             @searchWords = @searchWords[$start..$end];
1303             $dataAry[$i] = join( '<>', @searchWords );
1304             }
1305             }
1306            
1307             $self->WriteLog( "CLSimilarityAvg - Finished Computing Results" );
1308             $self->WriteLog( "CLSimilarityAvg - Saving Results In Similarity Format" );
1309            
1310             $similarityFilePath =~ s/\.sim//g;
1311             my @tempAry = split( '/', $similarityFilePath );
1312             $similarityFilePath = Cwd::getcwd() . "/" . $tempAry[-1] . ".avg_results";
1313             undef( @tempAry );
1314            
1315             open( $fileHandle, ">:encoding(utf8)", $similarityFilePath ) or $self->( "CLSimilarityAvg - Error: Creating/Saving Results File" );
1316            
1317             for( my $i = 0; $i < @dataAry; $i++ )
1318             {
1319             print $fileHandle $resultAry[$i] . "<>" . $dataAry[$i] . "\n";
1320             }
1321            
1322             close( $fileHandle );
1323             undef( $fileHandle );
1324            
1325             undef( @dataAry );
1326             undef( @resultAry );
1327            
1328             $self->WriteLog( "CLSimilarityAvg - Finished" );
1329            
1330             return 0;
1331             }
1332            
1333             sub CLSimilarityComp
1334             {
1335             my ( $self, $similarityFilePath, $vectorBinFilePath ) = @_;
1336            
1337             my @dataAry = ();
1338            
1339             $self->WriteLog( "CLSimilarityComp - Error: Specified File: \"$similarityFilePath\" Does Not Exist" ) if !( -e "$similarityFilePath" );
1340             return -1 if !( -e "$similarityFilePath" );
1341            
1342             $self->WriteLog( "CLSimilarityComp - Error: No Vector Data In Memory" ) if $self->W2VIsVectorDataInMemory() == 0;
1343             return -1 if ( $self->W2VIsVectorDataInMemory() == 0 );
1344            
1345             $self->WriteLog( "CLSimilarityComp - Reading Similarity File Data: $similarityFilePath" );
1346            
1347             open( my $fileHandle, "<:encoding(UTF-8)", "$similarityFilePath" );
1348            
1349             while( my $line = <$fileHandle> )
1350             {
1351             chomp( $line );
1352             push( @dataAry, $line );
1353             }
1354            
1355             close( $fileHandle );
1356             undef( $fileHandle );
1357            
1358             $self->WriteLog( "CLSimilarityComp - Finished Reading Similarity File Data" );
1359             $self->WriteLog( "CLSimilarityComp - Computing File Data Cosine Similarity" );
1360             print( "Generating Compound Cosine Similarity File\n" ) if ( $self->GetDebugLog() == 0 );
1361            
1362             my @resultAry = ();
1363            
1364             for( my $i = 0; $i < @dataAry; $i++ )
1365             {
1366             my @searchWords = split( '<>', $dataAry[$i] );
1367            
1368             my $searchWord1 = $searchWords[@searchWords-2];
1369             my $searchWord2 = $searchWords[@searchWords-1];
1370            
1371             $searchWord1 =~ s/ +/_/g if defined( $searchWord1 );
1372             $searchWord2 =~ s/ +/_/g if defined( $searchWord2 );
1373            
1374             # Check(s)
1375             $self->WriteLog( "CLSimilarityComp - Warning: Comparison Contains Less Than Two Words - Line Number: ". $i+1 . ", Line String: \"" . $dataAry[$i] . "\"" ) if @searchWords < 2;
1376             $self->WriteLog( "CLSimilarityComp - Warning: Line Contains Empty Search Term - Line Number: ". $i+1 . ", Line String: \"" . $dataAry[$i] . "\"" )
1377             if ( defined( $searchWord1 ) && $searchWord1 eq "" ) || ( defined( $searchWord2 ) && $searchWord2 eq "" );
1378             $searchWord1 = undef if @searchWords - 2 < 0;
1379             $searchWord2 = undef if @searchWords - 1 < 0;
1380             $searchWord1 = undef if defined( $searchWord1 ) && length( $searchWord1 ) == 0;
1381             $searchWord2 = undef if defined( $searchWord2 ) && length( $searchWord2 ) == 0;
1382             my $result = -1 if !defined( $searchWord1 ) or !defined( $searchWord2 );
1383            
1384             $result = $self->W2VComputeCosineSimilarity( lc( $searchWord1 ), lc( $searchWord2 ) ) if !defined( $result );
1385             $result = -1 if !defined( $result );
1386             push( @resultAry, $result );
1387            
1388             $result = undef;
1389            
1390             if( @searchWords == 3 )
1391             {
1392             my $start = @searchWords - 2;
1393             my $end = @searchWords - 1;
1394             @searchWords = @searchWords[$start..$end];
1395             $dataAry[$i] = join( '<>', @searchWords );
1396             }
1397             }
1398            
1399             $self->WriteLog( "CLSimilarityComp - Finished Computing Results" );
1400             $self->WriteLog( "CLSimilarityComp - Saving Results In Similarity Format" );
1401            
1402             $similarityFilePath =~ s/\.sim//g;
1403             my @tempAry = split( '/', $similarityFilePath );
1404             $similarityFilePath = Cwd::getcwd() . "/" . $tempAry[-1] . ".comp_results";
1405             undef( @tempAry );
1406            
1407             open( $fileHandle, ">:encoding(utf8)", $similarityFilePath ) or $self->( "CLSimilarityComp - Error: Creating/Saving Results File" );
1408            
1409             for( my $i = 0; $i < @dataAry; $i++ )
1410             {
1411             print $fileHandle $resultAry[$i] . "<>" . $dataAry[$i] . "\n";
1412             }
1413            
1414             close( $fileHandle );
1415             undef( $fileHandle );
1416            
1417             undef( @dataAry );
1418             undef( @resultAry );
1419            
1420             $self->WriteLog( "CLSimilarityComp - Finished" );
1421            
1422             return 0;
1423             }
1424            
1425             sub CLSimilaritySum
1426             {
1427             my ( $self, $similarityFilePath, $vectorBinFilePath ) = @_;
1428            
1429             my @dataAry = ();
1430            
1431             $self->WriteLog( "CLSimilaritySum - Error: Specified File: \"$similarityFilePath\" Does Not Exist" ) if !( -e "$similarityFilePath" );
1432             return -1 if !( -e "$similarityFilePath" );
1433            
1434             $self->WriteLog( "CLSimilaritySum - Error: No Vector Data In Memory" ) if $self->W2VIsVectorDataInMemory() == 0;
1435             return -1 if ( $self->W2VIsVectorDataInMemory() == 0 );
1436            
1437             $self->WriteLog( "CLSimilaritySum - Reading Similarity File Data: $similarityFilePath" );
1438            
1439             open( my $fileHandle, "<:encoding(UTF-8)", "$similarityFilePath" );
1440            
1441             while( my $line = <$fileHandle> )
1442             {
1443             chomp( $line );
1444             push( @dataAry, $line );
1445             }
1446            
1447             close( $fileHandle );
1448             undef( $fileHandle );
1449            
1450             $self->WriteLog( "CLSimilaritySum - Finished Reading Similarity File Data" );
1451             $self->WriteLog( "CLSimilaritySum - Computing File Data Cosine Similarity" );
1452             print( "Generating Summed Cosine Similarity File\n" ) if ( $self->GetDebugLog() == 0 );
1453            
1454             my @resultAry = ();
1455            
1456             for( my $i = 0; $i < @dataAry; $i++ )
1457             {
1458             my @searchWords = split( '<>', $dataAry[$i] );
1459            
1460             my $searchWord1 = $searchWords[@searchWords-2];
1461             my $searchWord2 = $searchWords[@searchWords-1];
1462            
1463             # Check(s)
1464             $self->WriteLog( "CLSimilaritySum - Warning: Comparison Contains Less Than Two Words - Line Number: ". $i+1 . ", Line String: \"" . $dataAry[$i] . "\"" ) if @searchWords < 2;
1465             $self->WriteLog( "CLSimilaritySum - Warning: Line Contains Empty Search Term - Line Number: ". $i+1 . ", Line String: \"" . $dataAry[$i] . "\"" )
1466             if ( defined( $searchWord1 ) && $searchWord1 eq "" ) || ( defined( $searchWord2 ) && $searchWord2 eq "" );
1467             $searchWord1 = undef if @searchWords - 2 < 0;
1468             $searchWord2 = undef if @searchWords - 1 < 0;
1469             $searchWord1 = undef if defined( $searchWord1 ) && length( $searchWord1 ) == 0;
1470             $searchWord2 = undef if defined( $searchWord2 ) && length( $searchWord2 ) == 0;
1471             my $result = -1 if !defined( $searchWord1 ) or !defined( $searchWord2 );
1472            
1473             $result = $self->W2VComputeMultiWordCosineSimilarity( lc( $searchWord1 ), lc( $searchWord2 ), 1 ) if !defined( $result );
1474             $result = -1 if !defined( $result );
1475             push( @resultAry, $result );
1476            
1477             $result = undef;
1478            
1479             if( @searchWords == 3 )
1480             {
1481             my $start = @searchWords - 2;
1482             my $end = @searchWords - 1;
1483             @searchWords = @searchWords[$start..$end];
1484             $dataAry[$i] = join( '<>', @searchWords );
1485             }
1486             }
1487            
1488             $self->WriteLog( "CLSimilaritySum - Finished Computing Results" );
1489             $self->WriteLog( "CLSimilaritySum - Saving Results In Similarity Format" );
1490            
1491             $similarityFilePath =~ s/\.sim//g;
1492             my @tempAry = split( '/', $similarityFilePath );
1493             $similarityFilePath = Cwd::getcwd() . "/" . $tempAry[-1] . ".sum_results";
1494             undef( @tempAry );
1495            
1496             open( $fileHandle, ">:encoding(utf8)", $similarityFilePath ) or $self->( "CLSimilaritySum - Error: Creating/Saving Results File" );
1497            
1498             for( my $i = 0; $i < @dataAry; $i++ )
1499             {
1500             print $fileHandle $resultAry[$i] . "<>" . $dataAry[$i] . "\n";
1501             }
1502            
1503             close( $fileHandle );
1504             undef( $fileHandle );
1505            
1506             undef( @dataAry );
1507             undef( @resultAry );
1508            
1509             $self->WriteLog( "CLSimilaritySum - Finished" );
1510            
1511             return 0;
1512             }
1513            
1514             ######################################################################################
1515             # Word Sense Disambiguation Functions
1516             ######################################################################################
1517            
1518             sub CLWordSenseDisambiguation
1519             {
1520             my ( $self, $instancesFilePath, $sensesFilePath, $vectorBinFilePath, $stopListFilePath, $listOfFilesPath ) = @_;
1521            
1522             my $result = 0;
1523             my %listOfFiles;
1524            
1525             # Check(s)
1526             $listOfFilesPath = "" if !defined( $listOfFilesPath );
1527            
1528             if( $listOfFilesPath eq "" )
1529             {
1530             # Parse Directory Of Files
1531             if( defined( $instancesFilePath ) && $self->XTWIsFileOrDirectory( $instancesFilePath ) eq "dir" )
1532             {
1533             my $hashRef = $self->_WSDParseDirectory( $instancesFilePath );
1534             %listOfFiles = %{ $hashRef } if defined( $hashRef );
1535            
1536             # Enable List Parsing
1537             $listOfFilesPath = "directory";
1538             }
1539             # Parse Pair Of Files
1540             else
1541             {
1542             $self->WriteLog( "CLWordSenseDisambiguation - Error: \"Instances\" File Not Specified" ) if !defined( $instancesFilePath ) || length( $instancesFilePath ) == 0;
1543             $self->WriteLog( "CLWordSenseDisambiguation - Error: \"Senses\" File Not Specified" ) if !defined( $sensesFilePath ) || length( $sensesFilePath ) == 0;
1544             $self->WriteLog( "CLWordSenseDisambiguation - Error: \"vector binary\" File Not Specified" ) if !defined ( $vectorBinFilePath ) || length( $vectorBinFilePath ) == 0;
1545             $self->WriteLog( "CLWordSenseDisambiguation - Attn: \"stoplist\" File Not Specified" ) if !defined ( $stopListFilePath ) || length( $stopListFilePath ) == 0;
1546             $self->WriteLog( "CLWordSenseDisambiguation - \"$instancesFilePath\" Does Not Exist" ) if length( $instancesFilePath ) != 0 && !( -e $instancesFilePath );
1547             $self->WriteLog( "CLWordSenseDisambiguation - \"$sensesFilePath\" Does Not Exist" ) if length( $sensesFilePath ) != 0 && !( -e $sensesFilePath );
1548             $self->WriteLog( "CLWordSenseDisambiguation - \"$vectorBinFilePath\" Does Not Exist" ) if length( $vectorBinFilePath ) != 0 && !( -e $vectorBinFilePath );
1549             $self->WriteLog( "CLWordSenseDisambiguation - \"$stopListFilePath\" Does Not Exist" ) if length( $stopListFilePath ) != 0 && !( -e $stopListFilePath );
1550            
1551             print( "CLWordSenseDisambiguation - Error: No Specified Files To Parse\n" ) if ( $self->GetDebugLog() == 0 )
1552             && ( !defined( $instancesFilePath ) || !defined( $sensesFilePath ) || !defined( $vectorBinFilePath ) );
1553            
1554             print( "CLWordSenseDisambiguation - Error: Specified File(s) Do Not Exist\n" ) if ( $self->GetDebugLog() == 0 )
1555             && ( !( -e $instancesFilePath ) || !( -e $sensesFilePath ) || !( -e $vectorBinFilePath ) );
1556            
1557             return -1 if ( !defined( $instancesFilePath ) || !defined( $sensesFilePath ) || !defined( $vectorBinFilePath ) );
1558             return -1 if ( !( -e $instancesFilePath ) || !( -e $sensesFilePath ) || !( -e $vectorBinFilePath ) );
1559             }
1560             }
1561             else
1562             {
1563             $self->WriteLog( "CLWordSenseDisambiguation - Parsing List Of Files Option Enabled" );
1564            
1565             my $hashRef = $self->_WSDReadList( $listOfFilesPath );
1566             %listOfFiles = %{ $hashRef } if defined( $hashRef );
1567             }
1568            
1569             # Continue if files are defined
1570             if( $listOfFilesPath eq "" )
1571             {
1572             $listOfFiles{ $instancesFilePath } = $sensesFilePath;
1573             $result = $self->_WSDParseList( \%listOfFiles, $vectorBinFilePath, $stopListFilePath );
1574             }
1575             elsif( $listOfFilesPath ne "" )
1576             {
1577             $vectorBinFilePath = $listOfFiles{ "-vectors" } if !defined( $vectorBinFilePath ) || length( $vectorBinFilePath ) == 0;
1578             $stopListFilePath = $listOfFiles{ "-stoplist" } if !defined( $stopListFilePath ) || length( $stopListFilePath ) == 0;
1579             chomp( $vectorBinFilePath ) if defined( $vectorBinFilePath );
1580             chomp( $stopListFilePath ) if defined( $stopListFilePath );
1581             delete( $listOfFiles{ "-vectors" } );
1582             delete( $listOfFiles{ "-stoplist" } );
1583             $result = $self->_WSDParseList( \%listOfFiles, $vectorBinFilePath, $stopListFilePath );
1584             $self->_WSDGenerateAccuracyReport( $self->GetWorkingDirectory() ) if $result != -1 && ( keys %listOfFiles ) > 1;
1585             }
1586            
1587             $self->WriteLog( "CLWordSenseDisambiguation - Finished" ) if ( $result == 0 );
1588             $self->WriteLog( "CLWordSenseDisambiguation - Script Finished With Errors" ) if ( $result != 0 && $self->GetWriteLog() == 0 );
1589             $self->WriteLog( "CLWordSenseDisambiguation - Script Finished With Errors, See Logs For Details" ) if ( $result != 0 && $self-GetWriteLog() == 1 );
1590            
1591             print( "Complete\n" ) if ( $self->GetDebugLog() == 0 && $result == 0 );
1592             print( "Error Processing File(s)\n" ) if ( $self->GetDebugLog() == 0 && $result != 0 );
1593            
1594             return $result;
1595             }
1596            
1597             sub _WSDAnalyzeSenseData
1598             {
1599             my ( $self ) = @_;
1600            
1601             my $senseStrLength = 0;
1602             my @instanceAry = $self->GetInstanceAry();
1603             my @senseAry = $self->GetSenseAry();
1604            
1605             # Check(s)
1606             $self->WriteLog( "_WSDAnalyzeSenseData - Senses Array Empty / Has WSD Sense File Been Loaded Into Memory?" ) if @senseAry == 0;
1607             return -1 if @senseAry == 0;
1608            
1609             # Find Length Of SenseID For Instances
1610             for( my $i = 0; $i < @instanceAry; $i++ )
1611             {
1612             $senseStrLength = length( $instanceAry[$i]->senseID ) if ( length( $instanceAry[$i]->senseID ) > $senseStrLength );
1613             }
1614            
1615             # Check If Each Expected SenseID Is The Same Length In Sense Objects, Else Expected SenseID Is Probably Supposed To Be The InstanceID
1616             # ie. Instance->SenseID = C10030234 and Sense->SenseID = M2. Replace Sense->SenseID with Sense->InstanceID
1617             for( my $i = 0; $i < @senseAry; $i++ )
1618             {
1619             my $sense = $senseAry[$i];
1620            
1621             my $instanceID = $sense->instanceID;
1622             my $answerID = $sense->answerInstanceID;
1623             my $senseID = $sense->senseID;
1624            
1625             # Adjust SenseID If InstanceID Not Equal To SenseID
1626             if( length( $senseID ) != $senseStrLength && $instanceID ne $senseID )
1627             {
1628             $self->WriteLog( "_WSDAnalyzeSenseData - Warning: SenseID Mis-Match - InstanceID: $instanceID Not Equal SenseID: $senseID" );
1629            
1630             $sense->senseID( $instanceID );
1631             $senseAry[$i] = $sense;
1632            
1633             $self->WriteLog( " Correcting Data - InstanceID: $instanceID ----> SenseID: $instanceID" );
1634             }
1635             }
1636             }
1637            
1638             sub _WSDReadList
1639             {
1640             my ( $self, $listOfFilesPath ) = @_;
1641            
1642             # Check(s)
1643             $self->WriteLog( "_WSDReadList - \"$listOfFilesPath\" Does Not Exist" ) if !( -e "$listOfFilesPath" );
1644             return undef if !( -e "$listOfFilesPath" );
1645            
1646             my %listOfFiles;
1647            
1648             open( my $fileHandle, "<:encoding(utf8)", "$listOfFilesPath" ) or die "Error: Unable To Open File: $listOfFilesPath";
1649            
1650             while( my $line = <$fileHandle> )
1651             {
1652             chomp( $line );
1653            
1654             # Skip Commented And Empty Lines
1655             if( $line eq "" || index( $line, "#" ) != -1 )
1656             {
1657             next;
1658             }
1659             else
1660             {
1661             my @tempAry = split( ' ', $line );
1662            
1663             # Check
1664             next if @tempAry < 2;
1665            
1666             $listOfFiles{ $tempAry[0] } = $tempAry[1];
1667             undef( @tempAry );
1668             }
1669             }
1670            
1671             close( $fileHandle );
1672            
1673             return \%listOfFiles;
1674             }
1675            
1676             sub _WSDParseDirectory
1677             {
1678             my ( $self, $directory ) = @_;
1679            
1680             # Check(s)
1681             $self->WriteLog( "_WSDParseDirectory - Directory Not Defined" ) if !defined( $directory );
1682             return undef if !defined( $directory );
1683            
1684             $self->WriteLog( "_WSDParseDirectory - Specified Directory Does Not Exist" ) if !( -e $directory );
1685             return undef if !( -e $directory );
1686            
1687             # Set Working Directory
1688             $self->SetWorkingDirectory( $directory );
1689            
1690             # Read File Name(s) From Specified Directory
1691             my $result = 0;
1692             my %listOfFiles;
1693             opendir( my $dirHandle, "$directory" ) or $result = -1;
1694             $self->WriteLog( "_WSDParseDirectory - Error: Can't open $directory: $!" ) if $result == -1;
1695             return -1 if $result == -1;
1696            
1697             for my $file ( readdir( $dirHandle ) )
1698             {
1699             # Only Include ".sval" Files ( Omit ".sval.results" Files )
1700             if ( index( $file, ".sval" ) != -1 && index( $file, ".sval.results" ) == -1 )
1701             {
1702             my @fileName = split( '.', $file );
1703            
1704             my $instanceFile = $file;
1705             my $senseFile = $file;
1706            
1707             $instanceFile =~ s/senses/instances/g;
1708             $senseFile =~ s/instances/senses/g;
1709            
1710             $listOfFiles{ $instanceFile } = $senseFile if ( !defined( $listOfFiles{ $instanceFile } ) && -f "$directory/$instanceFile" );
1711             }
1712             }
1713            
1714             closedir $dirHandle;
1715             undef $dirHandle;
1716            
1717             return \%listOfFiles;
1718             }
1719            
1720             sub _WSDParseList
1721             {
1722             my ( $self, $hashRef, $vectorBinFilePath, $stopListFilePath ) = @_;
1723            
1724             # Check(s)
1725             $self->WriteLog( "_WSDParseList - List Of Files Not Defined" ) if !defined( $hashRef );
1726             return undef if !defined( $hashRef );
1727            
1728             my %listOfFiles = %{ $hashRef };
1729            
1730             $self->WriteLog( "_WSDParseList - Error: No Files To Compare Listed" ) if ( keys %listOfFiles ) == 0;
1731             return -1 if ( keys %listOfFiles ) == 0;
1732            
1733             print( "Generating Stop List Regex\n" ) if ( $self->GetDebugLog() == 0 && defined( $stopListFilePath ) && length( $stopListFilePath ) == 0 );
1734            
1735             print( "Attn: Stop List Not Utilized\n" ) if !defined( $stopListFilePath ) || length( $stopListFilePath ) == 0;
1736             $self->WriteLog( "_WSDParseList - Attn: \"Stop List\" File Not Specified" ) if !defined( $stopListFilePath ) || length( $stopListFilePath ) == 0;
1737             print( "Warning: Stop List File Does Not Exist\n" ) if defined( $stopListFilePath ) && !( -e $stopListFilePath );
1738             $self->WriteLog( "Warning: Stop List File Does Not Exist" ) if defined( $stopListFilePath ) && !( -e $stopListFilePath );
1739            
1740             print( "Generating Stop List Regex\n" ) if defined( $stopListFilePath ) && ( -e $stopListFilePath );
1741             $self->WriteLog( "_WSDParseList - Generating Stop List Regex" ) if defined( $stopListFilePath ) && ( -e $stopListFilePath );
1742             my $stopListRegex = $self->_WSDStop( $stopListFilePath ) if defined( $stopListFilePath ) && ( -e $stopListFilePath );
1743            
1744             $self->WriteLog( "_WSDParseList - Generated Stop List Regex: $stopListRegex" ) if defined( $stopListRegex );
1745             $self->WriteLog( "_WSDParseList - Warning: Stop List Regex Generation Failed - Continuing Without Stop List Regex" ) if !defined( $stopListRegex );
1746            
1747             my $word2vec = $self->GetWord2VecHandler();
1748             my $readFile = 0;
1749            
1750             if( $word2vec->IsVectorDataInMemory() == 0 )
1751             {
1752             print( "Reading Vector File: $vectorBinFilePath\n" ) if ( $self->GetDebugLog() == 0 );
1753             $self->WriteLog( "_WSDParseList - Reading \"Vector Binary\" File: \"$vectorBinFilePath\"" );
1754             $readFile = $word2vec->ReadTrainedVectorDataFromFile( $vectorBinFilePath );
1755            
1756             print( "Unable To Read Specified Vector Binary File: \"$vectorBinFilePath\"\n" ) if ( $self->GetDebugLog() == 0 && $readFile == -1 );
1757             $self->WriteLog( "_WSDParseList - Unable To Read Specified Vector Binary File: \"$vectorBinFilePath\"" ) if $readFile == -1;
1758             return -1 if $readFile == -1;
1759             }
1760             elsif( $word2vec->IsVectorDataInMemory() == 1 && defined( $vectorBinFilePath ) )
1761             {
1762             print( "Warning: Clearing Previous Vector Data In Memory\n" ) if ( $self->GetDebugLog() == 0 );
1763             $self->WriteLog("Warning: Clearing Previous Vector Data In Memory" );
1764             $word2vec->ClearVocabularyHash();
1765            
1766             print( "Reading Vector File: $vectorBinFilePath\n" ) if ( $self->GetDebugLog() == 0 );
1767             $self->WriteLog( "_WSDParseList - Reading \"Vector Binary\" File: \"$vectorBinFilePath\"" );
1768             $readFile = $word2vec->ReadTrainedVectorDataFromFile( $vectorBinFilePath );
1769            
1770             print( "Unable To Read Specified Vector Binary File: \"$vectorBinFilePath\"\n" ) if ( $self->GetDebugLog() == 0 && $readFile == -1 );
1771             $self->WriteLog( "_WSDParseList - Unable To Read Specified Vector Binary File: \"$vectorBinFilePath\"" ) if $readFile == -1;
1772             return -1 if $readFile == -1;
1773             }
1774             else
1775             {
1776             print( "Warning: Vector Data Already Exists In Memory - Using Existing Data\n" ) if ( $self->GetDebugLog() == 0 );
1777             $self->WriteLog( "Warning: Vector Data Already Exists In Memory - Using Existing Data" );
1778             }
1779            
1780             print( "Parsing File(s)\n" ) if ( $self->GetDebugLog() == 0 );
1781             $self->WriteLog( "_WSDParseList - Parsing List Of Files" );
1782            
1783             for my $file ( keys %listOfFiles )
1784             {
1785             my $instancesFilePath = $self->GetWorkingDirectory() . "/$file";
1786             my $sensesFilePath = $self->GetWorkingDirectory() . "/" .$listOfFiles{ $file };
1787            
1788             # Check(s)
1789             print( "\"$instancesFilePath\" Cannot Be Found\n" ) if !( -e $instancesFilePath ) && $self->GetDebugLog() == 0;
1790             print( "\"$sensesFilePath\" Cannot Be Found\n" ) if !( -e $sensesFilePath ) && $self->GetDebugLog() == 0;
1791             $self->WriteLog( "_WSDParseList - Error: \"$instancesFilePath\" Cannot Be Found" ) if !( -e $instancesFilePath );
1792             $self->WriteLog( "_WSDParseList - Error: \"$sensesFilePath\" Cannot Be Found" ) if !( -e $sensesFilePath );
1793             $self->WriteLog( "_WSDParseList - Error: \"$instancesFilePath\" Contains No Data" ) if ( -z $instancesFilePath );
1794             $self->WriteLog( "_WSDParseList - Error: \"$sensesFilePath\" Contains No Data" ) if ( -z $sensesFilePath );
1795             next if !( -e $instancesFilePath ) || !( -e $sensesFilePath ) || ( -z $instancesFilePath ) || ( -z $sensesFilePath );
1796            
1797             # Parse "Instances" From File
1798             my $aryRef = $self->WSDParseFile( $instancesFilePath, $stopListRegex );
1799             $self->SetInstanceAry( $aryRef ) if defined( $aryRef );
1800             $self->SetInstanceCount( @{ $aryRef } );
1801             $self->WriteLog( "_WSDParseList - Parsed And Stored ". @{ $aryRef } . " Instances From File." );
1802            
1803             # Parse "Senses" From File
1804             $aryRef = $self->WSDParseFile( $sensesFilePath, $stopListRegex );
1805             $self->SetSenseAry( $aryRef ) if defined( $aryRef );
1806             $self->SetSenseCount( @{ $aryRef } );
1807             $self->WriteLog( "_WSDParseList - Parsed And Stored " . @{ $aryRef } . " Senses From File." );
1808            
1809             # Analyze Sense Array For SenseID Mis-Match
1810             $self->_WSDAnalyzeSenseData();
1811            
1812             # Calculate Cosine Similarity For All Data Entries
1813             my $success = $self->WSDCalculateCosineAvgSimilarity();
1814            
1815             $self->WriteLog( "_WSDParseList - Error Calculating Cosine Average Similarity / Skipping File" ) if ( $success == -1 );
1816             next if ( $success == -1 );
1817            
1818             # Save Results
1819             $self->WSDSaveResults( $instancesFilePath ) if ( $success == 0 );
1820             $self->WriteLog( "_WSDParseList - Results Saved To File \"$instancesFilePath.results\"" ) if ( $success == 0 );
1821            
1822             # Clear Old Data
1823             $instancesFilePath = "";
1824             $sensesFilePath = "";
1825             $self->SetInstanceCount( 0 );
1826             $self->SetSenseCount( 0 );
1827             $self->ClearInstanceAry();
1828             $self->ClearSenseAry();
1829            
1830             }
1831            
1832             $word2vec->ClearVocabularyHash();
1833             undef( $word2vec );
1834            
1835             return 0;
1836             }
1837            
1838             sub WSDParseFile
1839             {
1840             my ( $self, $filePath, $stopListRegex ) = @_;
1841            
1842             # Check(s)
1843             return undef if !defined( $filePath );
1844            
1845             # Begin file parsing
1846             print( "Parsing File: $filePath\n" ) if ( $self->GetDebugLog() == 0 );
1847             $self->WriteLog( "WSDParseFile - Parsing: $filePath" );
1848            
1849             open( my $fileHandle, "<:", $filePath ) or die "Error: Unable To Read File: $filePath";
1850            
1851             my $line = <$fileHandle>;
1852             return undef if ( index( $line, "
1853            
1854             $line = <$fileHandle>;
1855             return undef if ( index( $line, "lexelt item=\"" ) == -1 );
1856            
1857             my @dataAry = ();
1858            
1859             while( $line = <$fileHandle> )
1860             {
1861             chomp( $line );
1862             #print "$line\n"; # REMOVE ME
1863            
1864             if( index( $line, "
1865             {
1866             my $dataEntry = new WSDData();
1867            
1868             $line =~ s/
1869             $line =~ s/\">//g;
1870            
1871             $dataEntry->instanceID( $line );
1872             #print "InstanceID: $line\n"; # REMOVE ME
1873            
1874             # Fetch next line for answer instance and sense id
1875             $line = <$fileHandle>;
1876             chomp( $line );
1877            
1878             if( index( $line, "
1879             {
1880             # Set answer instance id
1881             $line =~ s/
1882             my $startIndex = 0;
1883             my $endIndex = index( $line, "\"" );
1884             $dataEntry->answerInstanceID( substr( $line, $startIndex, $endIndex ) );
1885             #print "Answer Instance ID: " . substr( $line, $startIndex, $endIndex ) . "\n"; # REMOVE ME
1886            
1887             # Set sense id
1888             if( index( $line, "senseid=\"" ) != -1 )
1889             {
1890             $startIndex = $endIndex + 1;
1891             $endIndex = length( $line );
1892             $line = substr( $line, $startIndex, $endIndex );
1893             $line =~ s/ +//g;
1894             $line =~ s/senseid=\"//g;
1895             $line =~ s/\"\/>//g;
1896             $dataEntry->senseID( $line );
1897             #print "SenseID: $line\n"; # REMOVE ME
1898             }
1899             }
1900            
1901             # Fetch next line for context
1902             $line = <$fileHandle>;
1903             chomp( $line );
1904            
1905             if( index( $line, "" ) != -1 )
1906             {
1907             # Fetch next line for context data
1908             $line = <$fileHandle>;
1909             chomp( $line );
1910            
1911             while( index( $line, "") == -1 )
1912             {
1913             # Normalize text
1914             $line =~ s///g; # Remove tag
1915             $line =~ s/<\/head>//g; # Remove tag
1916             $line = lc( $line ); # Convert all characters to lowercase
1917             $line =~ s/'s//g; # Remove "'s" characters (Apostrophe 's')
1918             $line =~ s/-/ /g; # Replace all hyphen characters to spaces
1919             $line =~ tr/a-z/ /cs; # Remove all characters except a to z
1920             $line =~ s/$stopListRegex//g if defined( $stopListRegex ); # Remove "stop" words
1921             $line =~ s/ +/ /g; # Remove duplicate white spaces between words
1922             $line = "" if( $line eq " " ); # Change line to empty string if line only contains space.
1923            
1924             my $context = $dataEntry->contextStr;
1925             $context .= "$line " if length( $line ) > 0;
1926             $context .= "" if length( $line ) == 0;
1927             $dataEntry->contextStr( $context );
1928             #print "Normalized Context: $line\n"; # REMOVE ME
1929            
1930             # Fetch next line for more context data
1931             $line = <$fileHandle>;
1932             chomp( $line );
1933             }
1934             }
1935            
1936             # Fetch next line for end of instance data entry
1937             $line = <$fileHandle>;
1938             chomp( $line );
1939            
1940             push( @dataAry, $dataEntry ) if index( $line, "" ) != -1;
1941             }
1942             }
1943            
1944             undef( $fileHandle );
1945            
1946             return \@dataAry;
1947             }
1948            
1949             sub WSDCalculateCosineAvgSimilarity
1950             {
1951             my ( $self ) = @_;
1952            
1953             my @instanceAry = $self->GetInstanceAry();
1954             my @senseAry = $self->GetSenseAry();
1955            
1956             # Check(s)
1957             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Error: Instance Or Sense Array Equals Zero - Cannot Continue" ) if ( @instanceAry == 0 || @senseAry == 0 );
1958             return -1 if ( @instanceAry == 0 || @senseAry == 0 );
1959            
1960             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Starting Word Sense Disambiguation Computations" );
1961            
1962             my $word2vec = $self->GetWord2VecHandler();
1963            
1964             # Calculate best senseID for each instance via cosine similarity of vector average.
1965             for my $instance ( @instanceAry )
1966             {
1967             my $instanceContext = $instance->contextStr;
1968             my @instanceWordAry = split( ' ', $instanceContext );
1969            
1970             # Compute vector average for instance->contextStr once and store value in memory to save computational time
1971             # NOTE: This is not necessary to store the result, since it is only used once.
1972             # Might have possibly applications in the future releases.
1973             # Comment out if needed be to save memory during run-time.
1974             my $resultStr1 = "";
1975            
1976             if( !defined( $instance->vectorAvgStr ) )
1977             {
1978             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Calculating Vector Average Of Instance: \"" . $instance->instanceID . "\" Context" ) if defined( $instance->instanceID );
1979            
1980             $resultStr1 = $word2vec->ComputeAverageOfWords( \@instanceWordAry );
1981             $instance->vectorAvgStr( $resultStr1 ) if defined( $resultStr1 );
1982             }
1983             else
1984             {
1985             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Vector Average Of Instance: \"" .$instance->instanceID . "\" Context Previously Computed" ) if defined( $instance->instanceID );
1986             $resultStr1 = $instance->vectorAvgStr;
1987             }
1988            
1989             # Clear Instance Word Array
1990             undef( @instanceWordAry );
1991             @instanceWordAry = ();
1992            
1993             for my $sense ( @senseAry )
1994             {
1995             my $senseContext = $sense->contextStr;
1996             my @senseWordAry = split( ' ', $senseContext );
1997            
1998             # Compute vector average for sense->contextStr once and store value in memory to save computational time
1999             my $resultStr2 = "";
2000            
2001             if( !defined( $sense->vectorAvgStr ) )
2002             {
2003             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Calculating Vector Average Of Sense: \"" . $sense->senseID . "\" Context" ) if defined( $sense->senseID );
2004            
2005             $resultStr2 = $word2vec->ComputeAverageOfWords( \@senseWordAry ) if !defined( $sense->vectorAvgStr );
2006             $sense->vectorAvgStr( $resultStr2 ) if defined( $resultStr2 );
2007             }
2008             else
2009             {
2010             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Vector Average Of Sense: \"" . $sense->senseID . "\" Context Previously Computed" ) if defined( $sense->senseID );
2011             $resultStr2 = $sense->vectorAvgStr;
2012             }
2013            
2014             # Clear Sense Word Array
2015             undef( @senseWordAry );
2016             @senseWordAry = ();
2017            
2018             # Compute Cosine Similarity Of Average Vectors
2019             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Calculating Cosine Similarity Between: \"$instanceContext\" and \"$senseContext\"" );
2020             my $cosSimValue = $word2vec->ComputeCosineSimilarityOfWordVectors( $resultStr1, $resultStr2 );
2021            
2022             # Assign First Sense ID To Calculated Sense ID
2023             if ( !defined( $instance->cosSimValue ) || ( defined( $instance->cosSimValue ) && defined( $cosSimValue ) && $cosSimValue > $instance->cosSimValue ) )
2024             {
2025             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Calculated Cosine Similarity Between Instance and Sense Context Greater Than Current Value" ) if defined( $cosSimValue );
2026             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Assigning \"Instance ID: " . $instance->instanceID .
2027             "\" -> \"Calculated Sense ID: " . $sense->senseID . "\" - \"CosSimValue: " . $cosSimValue . "\"" ) if defined( $cosSimValue );
2028            
2029             # Only Assign Calculated Sense ID If Cosine Similarity Is Defined
2030             $instance->calculatedSenseID( $sense->senseID ) if defined( $cosSimValue );
2031             $instance->calculatedSenseID( "undef" ) if !defined( $cosSimValue );
2032             $instance->cosSimValue( $cosSimValue );
2033             }
2034             elsif( defined( $instance->cosSimValue ) && ( defined( $cosSimValue ) && $cosSimValue <= $instance->cosSimValue ) )
2035             {
2036             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Calculated Cosine Similarity Between Instance and Sense Context Less Than Or Equal To Current Value" .
2037             " - \"CosSimValue: " . $cosSimValue . "\"" ) if defined( $cosSimValue );
2038             }
2039            
2040             # Clear Sense Context Average Cosine Similarity Vector
2041             $resultStr2 = "";
2042             }
2043            
2044             # Clear Instance Context Average Cosine Similarity Vector
2045             $resultStr1 = "";
2046             }
2047            
2048             $self->WriteLog( "WSDCalculateCosineAvgSimilarity - Complete" );
2049            
2050             return 0;
2051             }
2052            
2053             sub _WSDCalculateAccuracy
2054             {
2055             my ( $self ) = @_;
2056            
2057             my @instanceAry = $self->GetInstanceAry();
2058            
2059             # Check(s)
2060             return -1 if @instanceAry == 0;
2061            
2062             my $numberCorrect = 0;
2063            
2064             for my $instance ( @instanceAry )
2065             {
2066             $numberCorrect++ if $instance->calculatedSenseID eq $instance->senseID;
2067             }
2068            
2069             return $numberCorrect / @instanceAry;
2070             }
2071            
2072             sub WSDPrintResults
2073             {
2074             my ( $self ) = @_;
2075            
2076             my $percentCorrect = CalculateAccuracy();
2077            
2078             $self->WriteLog( "Accuracy: $percentCorrect" );
2079            
2080             my @instanceAry = $self->GetInstanceAry();
2081            
2082             for my $instance ( @instanceAry )
2083             {
2084             $self->WriteLog( "InstanceID: " . $instance->instanceID );
2085             $self->WriteLog( " - Assigned SenseID: " . $instance->senseID );
2086             $self->WriteLog( " - Calculated SenseID: " . $instance->calculatedSenseID );
2087             $self->WriteLog( " - CosSim: " . $instance->cosSimValue ) if defined( $instance->cosSimValue );
2088             $self->WriteLog( " - CosSim: undef " ) if !defined( $instance->cosSimValue );
2089             $self->WriteLog( "" );
2090             }
2091             }
2092            
2093             sub WSDSaveResults
2094             {
2095             my ( $self, $instancesFilePath ) = @_;
2096            
2097             open( my $fileHandle, ">:encoding(utf8)", "$instancesFilePath.results.txt" ) or die "Error: Unable to create save file\n";
2098            
2099             my $percentCorrect = $self->_WSDCalculateAccuracy();
2100            
2101             print $fileHandle "Accuracy: $percentCorrect\n";
2102            
2103             my @instanceAry = $self->GetInstanceAry();
2104            
2105             for my $instance ( @instanceAry )
2106             {
2107             print $fileHandle "InstanceID: " . $instance->instanceID;
2108             print $fileHandle " - Assigned SenseID: " . $instance->senseID;
2109             print $fileHandle " - Calculated SenseID: " . $instance->calculatedSenseID;
2110             print $fileHandle " - CosSim: " . $instance->cosSimValue if defined( $instance->cosSimValue );
2111             print $fileHandle " - CosSim: undef" if !defined( $instance->cosSimValue );
2112             print $fileHandle "\n";
2113             }
2114            
2115             close( $fileHandle );
2116             }
2117            
2118             sub _WSDGenerateAccuracyReport
2119             {
2120             my ( $self, $workingDir ) = @_;
2121            
2122             # Check(s)
2123             $self->WriteLog( "_WSDGenerateAccuracyReport - Working Directory Does Not Exist" ) if !( -e $workingDir );
2124             return -1 if !( -e $workingDir );
2125            
2126             # Read File Name(s) From Specified Directory
2127             $self->WriteLog( "_WSDGenerateAccuracyReport - Working Directory: $workingDir" );
2128            
2129             my @filesToParse = ();
2130            
2131             opendir( my $dirHandle, $workingDir ) or die "Error: Opening working directory\n";
2132            
2133             for my $file ( readdir( $dirHandle ) )
2134             {
2135             push( @filesToParse, $file ) if ( index( $file, ".results" ) != -1 );
2136             }
2137            
2138             close( $dirHandle );
2139             undef( $dirHandle );
2140            
2141            
2142             # Check(s)
2143             $self->WriteLog( "_WSDGenerateAccuracyReport - Warning: No Results Files Found") if ( @filesToParse == 0 );
2144             return if ( @filesToParse == 0 );
2145            
2146             $self->WriteLog( "_WSDGenerateAccuracyReport - Fetching Results From Files" ) if ( @filesToParse != 0 );
2147            
2148             my @resultAry = ();
2149            
2150             # Fetch accuracy results from each file
2151             for my $resultFile ( @filesToParse )
2152             {
2153             open( my $tempHandle, "<:encoding(utf8)", "$workingDir/$resultFile" ) or die "Error opening: $resultFile\n";
2154            
2155             while( my $line = <$tempHandle> )
2156             {
2157             chomp( $line );
2158            
2159             if( index( $line, "Accuracy:" ) != -1 )
2160             {
2161             my $endIndex = index( $resultFile, ".results" );
2162             $resultFile = substr( $resultFile, 0, $endIndex );
2163             push( @resultAry, "$resultFile : $line" );
2164             last;
2165             }
2166             }
2167            
2168             close( $tempHandle );
2169             undef( $tempHandle );
2170             }
2171            
2172             $self->WriteLog( "_WSDGenerateAccuracyReport - Done fetching results" ) if ( @filesToParse != 0 );
2173             $self->WriteLog( "_WSDGenerateAccuracyReport - Saving data to file: \"AccuracyReport.txt\"" ) if ( @filesToParse != 0 );
2174            
2175             # Save all results in file "AccuracyResults.txt"
2176             open( my $fileHandle, ">:encoding(utf8)", "$workingDir/AccuracyReport.txt" ) or die "Error creating file: \"AccuracyReport.txt\"\n";
2177            
2178             @resultAry = sort( @resultAry );
2179            
2180             for my $result ( @resultAry )
2181             {
2182             print $fileHandle $result . "\n";
2183             }
2184            
2185             close( $fileHandle );
2186             undef( $fileHandle );
2187            
2188             $self->WriteLog( "_WSDGenerateAccuracyReport - Data saved" ) if ( @filesToParse != 0 );
2189             }
2190            
2191             # Not my own code
2192             sub _WSDStop
2193             {
2194             my ( $self, $stopListFilePath ) = @_;
2195            
2196             $self->WriteLog( "_WSDStop - Reading Stop List Path: \"$stopListFilePath\"" );
2197            
2198             # Check(s)
2199             $self->WriteLog( "_WSDStop - Error: Stop List File Path Not Defined" ) if !defined( $stopListFilePath );
2200             return undef if !defined( $stopListFilePath );
2201            
2202             $self->WriteLog( "_WSDStop - Error: Stop List File Path Does Not Exist" ) if !( -e $stopListFilePath );
2203             return undef if !( -e $stopListFilePath );
2204            
2205             my $stop_regex = "";
2206             my $stop_mode = "AND";
2207            
2208             open ( STP, $stopListFilePath ) || die ( "Error: Couldn't Open The Stoplist File: $stopListFilePath\n" );
2209            
2210             while ( ) {
2211             chomp;
2212            
2213             if(/\@stop.mode\s*=\s*(\w+)\s*$/) {
2214             $stop_mode=$1;
2215             if(!($stop_mode=~/^(AND|and|OR|or)$/)) {
2216             print STDERR "Requested Stop Mode $1 is not supported.\n";
2217             exit;
2218             }
2219             next;
2220             }
2221            
2222             # accepting Perl Regexs from Stopfile
2223             s/^\s+//;
2224             s/\s+$//;
2225            
2226             #handling a blank lines
2227             if(/^\s*$/) { next; }
2228            
2229             #check if a valid Perl Regex
2230             if(!(/^\//)) {
2231             print STDERR "Stop token regular expression <$_> should start with '/'\n";
2232             exit;
2233             }
2234             if(!(/\/$/)) {
2235             print STDERR "Stop token regular expression <$_> should end with '/'\n";
2236             exit;
2237             }
2238            
2239             #remove the / s from beginning and end
2240             s/^\///;
2241             s/\/$//;
2242            
2243             #form a single big regex
2244             $stop_regex.="(".$_.")|";
2245             }
2246            
2247             if(length($stop_regex)<=0) {
2248             print STDERR "No valid Perl Regular Experssion found in Stop file $stopListFilePath";
2249             exit;
2250             }
2251            
2252             chop $stop_regex;
2253            
2254             # making AND a default stop mode
2255             if(!defined $stop_mode) {
2256             $stop_mode="AND";
2257             }
2258            
2259             close STP;
2260            
2261             return $stop_regex;
2262             }
2263            
2264             sub ConvertStringLineEndingsToTargetOS
2265             {
2266             my ( $self, $str ) = @_;
2267            
2268             # Check(s)
2269             $self->WriteLog( "ConvertLineEndingToTargetOS - Error: String Parameter Is Undefined" ) if ( $str eq "" );
2270             return undef if !defined( $str );
2271            
2272             $self->WriteLog( "ConvertLineEndingToTargetOS - Warning: Cannot Convert Empty String" ) if ( $str eq "" );
2273             return "" if ( $str eq "" );
2274            
2275             # Convert String Line Ending Suitable To The Target
2276             my $lineEnding = "";
2277             my $os = "linux";
2278            
2279             $lineEnding = "\015\012" if ( $os eq "MSWin32" );
2280             $lineEnding = "\012" if ( $os eq "linux" );
2281             $lineEnding = "\015" if ( $os eq "MacOS" );
2282            
2283             $str =~ s/(\015\012|\012|\015)/($lineEnding)/g;
2284            
2285             # Removes Spaces At Both Ends Of String And More Than Once Space In-Between Ends
2286             $str =~ s/^\s+|\s(?=\s)|\s+$//g;
2287            
2288             return $str;
2289             }
2290            
2291             ######################################################################################
2292             # Accessors
2293             ######################################################################################
2294            
2295             sub GetWord2VecDir
2296             {
2297             my ( $self ) = @_;
2298             $self->{ _word2vecDir } = "" if !defined ( $self->{ _word2vecDir } );
2299             return $self->{ _word2vecDir };
2300             }
2301            
2302             sub GetDebugLog
2303             {
2304             my ( $self ) = @_;
2305             $self->{ _debugLog } = 0 if !defined ( $self->{ _debugLog } );
2306             return $self->{ _debugLog };
2307             }
2308            
2309             sub GetWriteLog
2310             {
2311             my ( $self ) = @_;
2312             $self->{ _writeLog } = 0 if !defined ( $self->{ _writeLog } );
2313             return $self->{ _writeLog };
2314             }
2315            
2316             sub GetIgnoreCompileErrors
2317             {
2318             my ( $self ) = @_;
2319             $self->{ _ignoreCompileErrors } = 0 if !defined ( $self->{ _ignoreCompileErrors } );
2320             return $self->{ _ignoreCompileErrors };
2321             }
2322            
2323             sub GetIgnoreFileChecks
2324             {
2325             my ( $self ) = @_;
2326             $self->{ _ignoreFileChecks } = 0 if !defined ( $self->{ _ignoreFileChecks } );
2327             return $self->{ _ignoreFileChecks };
2328             }
2329            
2330             sub GetExitFlag
2331             {
2332             my ( $self ) = @_;
2333             $self->{ _exitFlag } = 0 if !defined ( $self->{ _exitFlag } );
2334             return $self->{ _exitFlag };
2335             }
2336            
2337             sub GetFileHandle
2338             {
2339             my ( $self ) = @_;
2340            
2341             # Setup File Handle If Not Already Defined
2342             if( !defined( $self->{ _fileHandle } ) && $self->{ _writeLog } )
2343             {
2344             open( $self->{ _fileHandle }, '>:utf8', 'InterfaceLog.txt' );
2345             $self->{ _fileHandle }->autoflush( 1 ); # Auto-flushes writes to log file
2346             }
2347            
2348             return $self->{ _fileHandle };
2349             }
2350            
2351             sub GetWorkingDirectory
2352             {
2353             my ( $self ) = @_;
2354             $self->{ _workingDir } = Cwd::getcwd() if !defined ( $self->{ _workingDir } );
2355             return $self->{ _workingDir };
2356             }
2357            
2358             sub GetSpearmansHandler
2359             {
2360             my ( $self ) = @_;
2361             my $debugLog = $self->GetDebugLog();
2362             my $writeLog = $self->GetWriteLog();
2363             $self->{ _spearmans } = Word2vec::Spearmans->new( $debugLog, $writeLog ) if !defined( $self->{ _spearmans } );
2364             return $self->{ _spearmans };
2365             }
2366            
2367             sub GetWord2VecHandler
2368             {
2369             my ( $self ) = @_;
2370             my $debugLog = $self->GetDebugLog();
2371             my $writeLog = $self->GetWriteLog();
2372             $self->{ _word2vec } = Word2vec::Word2vec->new( $debugLog, $writeLog ) if !defined ( $self->{ _word2vec } );
2373             return $self->{ _word2vec };
2374             }
2375            
2376             sub GetWord2PhraseHandler
2377             {
2378             my ( $self ) = @_;
2379             my $debugLog = $self->GetDebugLog();
2380             my $writeLog = $self->GetWriteLog();
2381             $self->{ _word2phrase } = Word2vec::Word2phrase->( $debugLog, $writeLog ) if !defined ( $self->{ _word2phrase } );
2382             return $self->{ _word2phrase };
2383             }
2384            
2385             sub GetXMLToW2VHandler
2386             {
2387             my ( $self ) = @_;
2388             my $debugLog = $self->GetDebugLog();
2389             my $writeLog = $self->GetWriteLog();
2390             $self->{ _xmltow2v } = Word2vec::Xmltow2v->( $debugLog, $writeLog, 1, 1, 1, 1, 2 ) if !defined ( $self->{ _xmltow2v } );
2391             return $self->{ _xmltow2v };
2392             }
2393            
2394             sub GetUtilHandler
2395             {
2396             my ( $self ) = @_;
2397             my $debugLog = $self->GetDebugLog();
2398             my $writeLog = $self->GetWriteLog();
2399             $self->{ _util } = Word2vec::Util->new( $debugLog, $writeLog ) if !defined ( $self->{ _util } );
2400             return $self->{ _util };
2401             }
2402            
2403             sub GetInstanceAry
2404             {
2405             my ( $self ) = @_;
2406             @{ $self->{ _instanceAry } } = () if !defined( $self->{ _instanceAry } );
2407             return @{ $self->{ _instanceAry } };
2408             }
2409            
2410             sub GetSenseAry
2411             {
2412             my ( $self ) = @_;
2413             @{ $self->{ _senseAry } } = () if !defined( $self->{ _senseAry } );
2414             return @{ $self->{ _senseAry } };
2415             }
2416            
2417             sub GetInstanceCount
2418             {
2419             my ( $self ) = @_;
2420             $self->{ _instanceCount } = 0 if !defined( $self->{ _instanceCount } );
2421             return $self->{ _instanceCount };
2422             }
2423            
2424             sub GetSenseCount
2425             {
2426             my ( $self ) = @_;
2427             $self->{ _senseCount } = 0 if !defined( $self->{ _senseCount } );
2428             return $self->{ _senseCount };
2429             }
2430            
2431            
2432             ######################################################################################
2433             # Mutators
2434             ######################################################################################
2435            
2436             sub SetWord2VecDir
2437             {
2438             my ( $self, $dir ) = @_;
2439            
2440             $self->WriteLog( "SetWord2VecDir - Changing Word2Vec Executable Directory To $dir" ) if defined( $dir );
2441             $self->WriteLog( "SetWord2VecDir - Adjusting For \"word2vec\" And \"word2phrase\" Objects" ) if defined( $dir );
2442            
2443             # Set word2vec Directory In Respective Objects
2444             $self->W2VSetWord2VecExeDir( $dir ) if defined( $dir );
2445             $self->W2PSetWord2PhraseExeDir( $dir ) if defined( $dir );
2446            
2447             return $self->{ _word2vecDir } = $dir if defined( $dir );
2448             }
2449            
2450             sub SetDebugLog
2451             {
2452             my ( $self, $temp ) = @_;
2453             return $self->{ _debugLog } = $temp if defined( $temp );
2454             }
2455            
2456             sub SetWriteLog
2457             {
2458             my ( $self, $temp ) = @_;
2459             return $self->{ _writeLog } = $temp if defined( $temp );
2460             }
2461            
2462             # Note: Useless Sub-routines - Remove Me
2463             sub SetIgnoreCompileErrors
2464             {
2465             my ( $self, $temp ) = @_;
2466             return $self->{ _ignoreCompileErrors } = $temp if defined( $temp );
2467             }
2468            
2469             # Note: Useless Sub-routines - Remove Me
2470             sub SetIgnoreFileCheckErrors
2471             {
2472             my ( $self, $temp ) = @_;
2473             return $self->{ _ignoreFileChecks } = $temp if defined( $temp );
2474             }
2475            
2476             sub SetWorkingDirectory
2477             {
2478             my ( $self, $temp ) = @_;
2479             $self->WriteLog( "SetWorkingDirectory - Directory Changed From: \"" . $self->{ _workingDir } . "\ To \"$temp\"" )
2480             if defined( $self->{ _workingDir } ) && defined( $temp );
2481             return $self->{ _workingDir } = $temp if defined( $temp );
2482             }
2483            
2484             sub SetInstanceAry
2485             {
2486             my ( $self, $aryRef ) = @_;
2487             return @{ $self->{ _instanceAry } } = @{ $aryRef } if defined( $aryRef );
2488             }
2489            
2490             sub ClearInstanceAry
2491             {
2492             my ( $self ) = @_;
2493             undef( @{ $self->{ _instanceAry } } );
2494             return @{ $self->{ _instanceAry } } = ();
2495             }
2496            
2497             sub SetSenseAry
2498             {
2499             my ( $self, $aryRef ) = @_;
2500             return @{ $self->{ _senseAry } } = @{ $aryRef } if defined( $aryRef );
2501             }
2502            
2503             sub ClearSenseAry
2504             {
2505             my ( $self ) = @_;
2506             undef( @{ $self->{ _senseAry } } );
2507             return @{ $self->{ _senseAry } } = ();
2508             }
2509            
2510             sub SetInstanceCount
2511             {
2512             my ( $self, $value ) = @_;
2513             return $self->{ _instanceCount } = $value if defined( $value );
2514             }
2515            
2516             sub SetSenseCount
2517             {
2518             my ( $self, $value ) = @_;
2519             return $self->{ _senseCount } = $value if defined( $value );
2520             }
2521            
2522            
2523             ######################################################################################
2524             # Debug Functions
2525             ######################################################################################
2526            
2527             sub GetTime
2528             {
2529             my ( $self ) = @_;
2530             my( $sec, $min, $hour ) = localtime();
2531            
2532             if( $hour < 10 )
2533             {
2534             $hour = "0$hour";
2535             }
2536            
2537             if( $min < 10 )
2538             {
2539             $min = "0$min";
2540             }
2541            
2542             if( $sec < 10 )
2543             {
2544             $sec = "0$sec";
2545             }
2546            
2547             return "$hour:$min:$sec";
2548             }
2549            
2550             sub GetDate
2551             {
2552             my ( $self ) = @_;
2553             my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime();
2554            
2555             $mon += 1;
2556             $year += 1900;
2557            
2558             return "$mon/$mday/$year";
2559             }
2560            
2561             sub WriteLog
2562             {
2563             my ( $self ) = shift;
2564             my $string = shift;
2565             my $printNewLine = shift;
2566            
2567             return if !defined ( $string );
2568             $printNewLine = 1 if !defined ( $printNewLine );
2569            
2570            
2571             if( $self->GetDebugLog() )
2572             {
2573             if( ref ( $self ) ne "Word2vec::Interface" )
2574             {
2575             print( GetDate() . " " . GetTime() . " - interface: Cannot Call WriteLog() From Outside Module!\n" );
2576             return;
2577             }
2578            
2579             $string = "" if !defined ( $string );
2580             print GetDate() . " " . GetTime() . " - interface::$string";
2581             print "\n" if( $printNewLine != 0 );
2582             }
2583            
2584             if( $self->GetWriteLog() )
2585             {
2586             if( ref ( $self ) ne "Word2vec::Interface" )
2587             {
2588             print( GetDate() . " " . GetTime() . " - interface: Cannot Call WriteLog() From Outside Module!\n" );
2589             return;
2590             }
2591            
2592             my $fileHandle = $self->GetFileHandle();
2593            
2594             if( defined( $fileHandle ) )
2595             {
2596             print( $fileHandle GetDate() . " " . GetTime() . " - interface::$string" );
2597             print( $fileHandle "\n" ) if( $printNewLine != 0 );
2598             }
2599             }
2600             }
2601            
2602            
2603             ######################################################################################
2604             # Utility Module Functions
2605             ######################################################################################
2606            
2607             sub IsFileOrDirectory
2608             {
2609             my ( $self, $path ) = @_;
2610             return $self->GetUtilHandler()->IsFileOrDirectory( $path );
2611             }
2612            
2613             sub GetFilesInDirectory
2614             {
2615             my ( $self, $directoryPath, $fileTagStr ) = @_;
2616             return $self->GetUtilHandler()->GetFilesInDirectory( $directoryPath, $fileTagStr );
2617             }
2618            
2619            
2620             ######################################################################################
2621             # Spearmans Module Functions
2622             ######################################################################################
2623            
2624             sub SpCalculateSpearmans
2625             {
2626             my ( $self, $fileA, $fileB, $includeCountsInResults ) = @_;
2627             return $self->GetSpearmansHandler()->CalculateSpearmans( $fileA, $fileB, $includeCountsInResults );
2628             }
2629            
2630             sub SpIsFileWordOrCUIFile
2631             {
2632             my ( $self, $filePath ) = @_;
2633             return $self->GetSpearmansHandler()->IsFileWordOrCUIFile( $filePath );
2634             }
2635            
2636             sub SpGetPrecision
2637             {
2638             my ( $self ) = @_;
2639             return $self->GetSpearmansHandler()->GetPrecision();
2640             }
2641            
2642             sub SpGetIsFileOfWords
2643             {
2644             my ( $self ) = @_;
2645             return $self->GetSpearmansHandler()->GetIsFileOfWords();
2646             }
2647            
2648             sub SpGetPrintN
2649             {
2650             my ( $self ) = @_;
2651             return $self->GetSpearmansHandler()->GetPrintN();
2652             }
2653            
2654             sub SpGetACount
2655             {
2656             my ( $self ) = @_;
2657             return $self->GetSpearmansHandler()->GetACount();
2658             }
2659            
2660             sub SpGetBCount
2661             {
2662             my ( $self ) = @_;
2663             return $self->GetSpearmansHandler()->GetBCount();
2664             }
2665            
2666             sub SpGetNValue
2667             {
2668             my ( $self ) = @_;
2669             return $self->GetSpearmansHandler()->GetNValue();
2670             }
2671            
2672             sub SpSetPrecision
2673             {
2674             my ( $self, $value ) = @_;
2675             return $self->GetSpearmansHandler()->SetPrecision( $value );
2676             }
2677            
2678             sub SpSetIsFileOfWords
2679             {
2680             my ( $self, $value ) = @_;
2681             return $self->GetSpearmansHandler()->SetIsFileOfWords( $value );
2682             }
2683            
2684             sub SpSetPrintN
2685             {
2686             my ( $self, $value ) = @_;
2687             return $self->GetSpearmansHandler()->SetPrintN( $value );
2688             }
2689            
2690             ######################################################################################
2691             # Word2Vec Module Functions
2692             ######################################################################################
2693            
2694             sub W2VExecuteTraining
2695             {
2696             my ( $self, $trainFilePath, $outputFilePath, $vectorSize, $windowSize, $minCount,
2697             $sample, $negative, $alpha, $hs, $binary, $numOfThreads, $iterations,
2698             $useCBOW, $classes, $readVocab, $saveVocab, $debug, $overwrite ) = @_;
2699            
2700             return $self->GetWord2VecHandler()->ExecuteTraining( $trainFilePath, $outputFilePath, $vectorSize, $windowSize,
2701             $minCount, $sample, $negative, $alpha, $hs, $binary,
2702             $numOfThreads, $iterations, $useCBOW, $classes, $readVocab,
2703             $saveVocab, $debug, $overwrite );
2704             }
2705            
2706             sub W2VExecuteStringTraining
2707             {
2708             my ( $self, $trainingStr, $outputFilePath, $vectorSize, $windowSize, $minCount,
2709             $sample, $negative, $alpha, $hs, $binary, $numOfThreads, $iterations,
2710             $useCBOW, $classes, $readVocab, $saveVocab, $debug, $overwrite ) = @_;
2711            
2712             return $self->GetWord2VecHandler()->ExecuteStringTraining( $trainingStr, $outputFilePath, $vectorSize, $windowSize,
2713             $minCount, $sample, $negative, $alpha, $hs, $binary,
2714             $numOfThreads, $iterations, $useCBOW, $classes, $readVocab,
2715             $saveVocab, $debug, $overwrite );
2716             }
2717            
2718             sub W2VComputeCosineSimilarity
2719             {
2720             my ( $self, $wordA, $wordB ) = @_;
2721             return $self->GetWord2VecHandler()->ComputeCosineSimilarity( $wordA, $wordB );
2722             }
2723            
2724             sub W2VComputeAvgOfWordsCosineSimilarity
2725             {
2726             my ( $self, $avgStrA, $avgStrB ) = @_;
2727             return $self->GetWord2VecHandler()->ComputeAvgOfWordsCosineSimilarity( $avgStrA, $avgStrB );
2728             }
2729            
2730             sub W2VComputeMultiWordCosineSimilarity
2731             {
2732             my ( $self, $wordA, $wordB, $allWordsMustExist ) = @_;
2733             return $self->GetWord2VecHandler()->ComputeMultiWordCosineSimilarity( $wordA, $wordB, $allWordsMustExist );
2734             }
2735            
2736             sub W2VComputeCosineSimilarityOfWordVectors
2737             {
2738             my( $self, $wordAData, $wordBData ) = @_;
2739             return $self->GetWord2VecHandler()->ComputeCosineSimilarityOfWordVectors( $wordAData, $wordBData );
2740             }
2741            
2742             sub W2VCosSimWithUserInput
2743             {
2744             my ( $self ) = @_;
2745             $self->GetWord2VecHandler()->CosSimWithUserInput();
2746             }
2747            
2748             sub W2VMultiWordCosSimWithUserInput
2749             {
2750             my ( $self ) = @_;
2751             $self->GetWord2VecHandler()->MultiWordCosSimWithUserInput();
2752             }
2753            
2754             sub W2VComputeAverageOfWords
2755             {
2756             my ( $self, $wordAryRef ) = @_;
2757             return $self->GetWord2VecHandler()->ComputeAverageOfWords( $wordAryRef );
2758             }
2759            
2760             sub W2VAddTwoWords
2761             {
2762             my ( $self, $wordA, $wordB ) = @_;
2763             return $self->GetWord2VecHandler()->AddTwoWords( $wordA, $wordB );
2764             }
2765            
2766             sub W2VSubtractTwoWords
2767             {
2768             my ( $self, $wordA, $wordB ) = @_;
2769             return $self->GetWord2VecHandler()->SubtractTwoWords( $wordA, $wordB );
2770             }
2771            
2772             sub W2VAddTwoWordVectors
2773             {
2774             my ( $self, $wordA, $wordB ) = @_;
2775             return $self->GetWord2VecHandler()->AddTwoWordVectors( $wordA, $wordB );
2776             }
2777            
2778             sub W2VSubtractTwoWordVectors
2779             {
2780             my ( $self, $wordA, $wordB ) = @_;
2781             return $self->GetWord2VecHandler()->SubtractTwoWordVectors( $wordA, $wordB );
2782             }
2783            
2784             sub W2VAverageOfTwoWordVectors
2785             {
2786             my ( $self, $wordA, $wordB ) = @_;
2787             return $self->GetWord2VecHandler()->AverageOfTwoWordVectors( $wordA, $wordB );
2788             }
2789            
2790             sub W2VGetWordVector
2791             {
2792             my ( $self, $searchWord ) = @_;
2793             return $self->GetWord2VecHandler()->GetWordVector( $searchWord );
2794             }
2795            
2796             sub W2VIsVectorDataInMemory
2797             {
2798             my ( $self ) = @_;
2799             return $self->GetWord2VecHandler()->IsVectorDataInMemory();
2800             }
2801            
2802             sub W2VIsWordOrCUIVectorData
2803             {
2804             my ( $self ) = @_;
2805             return $self->GetWord2VecHandler()->IsWordOrCUIVectorData();
2806             }
2807            
2808             sub W2VIsVectorDataSorted
2809             {
2810             my ( $self, $aryRef ) = @_;
2811             return $self->GetWord2VecHandler()->IsVectorDataSorted( $aryRef );
2812             }
2813            
2814             sub W2VCheckWord2VecDataFileType
2815             {
2816             my ( $self, $fileDir ) = @_;
2817             return $self->GetWord2VecHandler()->CheckWord2VecDataFileType( $fileDir );
2818             }
2819            
2820             sub W2VReadTrainedVectorDataFromFile
2821             {
2822             my ( $self, $fileDir, $searchWord ) = @_;
2823             return $self->GetWord2VecHandler()->ReadTrainedVectorDataFromFile( $fileDir, $searchWord );
2824             }
2825            
2826             sub W2VSaveTrainedVectorDataToFile
2827             {
2828             my ( $self, $filename, $saveFormat ) = @_;
2829             return $self->GetWord2VecHandler()->SaveTrainedVectorDataToFile( $filename, $saveFormat );
2830             }
2831            
2832             sub W2VStringsAreEqual
2833             {
2834             my ( $self, $strA, $strB ) = @_;
2835             return $self->GetWord2VecHandler()->StringsAreEqual( $strA, $strB );
2836             }
2837            
2838             sub W2VRemoveWordFromWordVectorString
2839             {
2840             my ( $self, $vectorDataStr ) = @_;
2841             return $self->GetWord2VecHandler()->RemoveWordFromWordVectorString( $vectorDataStr );
2842             }
2843            
2844             sub W2VConvertRawSparseTextToVectorDataAry
2845             {
2846             my ( $self, $strData ) = @_;
2847             return $self->GetWord2VecHandler()->ConvertRawSparseTextToVectorDataAry( $strData );
2848             }
2849            
2850             sub W2VConvertRawSparseTextToVectorDataHash
2851             {
2852             my ( $self, $strData ) = @_;
2853             return $self->GetWord2VecHandler()->ConvertRawSparseTextToVectorDataHash( $strData );
2854             }
2855            
2856             sub W2VGetDebugLog
2857             {
2858             my ( $self ) = @_;
2859             return $self->GetWord2VecHandler()->GetDebugLog();
2860             }
2861            
2862             sub W2VGetWriteLog
2863             {
2864             my ( $self ) = @_;
2865             return $self->GetWord2VecHandler()->GetWriteLog();
2866             }
2867            
2868             sub W2VGetFileHandle
2869             {
2870             my ( $self ) = @_;
2871             return $self->GetWord2VecHandler()->GetFileHandle();
2872             }
2873            
2874             sub W2VGetTrainFilePath
2875             {
2876             my ( $self ) = @_;
2877             return $self->GetWord2VecHandler()->GetTrainFilePath();
2878             }
2879            
2880             sub W2VGetOutputFilePath
2881             {
2882             my ( $self ) = @_;
2883             return $self->GetWord2VecHandler()->GetOutputFilePath();
2884             }
2885            
2886             sub W2VGetWordVecSize
2887             {
2888             my ( $self ) = @_;
2889             return $self->GetWord2VecHandler()->GetWordVecSize();
2890             }
2891            
2892             sub W2VGetWindowSize
2893             {
2894             my ( $self ) = @_;
2895             return $self->GetWord2VecHandler()->GetWindowSize();
2896             }
2897            
2898             sub W2VGetSample
2899             {
2900             my ( $self ) = @_;
2901             return $self->GetWord2VecHandler()->GetSample();
2902             }
2903            
2904             sub W2VGetHSoftMax
2905             {
2906             my ( $self ) = @_;
2907             return $self->GetWord2VecHandler()->GetHSoftMax();
2908             }
2909            
2910             sub W2VGetNegative
2911             {
2912             my ( $self ) = @_;
2913             return $self->GetWord2VecHandler()->GetNegative();
2914             }
2915            
2916             sub W2VGetNumOfThreads
2917             {
2918             my ( $self ) = @_;
2919             return $self->GetWord2VecHandler()->GetNumOfThreads();
2920             }
2921            
2922             sub W2VGetNumOfIterations
2923             {
2924             my ( $self ) = @_;
2925             return $self->GetWord2VecHandler()->GetNumOfIterations();
2926             }
2927            
2928             sub W2VGetMinCount
2929             {
2930             my ( $self ) = @_;
2931             return $self->GetWord2VecHandler()->GetMinCount();
2932             }
2933            
2934             sub W2VGetAlpha
2935             {
2936             my ( $self ) = @_;
2937             return $self->GetWord2VecHandler()->GetAlpha();
2938             }
2939            
2940             sub W2VGetClasses
2941             {
2942             my ( $self ) = @_;
2943             return $self->GetWord2VecHandler()->GetClasses();
2944             }
2945            
2946             sub W2VGetDebugTraining
2947             {
2948             my ( $self ) = @_;
2949             return $self->GetWord2VecHandler()->GetDebugTraining();
2950             }
2951            
2952             sub W2VGetBinaryOutput
2953             {
2954             my ( $self ) = @_;
2955             return $self->GetWord2VecHandler()->GetBinaryOutput();
2956             }
2957            
2958             sub W2VGetSaveVocabFilePath
2959             {
2960             my ( $self ) = @_;
2961             return $self->GetWord2VecHandler()->GetSaveVocabFilePath();
2962             }
2963            
2964             sub W2VGetReadVocabFilePath
2965             {
2966             my ( $self ) = @_;
2967             return $self->GetWord2VecHandler()->GetReadVocabFilePath();
2968             }
2969            
2970             sub W2VGetUseCBOW
2971             {
2972             my ( $self ) = @_;
2973             return $self->GetWord2VecHandler()->GetUseCBOW();
2974             }
2975            
2976             sub W2VGetWorkingDir
2977             {
2978             my ( $self ) = @_;
2979             return $self->GetWord2VecHandler()->GetWorkingDir();
2980             }
2981            
2982             sub W2VGetWord2VecExeDir
2983             {
2984             my ( $self ) = @_;
2985             return $self->GetWord2VecHandler()->GetWord2VecExeDir();
2986             }
2987            
2988             sub W2VGetVocabularyHash
2989             {
2990             my ( $self ) = @_;
2991             return $self->GetWord2VecHandler()->GetVocabularyHash();
2992             }
2993            
2994             sub W2VGetOverwriteOldFile
2995             {
2996             my ( $self ) = @_;
2997             return $self->GetWord2VecHandler()->GetOverwriteOldFile();
2998             }
2999            
3000             sub W2VGetSparseVectorMode
3001             {
3002             my ( $self ) = @_;
3003             return $self->GetWord2VecHandler()->GetSparseVectorMode();
3004             }
3005            
3006             sub W2VGetVectorLength
3007             {
3008             my ( $self ) = @_;
3009             return $self->GetWord2VecHandler()->GetVectorLength();
3010             }
3011            
3012             sub W2VGetNumberOfWords
3013             {
3014             my ( $self ) = @_;
3015             return $self->GetWord2VecHandler()->GetNumberOfWords();
3016             }
3017            
3018             sub W2VGetMinimizeMemoryUsage
3019             {
3020             my ( $self ) = @_;
3021             return $self->GetWord2VecHandler()->GetMinimizeMemoryUsage();
3022             }
3023            
3024             sub W2VSetTrainFilePath
3025             {
3026             my ( $self, $str ) = @_;
3027             return $self->GetWord2VecHandler()->SetTrainFilePath( $str );
3028             }
3029            
3030             sub W2VSetOutputFilePath
3031             {
3032             my ( $self, $str ) = @_;
3033             return $self->GetWord2VecHandler()->SetOutputFilePath( $str );
3034             }
3035            
3036             sub W2VSetWordVecSize
3037             {
3038             my ( $self, $value ) = @_;
3039             return $self->GetWord2VecHandler()->SetWordVecSize( $value );
3040             }
3041            
3042             sub W2VSetWindowSize
3043             {
3044             my ( $self, $value ) = @_;
3045             return $self->GetWord2VecHandler()->SetWindowSize( $value );
3046             }
3047            
3048             sub W2VSetSample
3049             {
3050             my ( $self, $value ) = @_;
3051             return $self->GetWord2VecHandler()->SetSample( $value );
3052             }
3053            
3054             sub W2VSetHSoftMax
3055             {
3056             my ( $self, $value ) = @_;
3057             return $self->GetWord2VecHandler()->SetHSoftMax( $value );
3058             }
3059            
3060             sub W2VSetNegative
3061             {
3062             my ( $self, $value ) = @_;
3063             return $self->GetWord2VecHandler()->SetNegative( $value );
3064             }
3065            
3066             sub W2VSetNumOfThreads
3067             {
3068             my ( $self, $value ) = @_;
3069             return $self->GetWord2VecHandler()->SetNumOfThreads( $value );
3070             }
3071            
3072             sub W2VSetNumOfIterations
3073             {
3074             my ( $self, $value ) = @_;
3075             return $self->GetWord2VecHandler()->SetNumOfIterations( $value );
3076             }
3077            
3078             sub W2VSetMinCount
3079             {
3080             my ( $self, $value ) = @_;
3081             return $self->GetWord2VecHandler()->SetMinCount( $value );
3082             }
3083            
3084             sub W2VSetAlpha
3085             {
3086             my ( $self, $value ) = @_;
3087             return $self->GetWord2VecHandler()->SetAlpha( $value );
3088             }
3089            
3090             sub W2VSetClasses
3091             {
3092             my ( $self, $value ) = @_;
3093             return $self->GetWord2VecHandler()->SetClasses( $value );
3094             }
3095            
3096             sub W2VSetDebugTraining
3097             {
3098             my ( $self, $value ) = @_;
3099             return $self->GetWord2VecHandler()->SetDebugTraining( $value );
3100             }
3101            
3102             sub W2VSetBinaryOutput
3103             {
3104             my ( $self, $value ) = @_;
3105             return $self->GetWord2VecHandler()->SetBinaryOutput( $value );
3106             }
3107            
3108             sub W2VSetSaveVocabFilePath
3109             {
3110             my ( $self, $str ) = @_;
3111             return $self->GetWord2VecHandler()->SetSaveVocabFilePath( $str );
3112             }
3113            
3114             sub W2VSetReadVocabFilePath
3115             {
3116             my ( $self, $str ) = @_;
3117             return $self->GetWord2VecHandler()->SetReadVocabFilePath( $str );
3118             }
3119            
3120             sub W2VSetUseCBOW
3121             {
3122             my ( $self, $value ) = @_;
3123             return $self->GetWord2VecHandler()->SetUseCBOW( $value );
3124             }
3125            
3126             sub W2VSetWorkingDir
3127             {
3128             my ( $self, $dir ) = @_;
3129             return $self->GetWord2VecHandler()->SetWorkingDir( $dir );
3130             }
3131            
3132             sub W2VSetWord2VecExeDir
3133             {
3134             my ( $self, $dir ) = @_;
3135             return $self->GetWord2VecHandler()->SetWord2VecExeDir( $dir );
3136             }
3137            
3138             sub W2VSetVocabularyHash
3139             {
3140             my ( $self, $ref ) = @_;
3141             return $self->GetWord2VecHandler()->SetVocabularyHash( $ref );
3142             }
3143            
3144             sub W2VClearVocabularyHash
3145             {
3146             my ( $self ) = @_;
3147             return $self->GetWord2VecHandler()->ClearVocabularyHash();
3148             }
3149            
3150             sub W2VAddWordVectorToVocabHash
3151             {
3152             my ( $self, $wordVectorStr ) = @_;
3153             return $self->GetWord2VecHandler()->AddWordVectorToVocabHash( $wordVectorStr );
3154             }
3155            
3156             sub W2VSetOverwriteOldFile
3157             {
3158             my ( $self, $value ) = @_;
3159             return $self->GetWord2VecHandler()->SetOverwriteOldFile( $value );
3160             }
3161            
3162             sub W2VSetSparseVectorMode
3163             {
3164             my ( $self, $value ) = @_;
3165             return $self->GetWord2VecHandler()->SetSparseVectorMode( $value );
3166             }
3167            
3168             sub W2VSetVectorLength
3169             {
3170             my ( $self, $value ) = @_;
3171             return $self->GetWord2VecHandler()->SetVectorLength( $value );
3172             }
3173            
3174             sub W2VSetNumberOfWords
3175             {
3176             my ( $self, $value ) = @_;
3177             return $self->GetWord2VecHandler()->SetNumberOfWords( $value );
3178             }
3179            
3180             sub W2VSetMinimizeMemoryUsage
3181             {
3182             my ( $self, $value ) = @_;
3183             return $self->GetWord2VecHandler()->SetMinimizeMemoryUsage( $value );
3184             }
3185            
3186             ######################################################################################
3187             # Word2Phrase Module Functions
3188             ######################################################################################
3189            
3190             sub W2PExecuteTraining
3191             {
3192             my( $self, $trainFilePath, $outputFilePath, $minCount, $threshold, $debug, $overwrite ) = @_;
3193             return $self->GetWord2PhraseHandler()->ExecuteTraining( $trainFilePath, $outputFilePath, $minCount, $threshold, $debug, $overwrite );
3194             }
3195            
3196             sub W2PExecuteStringTraining
3197             {
3198             my( $self, $trainingStr, $outputFilePath, $minCount, $threshold, $debug, $overwrite ) = @_;
3199             return $self->GetWord2PhraseHandler()->ExecuteStringTraining( $trainingStr, $outputFilePath, $minCount, $threshold, $debug, $overwrite );
3200             }
3201            
3202             sub W2PGetDebugLog
3203             {
3204             my ( $self ) = @_;
3205             return $self->GetWord2PhraseHandler()->GetDebugLog();
3206             }
3207            
3208             sub W2PGetWriteLog
3209             {
3210             my ( $self ) = @_;
3211             return $self->GetWord2PhraseHandler()->GetWriteLog();
3212             }
3213            
3214             sub W2PGetFileHandle
3215             {
3216             my ( $self ) = @_;
3217             return $self->GetWord2PhraseHandler()->GetFileHandle();
3218             }
3219            
3220             sub W2PGetTrainFilePath
3221             {
3222             my ( $self ) = @_;
3223             return $self->GetWord2PhraseHandler()->GetTrainFilePath()
3224             }
3225            
3226             sub W2PGetOutputFilePath
3227             {
3228             my ( $self ) = @_;
3229             return $self->GetWord2PhraseHandler()->GetOutputFilePath();
3230             }
3231            
3232             sub W2PGetMinCount
3233             {
3234             my ( $self ) = @_;
3235             return $self->GetWord2PhraseHandler()->GetMinCount();
3236             }
3237            
3238             sub W2PGetThreshold
3239             {
3240             my ( $self ) = @_;
3241             return $self->GetWord2PhraseHandler()->GetThreshold();
3242             }
3243            
3244             sub W2PGetW2PDebug
3245             {
3246             my ( $self ) = @_;
3247             return $self->GetWord2PhraseHandler()->GetW2PDebug();
3248             }
3249            
3250             sub W2PGetWorkingDir
3251             {
3252             my ( $self ) = @_;
3253             return $self->GetWord2PhraseHandler()->GetWorkingDir();
3254             }
3255            
3256             sub W2PGetWord2PhraseExeDir
3257             {
3258             my ( $self ) = @_;
3259             return $self->GetWord2PhraseHandler()->GetWord2PhraseExeDir();
3260             }
3261            
3262             sub W2PGetOverwriteOldFile
3263             {
3264             my ( $self ) = @_;
3265             return $self->GetWord2PhraseHandler()->GetOverwriteOldFile();
3266             }
3267            
3268             sub W2PSetTrainFilePath
3269             {
3270             my ( $self, $dir ) = @_;
3271             return $self->GetWord2PhraseHandler()->SetTrainFilePath( $dir );
3272             }
3273            
3274             sub W2PSetOutputFilePath
3275             {
3276             my ( $self, $dir ) = @_;
3277             return $self->GetWord2PhraseHandler()->SetOutputFilePath( $dir );
3278             }
3279            
3280             sub W2PSetMinCount
3281             {
3282             my ( $self, $value ) = @_;
3283             return $self->GetWord2PhraseHandler()->SetMinCount( $value );
3284             }
3285            
3286             sub W2PSetThreshold
3287             {
3288             my ( $self, $value ) = @_;
3289             return $self->GetWord2PhraseHandler()->SetThreshold( $value );
3290             }
3291            
3292             sub W2PSetW2PDebug
3293             {
3294             my ( $self, $value ) = @_;
3295             return $self->GetWord2PhraseHandler()->SetW2PDebug( $value );
3296             }
3297            
3298             sub W2PSetWorkingDir
3299             {
3300             my ( $self, $dir ) = @_;
3301             return $self->GetWord2PhraseHandler()->SetWorkingDir( $dir );
3302             }
3303            
3304             sub W2PSetWord2PhraseExeDir
3305             {
3306             my ( $self, $dir ) = @_;
3307             return $self->GetWord2PhraseHandler()->SetWord2PhraseExeDir( $dir );
3308             }
3309            
3310             sub W2PSetOverwriteOldFile
3311             {
3312             my ( $self, $value ) = @_;
3313             return $self->GetWord2PhraseHandler()->SetOverwriteOldFile( $value );
3314             }
3315            
3316            
3317             ######################################################################################
3318             # XMLToWW2V Module Functions
3319             ######################################################################################
3320            
3321             sub XTWConvertMedlineXMLToW2V
3322             {
3323             my ( $self ) = @_;
3324             $self->GetXMLToW2VHandler()->ConvertMedlineXMLToW2V();
3325             }
3326            
3327             sub XTWCreateCompoundWordBST
3328             {
3329             my ( $self ) = @_;
3330             $self->GetXMLToW2VHandler()->CreateCompoundWordBST();
3331             }
3332            
3333             sub XTWCompoundifyString
3334             {
3335             my ( $self, $str ) = @_;
3336             return $self->GetXMLToW2VHandler()->CompoundifyString( $str );
3337             }
3338            
3339             sub XTWReadCompoundWordDataFromFile
3340             {
3341             my ( $self, $fileDir, $autoSetMaxCompoundWordLength ) = @_;
3342             return $self->GetXMLToW2VHandler()->ReadCompoundWordDataFromFile( $fileDir, $autoSetMaxCompoundWordLength );
3343             }
3344            
3345             sub XTWSaveCompoundWordListToFile
3346             {
3347             my ( $self, $savePath ) = @_;
3348             return $self->GetXMLToW2VHandler()->SaveCompoundWordListToFile( $savePath );
3349             }
3350            
3351             sub XTWReadTextFromFile
3352             {
3353             my ( $self, $fileDir ) = @_;
3354             return $self->GetXMLToW2VHandler()->ReadTextFromFile( $fileDir );
3355             }
3356            
3357             sub XTWSaveTextToFile
3358             {
3359             my ( $self, $fileName, $str ) = @_;
3360             return $self->GetXMLToW2VHandler()->SaveTextToFile( $fileName, $str );
3361             }
3362            
3363             sub XTWReadXMLDataFromFile
3364             {
3365             my ( $self, $fileDir ) = @_;
3366             return $self->GetXMLToW2VHandler()->_ReadXMLDataFromFile( $fileDir );
3367             }
3368            
3369             sub XTWSaveTextCorpusToFile
3370             {
3371             my ( $self, $saveDir, $appendToFile ) = @_;
3372             return $self->GetXMLToW2VHandler()->_SaveTextCorpusToFile( $saveDir, $appendToFile );
3373             }
3374            
3375             sub XTWIsDateInSpecifiedRange
3376             {
3377             my ( $self, $date, $beginDate, $endDate ) = @_;
3378             return $self->GetXMLToW2VHandler()->IsDateInSpecifiedRange( $date, $beginDate, $endDate );
3379             }
3380            
3381             sub XTWIsFileOrDirectory
3382             {
3383             my ( $self, $path ) = @_;
3384             return $self->GetXMLToW2VHandler()->IsFileOrDirectory( $path );
3385             }
3386            
3387             sub XTWRemoveSpecialCharactersFromString
3388             {
3389             my ( $self, $str ) = @_;
3390             return $self->GetXMLToW2VHandler()->RemoveSpecialCharactersFromString( $str );
3391             }
3392            
3393             sub XTWGetFileType
3394             {
3395             my ( $self, $filePath ) = @_;
3396             return $self->GetXMLToW2VHandler()->GetFileType( $filePath );
3397             }
3398            
3399             sub XTWDateCheck
3400             {
3401             my ( $self ) = @_;
3402             return $self->GetXMLToW2VHandler()->_DateCheck();
3403             }
3404            
3405             sub XTWGetDebugLog
3406             {
3407             my ( $self ) = @_;
3408             return $self->GetXMLToW2VHandler()->GetDebugLog();
3409             }
3410            
3411             sub XTWGetWriteLog
3412             {
3413             my ( $self ) = @_;
3414             return $self->GetXMLToW2VHandler()->GetWriteLog();
3415             }
3416            
3417             sub XTWGetStoreTitle
3418             {
3419             my ( $self ) = @_;
3420             return $self->GetXMLToW2VHandler()->GetStoreTitle();
3421             }
3422            
3423             sub XTWGetStoreAbstract
3424             {
3425             my ( $self ) = @_;
3426             return $self->GetXMLToW2VHandler()->GetStoreAbstract();
3427             }
3428            
3429             sub XTWGetQuickParse
3430             {
3431             my ( $self ) = @_;
3432             return $self->GetXMLToW2VHandler()->GetQuickParse();
3433             }
3434            
3435             sub XTWGetCompoundifyText
3436             {
3437             my ( $self ) = @_;
3438             return $self->GetXMLToW2VHandler()->GetCompoundifyText();
3439             }
3440            
3441             sub XTWGetStoreAsSentencePerLine
3442             {
3443             my ( $self ) = @_;
3444             return $self->GetXMLToW2VHandler()->GetStoreAsSentencePerLine();
3445             }
3446            
3447             sub XTWGetNumOfThreads
3448             {
3449             my ( $self ) = @_;
3450             return $self->GetXMLToW2VHandler()->GetNumOfThreads();
3451             }
3452            
3453             sub XTWGetWorkingDir
3454             {
3455             my ( $self ) = @_;
3456             return $self->GetXMLToW2VHandler()->GetWorkingDir();
3457             }
3458            
3459             sub XTWGetSaveDir
3460             {
3461             my ( $self ) = @_;
3462             return $self->GetXMLToW2VHandler()->GetSaveDir();
3463             }
3464            
3465             sub XTWGetBeginDate
3466             {
3467             my ( $self ) = @_;
3468             return $self->GetXMLToW2VHandler()->GetBeginDate();
3469             }
3470            
3471             sub XTWGetEndDate
3472             {
3473             my ( $self ) = @_;
3474             return $self->GetXMLToW2VHandler()->GetEndDate();
3475             }
3476            
3477             sub XTWGetXMLStringToParse
3478             {
3479             my ( $self ) = @_;
3480             return $self->GetXMLToW2VHandler()->GetXMLStringToParse();
3481             }
3482            
3483             sub XTWGetTextCorpusStr
3484             {
3485             my ( $self ) = @_;
3486             return $self->GetXMLToW2VHandler()->GetTextCorpusStr();
3487             }
3488            
3489             sub XTWGetFileHandle
3490             {
3491             my ( $self ) = @_;
3492             return $self->GetXMLToW2VHandler()->GetFileHandle();
3493             }
3494            
3495             sub XTWGetTwigHandler
3496             {
3497             my ( $self ) = @_;
3498             return $self->GetXMLToW2VHandler()->GetTwigHandler();
3499             }
3500            
3501             sub XTWGetParsedCount
3502             {
3503             my ( $self ) = @_;
3504             return $self->GetXMLToW2VHandler()->GetParsedCount();
3505             }
3506            
3507             sub XTWGetTempStr
3508             {
3509             my ( $self ) = @_;
3510             return $self->GetXMLToW2VHandler()->GetTempStr();
3511             }
3512            
3513             sub XTWGetTempDate
3514             {
3515             my ( $self ) = @_;
3516             return $self->GetXMLToW2VHandler()->GetTempDate();
3517             }
3518            
3519             sub XTWGetOutputFileName
3520             {
3521             my ( $self ) = @_;
3522             return $self->GetXMLToW2VHandler()->GetOutputFilePath();
3523             }
3524            
3525             sub XTWGetCompoundWordAry
3526             {
3527             my ( $self ) = @_;
3528             return $self->GetXMLToW2VHandler()->GetCompoundWordAry();
3529             }
3530            
3531             sub XTWGetCompoundWordBST
3532             {
3533             my ( $self ) = @_;
3534             return $self->GetXMLToW2VHandler()->GetCompoundWordBST();
3535             }
3536            
3537             sub XTWGetMaxCompoundWordLength
3538             {
3539             my ( $self ) = @_;
3540             return $self->GetXMLToW2VHandler()->GetMaxCompoundWordLength();
3541             }
3542            
3543             sub XTWSetStoreTitle
3544             {
3545             my ( $self, $value ) = @_;
3546             return $self->GetXMLToW2VHandler()->SetStoreTitle( $value );
3547             }
3548            
3549             sub XTWSetStoreAbstract
3550             {
3551             my ( $self, $value ) = @_;
3552             return $self->GetXMLToW2VHandler()->SetStoreAbstract( $value );
3553             }
3554            
3555             sub XTWSetWorkingDir
3556             {
3557             my ( $self, $dir ) = @_;
3558             return $self->GetXMLToW2VHandler()->SetWorkingDir( $dir );
3559             }
3560            
3561             sub XTWSetSavePath
3562             {
3563             my ( $self, $dir ) = @_;
3564             return $self->GetXMLToW2VHandler()->SetSavePath( $dir );
3565             }
3566            
3567             sub XTWSetQuickParse
3568             {
3569             my ( $self, $value ) = @_;
3570             return $self->GetXMLToW2VHandler()->SetQuickParse( $value );
3571             }
3572            
3573             sub XTWSetCompoundifyText
3574             {
3575             my ( $self, $value ) = @_;
3576             return $self->GetXMLToW2VHandler()->SetCompoundifyText( $value );
3577             }
3578            
3579             sub XTWSetStoreAsSentencePerLine
3580             {
3581             my ( $self, $value ) = @_;
3582             return $self->GetXMLToW2VHandler()->SetStoreAsSentencePerLine( $value );
3583             }
3584            
3585             sub XTWSetBeginDate
3586             {
3587             my ( $self, $str ) = @_;
3588             return $self->GetXMLToW2VHandler()->SetBeginDate( $str );
3589             }
3590            
3591             sub XTWSetEndDate
3592             {
3593             my ( $self, $str ) = @_;
3594             return $self->GetXMLToW2VHandler()->SetEndDate( $str );
3595             }
3596            
3597             sub XTWSetXMLStringToParse
3598             {
3599             my ( $self, $str ) = @_;
3600             return $self->GetXMLToW2VHandler()->SetXMLStringToParse( $str );
3601             }
3602            
3603             sub XTWSetTextCorpusStr
3604             {
3605             my ( $self, $str ) = @_;
3606             return $self->GetXMLToW2VHandler()->SetTextCorpusStr( $str );
3607             }
3608            
3609             sub XTWAppendStrToTextCorpus
3610             {
3611             my ( $self, $str ) = @_;
3612             return $self->GetXMLToW2VHandler()->AppendStrToTextCorpus( $str );
3613             }
3614            
3615             sub XTWClearTextCorpusStr
3616             {
3617             my ( $self, $value ) = @_;
3618             return $self->GetXMLToW2VHandler()->ClearTextCorpusStr();
3619             }
3620            
3621             sub XTWSetTempStr
3622             {
3623             my ( $self, $str ) = @_;
3624             return $self->GetXMLToW2VHandler()->SetTempStr( $str );
3625             }
3626            
3627             sub XTWAppendToTempStr
3628             {
3629             my ( $self, $str ) = @_;
3630             return $self->GetXMLToW2VHandler()->AppendToTempStr( $str );
3631             }
3632            
3633             sub XTWClearTempStr
3634             {
3635             my ( $self, $value ) = @_;
3636             return $self->GetXMLToW2VHandler()->ClearTempStr();
3637             }
3638            
3639             sub XTWSetTempDate
3640             {
3641             my ( $self, $str ) = @_;
3642             return $self->GetXMLToW2VHandler()->SetTempDate( $str );
3643             }
3644            
3645             sub XTWClearTempDate
3646             {
3647             my ( $self ) = @_;
3648             return $self->GetXMLToW2VHandler()->ClearTempDate();
3649             }
3650            
3651             sub XTWSetCompoundWordAry
3652             {
3653             my ( $self, $aryRef ) = @_;
3654             return $self->GetXMLToW2VHandler()->SetCompoundWordAry( $aryRef );
3655             }
3656            
3657             sub XTWClearCompoundWordAry
3658             {
3659             my ( $self, $str ) = @_;
3660             return $self->GetXMLToW2VHandler()->ClearCompoundWordAry();
3661             }
3662            
3663             sub XTWSetCompoundWordBST
3664             {
3665             my ( $self, $bst ) = @_;
3666             return $self->GetXMLToW2VHandler()->SetCompoundWordBST( $bst );
3667             }
3668            
3669             sub XTWClearCompoundWordBST
3670             {
3671             my ( $self, $str ) = @_;
3672             return $self->GetXMLToW2VHandler()->ClearCompoundWordBST();
3673             }
3674            
3675             sub XTWSetMaxCompoundWordLength
3676             {
3677             my ( $self, $value ) = @_;
3678             return $self->GetXMLToW2VHandler()->SetMaxCompoundWordLength( $value );
3679             }
3680            
3681             sub XTWSetOverwriteExistingFile
3682             {
3683             my ( $self, $value ) = @_;
3684             return $self->GetXMLToW2VHandler()->SetOverwriteExistingFile( $value );
3685             }
3686            
3687             #################### All Modules Are To Output "1"(True) at EOF ######################
3688             1;
3689            
3690            
3691             =head1 NAME
3692            
3693             Word2vec::Interface - Interface module for word2vec.pm, word2phrase.pm, interface.pm modules and associated utilities.
3694            
3695             =head1 SYNOPSIS
3696            
3697             use Word2vec::Interface;
3698            
3699             my $result = 0;
3700            
3701             # Compile a text corpus, execute word2vec training and compute cosine similarity of two words
3702             my $w2vinterface = Word2vec::Interface->new();
3703            
3704             my $xmlconv = $w2vinterface->GetXMLToW2VHandler();
3705             $xmlconv->SetWorkingDir( "Medline/XML/Directory/Here" );
3706             $xmlconv->SetSavePath( "textcorpus.txt" );
3707             $xmlconv->SetStoreTitle( 1 );
3708             $xmlconv->SetStoreAbstract( 1 );
3709             $xmlconv->SetBeginDate( "01/01/2004" );
3710             $xmlconv->SetEndDate( "08/13/2016" );
3711             $xmlconv->SetOverwriteExistingFile( 1 );
3712            
3713             # If Compound Word File Exists, Store It In Memory
3714             # And Create Compound Word Binary Search Tree Using The Compound Word Data
3715             $xmlconv->ReadCompoundWordDataFromFile( "compoundword.txt" );
3716             $xmlconv->CreateCompoundWordBST();
3717            
3718             # Parse XML Files or Directory Of Files
3719             $result = $xmlconv->ConvertMedlineXMLToW2V( "/xmlDirectory/" );
3720            
3721             # Check(s)
3722             print( "Error Parsing Medline XML Files\n" ) if ( $result == -1 );
3723             exit if ( $result == -1 );
3724            
3725             # Setup And Execute word2vec Training
3726             my $word2vec = $w2vinterface->GetWord2VecHandler();
3727             $word2vec->SetTrainFilePath( "textcorpus.txt" );
3728             $word2vec->SetOutputFilePath( "vectors.bin" );
3729             $word2vec->SetWordVecSize( 200 );
3730             $word2vec->SetWindowSize( 8 );
3731             $word2vec->SetSample( 0.0001 );
3732             $word2vec->SetNegative( 25 );
3733             $word2vec->SetHSoftMax( 0 );
3734             $word2vec->SetBinaryOutput( 0 );
3735             $word2vec->SetNumOfThreads( 20 );
3736             $word2vec->SetNumOfIterations( 12 );
3737             $word2vec->SetUseCBOW( 1 );
3738             $word2vec->SetOverwriteOldFile( 0 );
3739            
3740             # Execute word2vec Training
3741             $result = $word2vec->ExecuteTraining();
3742            
3743             # Check(s)
3744             print( "Error Training Word2vec On File: \"textcorpus.txt\"" ) if ( $result == -1 );
3745             exit if ( $result == -1 );
3746            
3747             # Read word2vec Training Data Into Memory And Store As A Binary Search Tree
3748             $result = $word2vec->ReadTrainedVectorDataFromFile( "vectors.bin" );
3749            
3750             # Check(s)
3751             print( "Error Unable To Read Word2vec Trained Vector Data From File\n" ) if ( $result == -1 );
3752             exit if ( $result == -1 );
3753            
3754             # Compute Cosine Similarity Between "respiratory" and "arrest"
3755             $result = $word2vec->ComputeCosineSimilarity( "respiratory", "arrest" );
3756             print( "Cosine Similarity Between \"respiratory\" and \"arrest\": $result\n" ) if defined( $result );
3757             print( "Error Computing Cosine Similarity\n" ) if !defined( $result );
3758            
3759             # Compute Cosine Similarity Between "respiratory arrest" and "heart attack"
3760             $result = $word2vec->ComputeMultiWordCosineSimilarity( "respiratory arrest", "heart attack" );
3761             print( "Cosine Similarity Between \"respiratory arrest\" and \"heart attack\": $result\n" ) if defined( $result );
3762             print( "Error Computing Cosine Similarity\n" ) if !defined( $result );
3763            
3764             undef( $w2vinterface );
3765            
3766             # or
3767            
3768             use Word2vec::Interface;
3769            
3770             my $result = 0;
3771             my $w2vinterface = Word2vec::Interface->new();
3772             $w2vinterface->XTWSetWorkingDir( "Medline/XML/Directory/Here" );
3773             $w2vinterface->XTWSetSavePath( "textcorpus.txt" );
3774             $w2vinterface->XTWSetStoreTitle( 1 );
3775             $w2vinterface->XTWSetStoreAbstract( 1 );
3776             $w2vinterface->XTWSetBeginDate( "01/01/2004" );
3777             $w2vinterface->XTWSetEndDate( "08/13/2016" );
3778             $w2vinterface->XTWSetOverwriteExistingFile( 1 );
3779            
3780             # If Compound Word File Exists, Store It In Memory
3781             # And Create Compound Word Binary Search Tree Using The Compound Word Data
3782             $w2vinterface->XTWReadCompoundWordDataFromFile( "compoundword.txt" );
3783             $w2vinterface->XTWCreateCompoundWordBST();
3784            
3785             # Parse XML Files or Directory Of Files
3786             $result = $w2vinterface->XTWConvertMedlineXMLToW2V( "/xmlDirectory/" );
3787            
3788             $result = $w2vinterface->W2VExecuteTraining( "textcorpus.txt", "vectors.bin", 200, 8, undef, 0.001, 25,
3789             undef, 0, 0, 20, 15, 1, 0, undef, undef, undef, 1 );
3790            
3791             # Read word2vec Training Data Into Memory And Store As A Binary Search Tree
3792             $result = $w2vinterface->W2VReadTrainedVectorDataFromFile( "vectors.bin" );
3793            
3794             # Check(s)
3795             print( "Error Unable To Read Word2vec Trained Vector Data From File\n" ) if ( $result == -1 );
3796             exit if ( $result == -1 );
3797            
3798             # Compute Cosine Similarity Between "respiratory" and "arrest"
3799             $result = $w2vinterface->W2VComputeCosineSimilarity( "respiratory", "arrest" );
3800             print( "Cosine Similarity Between \"respiratory\" and \"arrest\": $result\n" ) if defined( $result );
3801             print( "Error Computing Cosine Similarity\n" ) if !defined( $result );
3802            
3803             # Compute Cosine Similarity Between "respiratory arrest" and "heart attack"
3804             $result = $w2vinterface->W2VComputeMultiWordCosineSimilarity( "respiratory arrest", "heart attack" );
3805             print( "Cosine Similarity Between \"respiratory arrest\" and \"heart attack\": $result\n" ) if defined( $result );
3806             print( "Error Computing Cosine Similarity\n" ) if !defined( $result );
3807            
3808             undef( $w2vinterface );
3809            
3810             =head1 DESCRIPTION
3811            
3812             Word2vec::Interface is an interface module for utilization of word2vec, word2phrase, xmltow2v and their associated functions.
3813             This program houses a set of functions, modules and utilities for use with UMLS Similarity.
3814            
3815             XmlToW2v Features:
3816             - Compilation of a text corpus from plain or gun-zipped Medline XML files.
3817             - Multi-threaded text corpus compilation support.
3818             - Include text corpus articles via date range.
3819             - Include text corpus articles via title, abstract or both.
3820             - Compoundifying on-the-fly while building text corpus given a compound word file.
3821            
3822             Word2vec Features:
3823             - Word2vec training with user specified settings.
3824             - Manipulation of Word2vec word vectors. (Addition/Subtraction/Average)
3825             - Word2vec binary format to plain text file conversion.
3826             - Word2vec plain text to binary format file conversion.
3827             - Multi-word cosine similarity computation. (Sudo-compound word cosine similarity).
3828            
3829             Word2phrase Features:
3830             - Word2phrase training with user specified settings.
3831            
3832             Interface Features:
3833             - Word Sense Disambiguation via trained word2vec data.
3834            
3835             =head2 Interface Main Functions
3836            
3837             =head3 new
3838            
3839             Description:
3840            
3841             Returns a new "Word2vec::Interface" module object.
3842            
3843             Note: Specifying no parameters implies default options.
3844            
3845             Default Parameters:
3846             word2vecDir = "../../External/word2vec"
3847             debugLog = 0
3848             writeLog = 0
3849             ignoreCompileErrors = 0
3850             ignoreFileChecks = 0
3851             exitFlag = 0
3852             workingDir = ""
3853             word2vec = Word2vec::Word2vec->new()
3854             word2phrase = Word2vec::Word2phrase->new()
3855             xmltow2v = Word2vec::Xmltow2v->new()
3856             util = Word2vec::Interface()
3857             instanceAry = ()
3858             senseAry = ()
3859             instanceCount = 0
3860             senseCount = 0
3861            
3862            
3863             Input:
3864            
3865             $word2vecDir -> Specifies word2vec package source/executable directory.
3866             $debugLog -> Instructs module to print debug statements to the console. ('1' = True / '0' = False)
3867             $writeLog -> Instructs module to print debug statements to a log file. ('1' = True / '0' = False)
3868             $ignoreCompileErrors -> Instructs module to ignore source code compilation errors. ('1' = True / '0' = False)
3869             $ignoreFileChecks -> Instructs module to ignore file checks. ('1' = True / '0' = False)
3870             $exitFlag -> In the event of a run-time check error, exitFlag is set to '1' which gracefully terminates the script.
3871             $workingDir -> Specifies the current working directory.
3872             $word2vec -> Word2vec::Word2vec object.
3873             $word2phrase -> Word2vec::Word2phrase object.
3874             $xmltow2v -> Word2vec::Xmltow2v object.
3875             $interface -> Word2vec::Interface object.
3876             $instanceAry -> Word Sense Disambiguation: Array of instances.
3877             $senseAry -> Word Sense Disambiguation: Array of senses.
3878             $instanceCount -> Number of Word Sense Disambiguation instances loaded in memory.
3879             $senseCount -> Number of Word Sense Disambiguation senses loaded in memory.
3880            
3881             Note: It is not recommended to specify all new() parameters, as it has not been thoroughly tested. Maximum recommended parameters to be specified include:
3882             "word2vecDir, debugLog, writeLog, ignoreCompileErrors, ignoreFileChecks"
3883            
3884             Output:
3885            
3886             Word2vec::Interface object.
3887            
3888             Example:
3889            
3890             use Word2vec::Interface;
3891            
3892             # Parameters: Word2Vec Directory = undef, DebugLog = True, WriteLog = False, IgnoreCompileErrors = False, IgnoreFileChecks = False
3893             my $interface = Word2vec::Interface->new( undef, 1, 0 );
3894            
3895             undef( $interface );
3896            
3897             # Or
3898            
3899             # Parameters: Word2Vec Directory = undef, DebugLog = False, WriteLog = False, IgnoreCompileErrors = False, IgnoreFileChecks = False
3900             use Word2vec::Interface;
3901            
3902             my $interface = Word2vec::Interface->new();
3903            
3904             undef( $interface );
3905            
3906             =head3 DESTROY
3907            
3908             Description:
3909            
3910             Removes member variables and file handle from memory.
3911            
3912             Input:
3913            
3914             None
3915            
3916             Output:
3917            
3918             None
3919            
3920             Example:
3921            
3922             use Word2vec::Interface;
3923            
3924             my $interface = Word2vec::Interface->new();
3925             $interface->DESTROY();
3926            
3927             undef( $interface );
3928            
3929             =head3 RunFileChecks
3930            
3931             Description:
3932            
3933             Runs word2vec file checks. Looks for word2vec executable files, if not found
3934             it will then look for the source code and compile automatically placing the
3935             executable files in the same directory. Errors out gracefully when word2vec
3936             executable files are not present and source files cannot be located.
3937            
3938             Notes : Word2vec Executable File List: word2vec, word2phrase, word-analogy, distance, compute-accuracy.
3939            
3940             : This method is called automatically in interface::new() function. It can be disabled by setting
3941             _ignoreFileChecks new() parameter to 1.
3942            
3943             Input:
3944            
3945             $string -> Word2vec source/executable directory.
3946            
3947             Output:
3948            
3949             $value -> Returns '1' if checks passed and '0' if file checks failed.
3950            
3951             Example:
3952            
3953             use Word2vec::Interface;
3954            
3955             my $interface = Word2vec::Interface->new( undef, 1, 0, 1, 1 );
3956             my $result = $interface->RunFileChecks();
3957            
3958             print( "Passed Word2Vec File Checks!\n" ) if $result == 0;
3959             print( "Failed Word2Vec File Checks!\n" ) if $result == 1;
3960            
3961             undef( $interface );
3962            
3963             =head3 _CheckIfExecutableFileExists
3964            
3965             Description:
3966            
3967             Checks specified executable file exists in a given directory.
3968            
3969             Input:
3970            
3971             $filePath -> Executable file path
3972             $fileName -> Executable file name
3973            
3974             Output:
3975            
3976             $value -> Returns '1' if file is found and '0' if otherwise.
3977            
3978             Example:
3979            
3980             use Word2vec::Interface;
3981            
3982             my $interface = Word2vec::Interface->new();
3983             my $result = $interface->_CheckIfExecutableFileExists( "../../External/word2vec", "word2vec" );
3984            
3985             print( "Executable File Exists!\n" ) if $result == 1;
3986             print( "Executable File Does Not Exist!\n" ) if $result == 0;
3987            
3988             undef( $interface );
3989            
3990             =head3 _CheckIfSourceFileExists
3991            
3992             Description:
3993            
3994             Checks specified directory (string) for the filename (string).
3995             This ensures the specified files are of file type "text/cpp".
3996            
3997             Input:
3998            
3999             $filePath -> Executable file path
4000             $fileName -> Executable file name
4001            
4002             Output:
4003            
4004             $value -> Returns '1' if file is found and of type "text/cpp" and '0' if otherwise.
4005            
4006             Example:
4007            
4008             use Word2vec::Interface;
4009            
4010             my $interface = Word2vec::Interface->new();
4011             my $result = $interface->_CheckIfSourceFileExists( "../../External/word2vec", "word2vec" );
4012            
4013             print( "Source File Exists!\n" ) if $result == 1;
4014             print( "Source File Does Not Exist!\n" ) if $result == 0;
4015            
4016             undef( $interface );
4017            
4018             =head3 _CompileSourceFile
4019            
4020             Description:
4021            
4022             Compiles C++ source filename in a specified directory.
4023            
4024             Input:
4025            
4026             $filePath -> Source file path (string)
4027             $fileName -> Source file name (string)
4028            
4029             Output:
4030            
4031             $value -> Returns '1' if successful and '0' if un-successful.
4032            
4033             Example:
4034            
4035             use Word2vec::Interface;
4036            
4037             my $interface = Word2vec::Interface;
4038             my $result = $interface->_CompileSourceFile( "../../External/word2vec", "word2vec" );
4039            
4040             print( "Compiled Source Successfully!\n" ) if $result == 1;
4041             print( "Source Compilation Attempt Unsuccessful!\n" ) if $result == 0;
4042            
4043             undef( $interface );
4044            
4045             =head3 GetFileType
4046            
4047             Description:
4048            
4049             Checks file in given file path and if it exists, returns the file type.
4050            
4051             Input:
4052            
4053             $filePath -> File path
4054            
4055             Output:
4056            
4057             $string -> Returns file type (string).
4058            
4059             Example:
4060            
4061             use Word2vec::Interface;
4062            
4063             my $interface = Word2vec::Interface->new();
4064             my $fileType = $interface->GetFileType( "samples/textcorpus.txt" );
4065            
4066             print( "File Type: $fileType\n" );
4067            
4068             undef( $interface );
4069            
4070             =head3 GetOSType
4071            
4072             Description:
4073            
4074             Returns current operating system (string).
4075            
4076             Input:
4077            
4078             None
4079            
4080             Output:
4081            
4082             $string -> Operating System Type. (String)
4083            
4084             Example:
4085            
4086             use Word2vec::Interface;
4087            
4088             my $interface = Word2vec::Interface->new();
4089             my $os = $interface->GetOSType();
4090            
4091             print( "Operating System: $os\n" );
4092            
4093             undef( $interface );
4094            
4095             =head3 _ModifyWord2VecSourceForWindows
4096            
4097             Description:
4098            
4099             Modifies "word2vec.c" file for compilation under windows operating system.
4100            
4101             Input:
4102            
4103             None
4104            
4105             Output:
4106            
4107             $value -> '1' = Successful / '0' = Un-successful
4108            
4109             Example:
4110            
4111             This is a private function and should not be utilized.
4112            
4113             =head3 _RemoveWord2VecSourceModification
4114            
4115             Description:
4116            
4117             Removes modification of "word2vec.c". Returns source file to its original state.
4118            
4119             Input:
4120            
4121             None
4122            
4123             Output:
4124            
4125             $value -> '1' = Successful / '0' = Un-successful.
4126            
4127             Example:
4128            
4129             This is a private function and should not be utilized.
4130            
4131             =head2 Interface Command-Line Functions
4132            
4133             =head3 CLComputeCosineSimilarity
4134            
4135             Description:
4136            
4137             Command-line Method: Computes cosine similarity between 'wordA' and 'wordB' using the specified 'filePath' for
4138             loading trained word2vec word vector data.
4139            
4140             Input:
4141            
4142             $filePath -> Word2Vec trained word vectors binary file path. (String)
4143             $wordA -> First word for cosine similarity comparison.
4144             $wordB -> Second word for cosine similarity comparison.
4145            
4146             Output:
4147            
4148             $value -> Cosine similarity value (float) or undefined.
4149            
4150             Example:
4151            
4152             use Word2vec::Interface;
4153            
4154             my $interface = Word2vec::Interface->new();
4155             my $value = $interface->CLComputeCosineSimilarity( "../../samples/samplevectors.bin", "of", "the" );
4156             print( "Cosine Similarity Between \"of\" and \"the\": $value\n" ) if defined( $value );
4157             print( "Error: Cosine Similarity Could Not Be Computed\n" ) if !defined( $value );
4158            
4159             undef( $interface );
4160            
4161             =head3 CLComputeMultiWordCosineSimilarity
4162            
4163             Description:
4164            
4165             Command-line Method: Computes cosine similarity between 'phraseA' and 'phraseB' using the specified 'filePath'
4166             for loading trained word2vec word vector data.
4167            
4168             Note: Supports multiple words concatenated by ':' for each string.
4169            
4170             Input:
4171            
4172             $filePath -> Word2Vec trained word vectors binary file path. (String)
4173             $phraseA -> First phrase for cosine similarity comparison. (String)
4174             $phraseB -> Second phrase for cosine similarity comparison. (String)
4175            
4176             Output:
4177            
4178             $value -> Cosine similarity value (float) or undefined.
4179            
4180             Example:
4181            
4182             use Word2vec::Interface;
4183            
4184             my $interface = Word2vec::Interface->new();
4185             my $value = $interface->CLComputeMultiWordCosineSimilarity( "../../samples/samplevectors.bin", "heart:attack", "myocardial:infarction" );
4186             print( "Cosine Similarity Between \"heart attack\" and \"myocardial infarction\": $value\n" ) if defined( $value );
4187             print( "Error: Cosine Similarity Could Not Be Computed\n" ) if !defined( $value );
4188            
4189             undef( $instance );
4190            
4191             =head3 CLComputeAvgOfWordsCosineSimilarity
4192            
4193             Description:
4194            
4195             Command-line Method: Computes cosine similarity average of all words in 'phraseA' and 'phraseB',
4196             then takes cosine similarity between 'phraseA' and 'phraseB' average values using the
4197             specified 'filePath' for loading trained word2vec word vector data.
4198            
4199             Note: Supports multiple words concatenated by ':' for each string.
4200            
4201             Input:
4202            
4203             $filePath -> Word2Vec trained word vectors binary file path. (String)
4204             $phraseA -> First phrase for cosine similarity comparison.
4205             $phraseB -> Second phrase for cosine similarity comparison.
4206            
4207             Output:
4208            
4209             $value -> Cosine similarity value (float) or undefined.
4210            
4211             Example:
4212            
4213             use Word2vec::Interface;
4214            
4215             my $interface = Word2vec::Interface->new();
4216             my $value = $interface->CLComputeAvgOfWordsCosineSimilarity( "../../samples/samplevectors.bin", "heart:attack", "myocardial:infarction" );
4217             print( "Cosine Similarity Between \"heart attack\" and \"myocardial infarction\": $value\n" ) if defined( $value );
4218             print( "Error: Cosine Similarity Could Not Be Computed\n" ) if !defined( $value );
4219            
4220             undef( $instance );
4221            
4222             =head3 CLMultiWordCosSimWithUserInput
4223            
4224             Description:
4225            
4226             Command-line Method: Computes cosine similarity depending on user input given a vectorBinaryFile (string).
4227            
4228             Note: Words can be compounded by the ':' character.
4229            
4230             Input:
4231            
4232             $filePath -> Word2Vec trained word vectors binary file path. (String)
4233            
4234             Output:
4235            
4236             None
4237            
4238             Example:
4239            
4240             use Word2vec::Interface;
4241            
4242             my $interface = Word2vec::Interface->new();
4243             $interface->CLMultiWordCosSimWithUserInput( "../../samples/samplevectors.bin" );
4244            
4245             undef( $instance );
4246            
4247             =head3 CLAddTwoWordVectors
4248            
4249             Description:
4250            
4251             Command-line Method: Loads the specified word2vec trained binary data file, adds word vectors and returns the summed result.
4252            
4253             Input:
4254            
4255             $filePath -> Word2Vec trained word vectors binary file path. (String)
4256             $wordDataA -> Word2Vec word data (String)
4257             $wordDataB -> Word2Vec word data (String)
4258            
4259             Output:
4260            
4261             $vectorData -> Summed '$wordDataA' and '$wordDataB' vectors
4262            
4263             Example:
4264            
4265             use Word2vec::Interface;
4266            
4267             my $interface = Word2vec::Interface->new();
4268             my $wordVtr = $interface->CLAddTwoWordVectors( "../../samples/samplevectors.bin", "of", "the" );
4269            
4270             print( "Word Vector for \"of\" + \"the\": $wordVtr\n" ) if defined( $wordVtr );
4271             print( "Word Vector Cannot Be Computed\n" ) if !defined( $wordVtr );
4272            
4273             undef( $instance );
4274            
4275             =head3 CLSubtractTwoWordVectors
4276            
4277             Description:
4278            
4279             Command-line Method: Loads the specified word2vec trained binary data file, subtracts word vectors and returns the difference result.
4280            
4281             Input:
4282            
4283             $filePath -> Word2Vec trained word vectors binary file path. (String)
4284             $wordDataA -> Word2Vec word data (String)
4285             $wordDataB -> Word2Vec word data (String)
4286            
4287             Output:
4288            
4289             $vectorData -> Difference of '$wordDataA' and '$wordDataB' vectors
4290            
4291             Example:
4292            
4293             use Word2vec::Interface;
4294            
4295             my $interface = Word2vec::Interface->new();
4296             my $wordVtr = $interface->CLSubtractTwoWordVectors( "../../samples/samplevectors.bin", "of", "the" );
4297            
4298             print( "Word Vector for \"of\" - \"the\": $wordVtr\n" ) if defined( $wordVtr );
4299             print( "Word Vector Cannot Be Computed\n" ) if !defined( $wordVtr );
4300            
4301             undef( $instance );
4302            
4303             =head3 CLStartWord2VecTraining
4304            
4305             Description:
4306            
4307             Command-line Method: Executes word2vec training given the specified options hash.
4308            
4309             Input:
4310            
4311             $hashRef -> Hash reference of word2vec options
4312            
4313             Output:
4314            
4315             $value -> Returns '0' = Successful / '-1' = Un-successful.
4316            
4317             Example:
4318            
4319             use Word2vec::Interface;
4320            
4321             my %options;
4322             $options{'-trainfile'} = "../../samples/textcorpus.txt";
4323             $options{'-outputfile'} = "../../samples/tempvectors.bin";
4324            
4325             my $interface = Word2vec::Interface->new();
4326             my $result = $interface->CLStartWord2VecTraining( \%options );
4327            
4328             print( "Success!\n" ) if $result == 0;
4329             print( "Failed!\n" ) if $result == -1;
4330            
4331             undef( $interface );
4332            
4333             =head3 CLStartWord2PhraseTraining
4334            
4335             Description:
4336            
4337             Command-line Method: Executes word2phrase training given the specified options hash.
4338            
4339             Input:
4340            
4341             $hashRef -> Hash reference of word2vec options.
4342            
4343             Output:
4344            
4345             $value -> Returns '0' = Successful / '-1' = Un-successful.
4346            
4347             Example:
4348            
4349             use Word2vec::Interface;
4350            
4351             my %options;
4352             $options{'-trainfile'} = "../../samples/textcorpus.txt";
4353             $options{'-outputfile'} = "../../samples/tempvectors.bin";
4354            
4355             my $interface = Word2vec::Interface->new();
4356             my $result = $interface->CLStartWord2PhraseTraining( \%options );
4357            
4358             print( "Success!\n" ) if $result == 0;
4359             print( "Failed!\n" ) if $result == -1;
4360            
4361             undef( $interface );
4362            
4363             =head3 CLCompileTextCorpus
4364            
4365             Description:
4366            
4367             Command-line Method: Compiles a text corpus given the specified options hash.
4368            
4369             Input:
4370            
4371             $hashRef -> Hash reference of xmltow2v options.
4372            
4373             Output:
4374            
4375             $value -> Returns '0' = Successful / '-1' = Un-successful.
4376            
4377             Example:
4378            
4379             use Word2vec::Interface;
4380            
4381             my %options;
4382             $options{'-workdir'} = "../../samples";
4383             $options{'-savedir'} = "../../samples/textcorpus.txt";
4384            
4385             my $interface = Word2vec::Interface->new();
4386             my $result = $interface->CLCompileTextCorpus( \%options );
4387            
4388             print( "Success!\n" ) if $result == 0;
4389             print( "Failed!\n" ) if $result == -1;
4390            
4391             undef( $interface );
4392            
4393             =head3 CLConvertWord2VecVectorFileToText
4394            
4395             Description:
4396            
4397             Command-line Method: Converts conversion of word2vec binary format to plain text word vector data.
4398            
4399             Input:
4400            
4401             $filePath -> Word2Vec binary file path
4402             $savePath -> Path to save converted file
4403            
4404             Output:
4405            
4406             $value -> '0' = Successful / '-1' = Un-successful
4407            
4408             Example:
4409            
4410             use Word2vec::Interface;
4411            
4412             my $interface = Word2vec::Interface->new();
4413             my $result = $interface->CLConvertWord2VecVectorFileToText( "../../samples/samplevectors.bin", "../../samples/convertedvectors.bin" );
4414            
4415             print( "Success!\n" ) if $result == 0;
4416             print( "Failed!\n" ) if $result == -1;
4417            
4418             undef( $interface );
4419            
4420             =head3 CLConvertWord2VecVectorFileToBinary
4421            
4422             Description:
4423            
4424             Command-line Method: Converts conversion of plain text word vector data to word2vec binary format.
4425            
4426             Input:
4427            
4428             $filePath -> Word2Vec binary file path
4429             $savePath -> Path to save converted file
4430            
4431             Output:
4432            
4433             $value -> '0' = Successful / '-1' = Un-successful
4434            
4435             Example:
4436            
4437             use Word2vec::Interface;
4438            
4439             my $interface = Word2vec::Interface->new();
4440             my $result = $interface->CLConvertWord2VecVectorFileToBinary( "../../samples/samplevectors.bin", "../../samples/convertedvectors.bin" );
4441            
4442             print( "Success!\n" ) if $result == 0;
4443             print( "Failed!\n" ) if $result == -1;
4444            
4445             undef( $interface );
4446            
4447             =head3 CLConvertWord2VecVectorFileToSparse
4448            
4449             Description:
4450            
4451             Command-line Method: Converts conversion of plain text word vector data to sparse vector data format.
4452            
4453             Input:
4454            
4455             $filePath -> Vectors file path
4456             $savePath -> Path to save converted file
4457            
4458             Output:
4459            
4460             $value -> '0' = Successful / '-1' = Un-successful
4461            
4462             Example:
4463            
4464             use Word2vec::Interface;
4465            
4466             my $interface = Word2vec::Interface->new();
4467             my $result = $interface->CLConvertWord2VecVectorFileToSparse( "../../samples/samplevectors.bin", "../../samples/convertedvectors.bin" );
4468            
4469             print( "Success!\n" ) if $result == 0;
4470             print( "Failed!\n" ) if $result == -1;
4471            
4472             undef( $interface );
4473            
4474             =head3 CLCompoundifyTextInFile
4475            
4476             Description:
4477            
4478             Command-line Method: Reads a specified plain text file at 'filePath' and 'compoundWordFile', then compoundifies and saves the file to 'savePath'.
4479            
4480             Input:
4481            
4482             $filePath -> Text file to compoundify
4483             $savePath -> Path to save compoundified file
4484             $compoundWordFile -> Compound word file path
4485            
4486             Output:
4487            
4488             $value -> Result '0' = Successful / '-1' = Un-successful
4489            
4490             Example:
4491            
4492             use Word2vec::Interface;
4493            
4494             my $interface = Word2vec::Interface->new();
4495             my $result = $interface->CLCompoundifyTextInFile( "../../samples/textcorpus.txt", "../../samples/compoundcorpus.txt", "../../samples/compoundword.txt" );
4496            
4497             print( "Success!\n" ) if $result == 0;
4498             print( "Failed!\n" ) if $result == -1;
4499            
4500             undef( $interface );
4501            
4502             =head3 CLSortVectorFile
4503            
4504             Description:
4505            
4506             Reads a specifed vector file in memory, sorts alphanumerically and saves to a file.
4507            
4508             Input:
4509            
4510             $hashRef -> Hash reference of parameters. (File path and overwrite parameters)
4511            
4512             Output:
4513            
4514             $value -> Result '0' = Successful / '-1' = Un-successful
4515            
4516             Example:
4517            
4518             use Word2vec::Interface;
4519            
4520             my $interface = Word2vec::Interface->new();
4521            
4522             my %options;
4523             %options{ "-filepath" } = "vectors.bin";
4524             %options{ "-overwrite" } = 1;
4525            
4526             my $result = $interface->CLSortVectorFile();
4527            
4528             print( "Success!\n" ) if $result == 0;
4529             print( "Failed!\n" ) if $result == -1;
4530            
4531             undef( $interface );
4532            
4533             =head3 CLFindSimilarTerms
4534            
4535             Description:
4536            
4537             Fetches an array containing the nearest n terms using cosine similarity as the metric of determining similar terms.
4538            
4539             Input:
4540            
4541             $term -> Comparison term used to find similar terms.
4542             $numberOfSimilarTerms -> Integer value used to limit the number of elements in array returned.
4543            
4544             Output:
4545            
4546             $value -> 'Array reference' = Successful / 'undef' = Un-successful
4547            
4548             Example:
4549            
4550             use Word2vec::Interface;
4551            
4552             my $interface = Word2vec::Interface->new();
4553             my $result = $interface->W2VReadTrainedVectorDataFromFile( "vectors.bin" );
4554             $result = $interface->CLFindSimilarTerms( "cookie", 10 ) if $result == 0;
4555            
4556             print "Success\n" if defined( $result );
4557             print "Error: No Elements Returned\n" if !defined( $result );
4558             return if !defined( $result );
4559            
4560             for my $element ( @{ $result } )
4561             {
4562             print "$element\n";
4563             }
4564            
4565             undef( $interface );
4566            
4567             =head3 CleanWord2VecDirectory
4568            
4569             Description:
4570            
4571             Cleans up C object and executable files in word2vec directory.
4572            
4573             Input:
4574            
4575             None
4576            
4577             Output:
4578            
4579             $value -> Result '0' = Successful / '-1' = Un-successful
4580            
4581             Example:
4582            
4583             use Word2vec::Interface;
4584            
4585             my $interface = Word2vec::Interface->new();
4586             my $result = $interface->CleanWord2VecDirectory();
4587            
4588             print( "Success!\n" ) if $result == 0;
4589             print( "Failed!\n" ) if $result == -1;
4590            
4591             undef( $interface );
4592            
4593             =head3 CLSimilarityAvg
4594            
4595             Description:
4596            
4597             Computes cosine similarity of average values for a list of specified word comparisons given a file.
4598            
4599             Note: Trained vector data must be loaded in memory previously before calling this method.
4600            
4601             Input:
4602            
4603             $filePath -> Text file with list of word comparisons by line.
4604            
4605             Output:
4606            
4607             $value -> Result '0' = Successful / '-1' = Un-successful
4608            
4609             Example:
4610            
4611             use Word2vec::Interface;
4612            
4613             my $interface = Word2vec::Interface->new();
4614             my $result = $interface->W2VReadTrainedVectorDataFromFile( "vectors.bin" );
4615             $result = $interface->CLSimilarityAvg( "MiniMayoSRS.terms" ) if $result == 0;
4616            
4617             print( "Success!\n" ) if $result == 0;
4618             print( "Failed!\n" ) if $result == -1;
4619            
4620             undef( $interface );
4621            
4622             =head3 CLSimilarityComp
4623            
4624             Description:
4625            
4626             Computes cosine similarity values for a list of specified compound word comparisons given a file.
4627            
4628             Note: Trained vector data must be loaded in memory previously before calling this method.
4629            
4630             Input:
4631            
4632             $filePath -> Text file with list of word comparisons by line.
4633            
4634             Output:
4635            
4636             $value -> Result '0' = Successful / '-1' = Un-successful
4637            
4638             Example:
4639            
4640             use Word2vec::Interface;
4641            
4642             my $interface = Word2vec::Interface->new();
4643             my $result = $interface->W2VReadTrainedVectorDataFromFile( "vectors.bin" );
4644             $result = $interface->CLSimilarityComp( "MiniMayoSRS.terms" ) if $result == 0;
4645            
4646             print( "Success!\n" ) if $result == 0;
4647             print( "Failed!\n" ) if $result == -1;
4648            
4649             undef( $interface );
4650            
4651             =head3 CLSimilaritySum
4652            
4653             Description:
4654            
4655             Computes cosine similarity of summed values for a list of specified word comparisons given a file.
4656            
4657             Note: Trained vector data must be loaded in memory previously before calling this method.
4658            
4659             Input:
4660            
4661             $filePath -> Text file with list of word comparisons by line.
4662            
4663             Output:
4664            
4665             $value -> Result '0' = Successful / '-1' = Un-successful
4666            
4667             Example:
4668            
4669             use Word2vec::Interface;
4670            
4671             my $interface = Word2vec::Interface->new();
4672             my $result = $interface->W2VReadTrainedVectorDataFromFile( "vectors.bin" );
4673             $result = $interface->CLSimilaritySum( "MiniMayoSRS.terms" ) if $result == 0;
4674            
4675             print( "Success!\n" ) if $result == 0;
4676             print( "Failed!\n" ) if $result == -1;
4677            
4678             undef( $interface );
4679            
4680             =head3 CLWordSenseDisambiguation
4681            
4682             Description:
4683            
4684             Command-line Method: Assigns a particular sense to each instance using word2vec trained word vector data.
4685             Stop words are removed if a stoplist is specified before computing cosine similarity average of each instance
4686             and sense context.
4687            
4688             Input:
4689            
4690             $instanceFilePath -> WSD instance file path
4691             $senseFilePath -> WSD sense file path
4692             $stopListfilePath -> Stop list file path
4693            
4694             Output:
4695            
4696             $value -> Returns '0' = Successful / '-1' = Un-successful
4697            
4698             Example:
4699            
4700             use Word2vec::Interface;
4701            
4702             my $interface = Word2vec::Interface->new();
4703             my $result = $interface->CLWordSenseDisambiguation( "ACE.instances.sval", "ACE.senses.sval", "vectors.bin", "stoplist" );
4704            
4705             print( "Success!\n" ) if $result == 0;
4706             print( "Failed!\n" ) if $result == -1;
4707            
4708             undef( $interface );
4709            
4710             =head3 _WSDAnalyzeSenseData
4711            
4712             Description:
4713            
4714             Analyzes sense sval files for identification number mismatch and adjusts accordingly in memory.
4715            
4716             Input:
4717            
4718             None
4719            
4720             Output:
4721            
4722             None
4723            
4724             Example:
4725            
4726             This is a private function and should not be utilized.
4727            
4728             =head3 _WSDReadList
4729            
4730             Description:
4731            
4732             Reads a WSD list when the '-list' parameter is specified.
4733            
4734             Input:
4735            
4736             $listPath -> WSD list file path
4737            
4738             Output:
4739            
4740             \%listOfFile -> List of files hash reference
4741            
4742             Example:
4743            
4744             This is a private function and should not be utilized.
4745            
4746             =head3 _WSDParseList
4747            
4748             Description:
4749            
4750             Parses the specified list of files for Word Sense Disambiguation computation.
4751            
4752             Input:
4753            
4754             $listOfFilesHashRef -> Hash reference to a hash of file paths
4755             $vectorBinaryFile -> Word2vec trained word vector data file
4756             $stopListFilePath -> Stop list file path
4757            
4758             Output:
4759            
4760             $value -> '0' = Successful / '-1' = Un-successful
4761            
4762             Example:
4763            
4764             This is a private function and should not be utilized.
4765            
4766             =head3 WSDParseFile
4767            
4768             Description:
4769            
4770             Parses a specified file in SVL format and stores all context in memory. Utilized for
4771             Word Sense Disambiguation cosine similarity computation.
4772            
4773             Input:
4774            
4775             $filePath -> WSD instance or sense file path
4776             $stopListRegex -> Stop list regex ( Automatically generated with stop list file )
4777            
4778             Output:
4779            
4780             $arrayReference -> Array reference of WSD instances or WSD senses in memory.
4781            
4782             Example:
4783            
4784             This is a private function and should not be utilized.
4785            
4786             =head3 WSDCalculateCosineAvgSimiliarity
4787            
4788             Description:
4789            
4790             For each instance stored in memory, this method computes an average cosine similarity for the context
4791             of each instance and sense with stop words removed via stop list regex. After average cosine similarity
4792             values are calculated for each instance and sense, the cosine similarity of each instance and sense is
4793             computed. The highest cosine similarity value of a given instance to a particular sense is assigned and
4794             stored.
4795            
4796             Input:
4797            
4798             None
4799            
4800             Output:
4801            
4802             $value -> Returns '0' = Successful / '-1' = Un-successful
4803            
4804             Example:
4805            
4806             This is a private function and should not be utilized.
4807            
4808             =head3 _WSDCalculateAccuracy
4809            
4810             Description:
4811            
4812             Computes accuracy of assigned sense identification for each instance in memory.
4813            
4814             Input:
4815            
4816             None
4817            
4818             Output:
4819            
4820             $value -> Returns accuracy percentage (float) or '-1' if un-successful.
4821            
4822             Example:
4823            
4824             This is a private function and should not be utilized.
4825            
4826             =head3 WSDPrintResults
4827            
4828             Description:
4829            
4830             For each instance, this method prints standard information to the console window consisting of:
4831            
4832             =over 4
4833            
4834             =item I
4835            
4836             =item I
4837            
4838             =item I
4839            
4840             =item I
4841            
4842             =back
4843            
4844             Note: Only prints to console if '--debuglog' or 'writelog' option is passed.
4845            
4846             Input:
4847            
4848             None
4849            
4850             Output:
4851            
4852             None
4853            
4854             Example:
4855            
4856             This is a private function and should not be utilized.
4857            
4858             =head3 WSDSaveResults
4859            
4860             Description:
4861            
4862             Saves WSD results post sense identification assignment in the 'instanceFilePath' (string) location. Saved data consists of:
4863            
4864             =over 4
4865            
4866             =item I
4867            
4868             =item I
4869            
4870             =item I
4871            
4872             =item I
4873            
4874             =back
4875            
4876             Input:
4877            
4878             $instanceFilePath -> WSD instance file path
4879            
4880             Output:
4881            
4882             None
4883            
4884             Example:
4885            
4886             This is a private function and should not be utilized.
4887            
4888             =head3 _WSDGenerateAccuracyReport
4889            
4890             Description:
4891            
4892             Fetches saved results for all instance files and stores accuracies for each in a text file.
4893            
4894             Input:
4895            
4896             $workingDirectory -> Directory of "*.results.txt" files
4897            
4898             Output:
4899            
4900             None
4901            
4902             Example:
4903            
4904             This is a private function and should not be utilized.
4905            
4906             =head3 _WSDStop
4907            
4908             Description:
4909            
4910             Generates and returns a stop list regex given a 'stopListFilePath' (string). Returns undefined in the event of an error.
4911            
4912             Input:
4913            
4914             $stopListFilePath -> WSD Stop list file path
4915            
4916             Output:
4917            
4918             $stopListRegex -> Returns stop list regex of the WSD stop list file.
4919            
4920             Example:
4921            
4922             This is a private function and should not be utilized.
4923            
4924             =head3 ConvertStringLineEndingsToTargetOS
4925            
4926             Description:
4927            
4928             Converts passed string parameter to current OS line ending format.
4929            
4930             ie. DOS/Windows to Unix/Linux or Unix/Linux to DOS/Windows.
4931            
4932             Warning: This is incompatible with the legacy MacOS format, errors may occur as it is not supported.
4933            
4934             Input:
4935            
4936             $string -> String to convert
4937            
4938             Output:
4939            
4940             $string -> Output data with target OS line endings.
4941            
4942             Example:
4943            
4944             use Word2vec::Interface;
4945            
4946             my $interface = Word2vec::Interface->new();
4947            
4948             my $tempStr = "samples text\r\n;
4949             $tempStr = $interface->ConvertStringLineEndingsToTargetOS( $tempStr );
4950            
4951             undef( $interface );
4952            
4953             =head2 Interface Accessor Functions
4954            
4955             =head3 GetWord2VecDir
4956            
4957             Description:
4958            
4959             Returns word2vec executable/source directory.
4960            
4961             Input:
4962            
4963             None
4964            
4965             Output:
4966            
4967             $string -> Word2vec file path
4968            
4969             Example:
4970            
4971             use Word2vec::Interface;
4972            
4973             my $interface = Word2vec::Interface->new();
4974             my $filePath = $interface->GetWord2VecDir();
4975            
4976             print( "FilePath: $filePath\n" );
4977            
4978             undef( $interface );
4979            
4980             =head3 GetDebugLog
4981            
4982             Description:
4983            
4984             Returns the _debugLog member variable set during Word2vec::Word2phrase object initialization of new function.
4985            
4986             Input:
4987            
4988             None
4989            
4990             Output:
4991            
4992             $value -> 0 = False, 1 = True
4993            
4994             Example:
4995            
4996             use Word2vec::Interface;
4997            
4998             my $interface = Word2vec::Interface->new();
4999             my $debugLog = $interface->GetDebugLog();
5000            
5001             print( "Debug Logging Enabled\n" ) if $debugLog == 1;
5002             print( "Debug Logging Disabled\n" ) if $debugLog == 0;
5003            
5004             undef( $interface );
5005            
5006             =head3 GetWriteLog
5007            
5008             Description:
5009            
5010             Returns the _writeLog member variable set during Word2vec::Word2phrase object initialization of new function.
5011            
5012             Input:
5013            
5014             None
5015            
5016             Output:
5017            
5018             $value -> 0 = False, 1 = True
5019            
5020             Example:
5021            
5022             use Word2vec::Interface;
5023            
5024             my $interface = Word2vec::Interface->new();
5025             my $writeLog = $interface->GetWriteLog();
5026            
5027             print( "Write Logging Enabled\n" ) if $writeLog == 1;
5028             print( "Write Logging Disabled\n" ) if $writeLog == 0;
5029            
5030             undef( $interface );
5031            
5032             =head3 GetIgnoreCompileErrors
5033            
5034             Description:
5035            
5036             Returns the _ignoreCompileErrors member variable set during Word2vec::Word2phrase object initialization of new function.
5037            
5038             Input:
5039            
5040             None
5041            
5042             Output:
5043            
5044             $value -> 0 = False, 1 = True
5045            
5046             Example:
5047            
5048             use Word2vec::Interface;
5049            
5050             my $interface = Word2vec::Interface->new();
5051             my $ignoreCompileErrors = $interface->GetIgnoreCompileErrors();
5052            
5053             print( "Ignore Compile Errors Enabled\n" ) if $ignoreCompileErrors == 1;
5054             print( "Ignore Compile Errors Disabled\n" ) if $ignoreCompileErrors == 0;
5055            
5056             undef( $interface );
5057            
5058             =head3 GetIgnoreFileChecks
5059            
5060             Description:
5061            
5062             Returns the _ignoreFileChecks member variable set during Word2vec::Word2phrase object initialization of new function.
5063            
5064             Input:
5065            
5066             None
5067            
5068             Output:
5069            
5070             $value -> 0 = False, 1 = True
5071            
5072             Example:
5073            
5074             use Word2vec::Interface;
5075            
5076             my $interface = Word2vec::Interface->new();
5077             my $ignoreFileChecks = $interface->GetIgnoreFileChecks();
5078            
5079             print( "Ignore File Checks Enabled\n" ) if $ignoreFileChecks == 1;
5080             print( "Ignore File Checks Disabled\n" ) if $ignoreFileChecks == 0;
5081            
5082             undef( $interface );
5083            
5084             =head3 GetExitFlag
5085            
5086             Description:
5087            
5088             Returns the _exitFlag member variable set during Word2vec::Word2phrase object initialization of new function.
5089            
5090             Input:
5091            
5092             None
5093            
5094             Output:
5095            
5096             $value -> 0 = False, 1 = True
5097            
5098             Example:
5099            
5100             use Word2vec::Interface;
5101            
5102             my $interface = Word2vec::Interface->new();
5103             my $exitFlag = $interface->GetExitFlag();
5104            
5105             print( "Exit Flag Set\n" ) if $exitFlag == 1;
5106             print( "Exit Flag Not Set\n" ) if $exitFlag == 0;
5107            
5108             undef( $interface );
5109            
5110             =head3 GetFileHandle
5111            
5112             Description:
5113            
5114             Returns file handle used by WriteLog() method.
5115            
5116             Input:
5117            
5118             None
5119            
5120             Output:
5121            
5122             $fileHandle -> Returns file handle blob used by 'WriteLog()' function or undefined.
5123            
5124             Example:
5125            
5126             This is a private function and should not be utilized.
5127            
5128             =head3 GetWorkingDirectory
5129            
5130             Description:
5131            
5132             Returns the _workingDir member variable set during Word2vec::Word2phrase object initialization of new function.
5133            
5134             Input:
5135            
5136             None
5137            
5138             Output:
5139            
5140             $string -> Returns working directory
5141            
5142             Example:
5143            
5144             use Word2vec::Interface;
5145            
5146             my $interface = Word2vec::Interface->new();
5147             my $dir = $interface->GetWorkingDirectory();
5148            
5149             print( "Working Directory: $dir\n" );
5150            
5151             undef( $interface );
5152            
5153             =head3 GetWord2VecHandler
5154            
5155             Description:
5156            
5157             Returns the _word2vec member variable set during Word2vec::Word2phrase object initialization of new function.
5158            
5159             Note: This returns a new object if not defined with word2vec::_debugLog and word2vec::_writeLog parameters mirroring interface::_debugLog and interface::_writeLog.
5160            
5161             Input:
5162            
5163             None
5164            
5165             Output:
5166            
5167             Word2vec::Word2vec -> Returns 'Word2vec::Word2vec' object.
5168            
5169             Example:
5170            
5171             use Word2vec::Interface;
5172            
5173             my $interface = Word2vec::Interface->new();
5174             my $word2vec = $interface->GetWord2VecHandler();
5175            
5176             undef( $word2vec );
5177             undef( $interface );
5178            
5179             =head3 GetWord2PhraseHandler
5180            
5181             Description:
5182            
5183             Returns the _word2phrase member variable set during Word2vec::Word2phrase object initialization of new function.
5184            
5185             Note: This returns a new object if not defined with word2vec::_debugLog and word2vec::_writeLog parameters mirroring interface::_debugLog and interface::_writeLog.
5186            
5187             Input:
5188            
5189             None
5190            
5191             Output:
5192            
5193             Word2vec::Word2phrase -> Returns 'Word2vec::Word2phrase' object
5194            
5195             Example:
5196            
5197             use Word2vec::Interface;
5198            
5199             my $interface = Word2vec::Interface->new();
5200             my $word2phrase = $interface->GetWord2PhraseHandler();
5201            
5202             undef( $word2phrase );
5203             undef( $interface );
5204            
5205             =head3 GetXMLToW2VHandler
5206            
5207             Description:
5208            
5209             Returns the _xmltow2v member variable set during Word2vec::Word2phrase object initialization of new function.
5210            
5211             Note: This returns a new object if not defined with word2vec::_debugLog and word2vec::_writeLog parameters mirroring interface::_debugLog and interface::_writeLog.
5212            
5213             Input:
5214            
5215             None
5216            
5217             Output:
5218            
5219             Word2vec::Xmltow2v -> Returns 'Word2vec::Xmltow2v' object
5220            
5221             Example:
5222            
5223             use Word2vec::Interface;
5224            
5225             my $interface = Word2vec::Interface->new();
5226             my $xmltow2v = $interface->GetXMLToW2VHandler();
5227            
5228             undef( $xmltow2v );
5229             undef( $interface );
5230            
5231             =head3 GetInstanceAry
5232            
5233             Description:
5234            
5235             Returns the _instanceAry member variable set during Word2vec::Word2phrase object initialization of new function.
5236            
5237             Input:
5238            
5239             None
5240            
5241             Output:
5242            
5243             $instance -> Returns array reference of WSD instances.
5244            
5245             Example:
5246            
5247             use Word2vec::Interface;
5248            
5249             my $interface = Word2vec::Interface->new();
5250             my $aryRef = $interface->GetInstanceAry();
5251            
5252             my @instanceAry = @{ $aryRef };
5253             undef( $interface );
5254            
5255             =head3 GetSensesAry
5256            
5257             Description:
5258            
5259             Returns the _senseAry member variable set during Word2vec::Word2phrase object initialization of new function.
5260            
5261             Input:
5262            
5263             None
5264            
5265             Output:
5266            
5267             $senses -> Returns array reference of WSD senses.
5268            
5269             Example:
5270            
5271             use Word2vec::Interface;
5272            
5273             my $interface = Word2vec::Interface->new();
5274             my $aryRef = $interface->GetSensesAry();
5275            
5276             my @sensesAry = @{ $aryRef };
5277             undef( $interface );
5278            
5279             =head3 GetInstanceCount
5280            
5281             Description:
5282            
5283             Returns the _instanceCount member variable set during Word2vec::Word2phrase object initialization of new function.
5284            
5285             Input:
5286            
5287             None
5288            
5289             Output:
5290            
5291             $value -> Returns number of stored WSD instances.
5292            
5293             Example:
5294            
5295             use Word2vec::Interface;
5296            
5297             my $interface = Word2vec::Interface->new();
5298             my $count = $interface->GetInstanceCount();
5299            
5300             print( "Stored WSD instances in memory: $count\n" );
5301            
5302             undef( $interface );
5303            
5304             =head3 GetSenseCount
5305            
5306             Description:
5307            
5308             Returns the _sensesCount member variable set during Word2vec::Word2phrase object initialization of new function.
5309            
5310             Input:
5311            
5312             None
5313            
5314             Output:
5315            
5316             $value -> Returns number of stored WSD senses.
5317            
5318             Example:
5319            
5320             use Word2vec::Interface;
5321            
5322             my $interface = Word2vec::Interface->new();
5323             my $count = $interface->GetSensesCount();
5324            
5325             print( "Stored WSD senses in memory: $count\n" );
5326            
5327             undef( $interface );
5328            
5329             =head2 Interface Mutator Functions
5330            
5331             =head3 SetWord2VecDir
5332            
5333             Description:
5334            
5335             Sets word2vec executable/source file directory.
5336            
5337             Input:
5338            
5339             $string -> Word2Vec Directory
5340            
5341             Output:
5342            
5343             None
5344            
5345             Example:
5346            
5347             use Word2vec::Interface;
5348            
5349             my $interface = Word2vec::Interface->new();
5350             $interface->SetWord2VecDir( "/word2vec" );
5351            
5352             undef( $interface );
5353            
5354             =head3 SetDebugLog
5355            
5356             Description:
5357            
5358             Instructs module to print debug statements to the console.
5359            
5360             Input:
5361            
5362             $value -> '1' = Print Debug Statements / '0' = Do Not Print Statements
5363            
5364             Output:
5365            
5366             None
5367            
5368             Example:
5369            
5370             use Word2vec::Interface;
5371            
5372             my $interface = Word2vec::Interface->new();
5373             $interface->SetDebugLog( 1 );
5374            
5375             undef( $interface );
5376            
5377             =head3 SetWriteLog
5378            
5379             Description:
5380            
5381             Instructs module to print a log file.
5382            
5383             Input:
5384            
5385             $value -> '1' = Print Debug Statements / '0' = Do Not Print Statements
5386            
5387             Output:
5388            
5389             None
5390            
5391             Example:
5392            
5393             use Word2vec::Interface;
5394            
5395             my $interface = Word2vec::Interface->new();
5396             $interface->SetWriteLog( 1 );
5397            
5398             undef( $interface );
5399            
5400             =head3 SetIgnoreCompileErrors
5401            
5402             Description:
5403            
5404             Instructs module to ignore compile errors when compiling source files.
5405            
5406             Input:
5407            
5408             $value -> '1' = Ignore warnings/errors, '0' = Display and process warnings/errors.
5409            
5410             Output:
5411            
5412             None
5413            
5414             Example:
5415            
5416             use Word2vec::Interface;
5417            
5418             my $instance = word2vec::instance->new();
5419             $instance->SetIgnoreCompileErrors( 1 );
5420            
5421             undef( $instance );
5422            
5423             =head3 SetIgnoreFileCheckErrors
5424            
5425             Description:
5426            
5427             Instructs module to ignore file checking errors.
5428            
5429             Input:
5430            
5431             $value -> '1' = Ignore warnings/errors, '0' = Display and process warnings/errors.
5432            
5433             Output:
5434            
5435             None
5436            
5437             Example:
5438            
5439             use Word2vec::Interface;
5440            
5441             my $interface = Word2vec::Interface->new();
5442             $interface->SetIgnoreFileCheckErrors( 1 );
5443            
5444             undef( $interface );
5445            
5446             =head3 SetWorkingDirectory
5447            
5448             Description:
5449            
5450             Sets current working directory.
5451            
5452             Input:
5453            
5454             $path -> Working directory path (String)
5455            
5456             Output:
5457            
5458             None
5459            
5460             Example:
5461            
5462             use Word2vec::Interface;
5463            
5464             my $interface = Word2vec::Interface->new();
5465             $interface->SetWorkingDirectory( "my/new/working/directory" );
5466            
5467             undef( $interface );
5468            
5469             =head3 SetInstanceAry
5470            
5471             Description:
5472            
5473             Sets member instance array variable to de-referenced passed array reference parameter.
5474            
5475             Input:
5476            
5477             $arrayReference -> Array reference for Word Sense Disambiguation - Array of instances (Word2vec::Wsddata objects).
5478            
5479             Output:
5480            
5481             None
5482            
5483             Example:
5484            
5485             use word2vec::instance;
5486            
5487             # This array would theoretically contain 'Word2vec::Wsddata' objects.
5488             my @instanceAry = ();
5489            
5490             my $instance = word2vec::instance->new();
5491             $instance->SetInstanceAry( \@instanceAry );
5492            
5493             undef( $instance );
5494            
5495             =head3 ClearInstanceAry
5496            
5497             Description:
5498            
5499             Clears member instance array.
5500            
5501             Input:
5502            
5503             None
5504            
5505             Output:
5506            
5507             None
5508            
5509             Example:
5510            
5511             use Word2vec::Interface;
5512            
5513             my $instance = word2vec::instance->new();
5514             $instance->ClearInstanceAry();
5515            
5516             undef( $instance );
5517            
5518             =head3 SetSenseAry
5519            
5520             Description:
5521            
5522             Sets member sense array variable to de-referenced passed array reference parameter.
5523            
5524             Input:
5525            
5526             $arrayReference -> Array reference for Word Sense Disambiguation - Array of senses (Word2vec::Wsddata objects).
5527            
5528             Output:
5529            
5530             None
5531            
5532             Example:
5533            
5534             use Word2vec::Interface;
5535            
5536             # This array would theoretically contain 'Word2vec::Wsddata' objects.
5537             my @senseAry = ();
5538            
5539             my $interface = word2vec::instance->new();
5540             $interface->SetSenseAry( \@senseAry );
5541            
5542             undef( $instance );
5543            
5544             =head3 ClearSenseAry
5545            
5546             Description:
5547            
5548             Clears member sense array.
5549            
5550             Input:
5551            
5552             None
5553            
5554             Output:
5555            
5556             None
5557            
5558             Example:
5559            
5560             use word2vec::instance;
5561            
5562             my $instance = word2vec::instance->new();
5563             $instance->ClearSenseAry();
5564            
5565             undef( $instance );
5566            
5567             =head3 SetInstanceCount
5568            
5569             Description:
5570            
5571             Sets member instance count variable to passed value (integer).
5572            
5573             Input:
5574            
5575             $value -> Integer (Positive)
5576            
5577             Output:
5578            
5579             None
5580            
5581             Example:
5582            
5583             use word2vec::instance;
5584            
5585             my $instance = word2vec::instance->new();
5586             $instance->SetInstanceCount( 12 );
5587            
5588             undef( $instance );
5589            
5590             =head3 SetSenseCount
5591            
5592             Description:
5593            
5594             Sets member sense count variable to passed value (integer).
5595            
5596             Input:
5597            
5598             $value -> Integer (Positive)
5599            
5600             Output:
5601            
5602             None
5603            
5604             Example:
5605            
5606             use Word2vec::Interface;
5607            
5608             my $interface = word2vec::instance->new();
5609             $instance->SetSenseCount( 12 );
5610            
5611             undef( $instance );
5612            
5613             =head2 Debug Functions
5614            
5615             =head3 GetTime
5616            
5617             Description:
5618            
5619             Returns current time string in "Hour:Minute:Second" format.
5620            
5621             Input:
5622            
5623             None
5624            
5625             Output:
5626            
5627             $string -> XX:XX:XX ("Hour:Minute:Second")
5628            
5629             Example:
5630            
5631             use Word2vec::Interface:
5632            
5633             my $interface = Word2vec::Interface->new();
5634             my $time = $interface->GetTime();
5635            
5636             print( "Current Time: $time\n" ) if defined( $time );
5637            
5638             undef( $interface );
5639            
5640             =head3 GetDate
5641            
5642             Description:
5643            
5644             Returns current month, day and year string in "Month/Day/Year" format.
5645            
5646             Input:
5647            
5648             None
5649            
5650             Output:
5651            
5652             $string -> XX/XX/XXXX ("Month/Day/Year")
5653            
5654             Example:
5655            
5656             use Word2vec::Interface:
5657            
5658             my $interface = Word2vec::Interface->new();
5659             my $date = $interface->GetDate();
5660            
5661             print( "Current Date: $date\n" ) if defined( $date );
5662            
5663             undef( $interface );
5664            
5665             =head3 WriteLog
5666            
5667             Description:
5668            
5669             Prints passed string parameter to the console, log file or both depending on user options.
5670            
5671             Note: printNewLine parameter prints a new line character following the string if the parameter
5672             is undefined and does not if parameter is 0.
5673            
5674             Input:
5675            
5676             $string -> String to print to the console/log file.
5677             $value -> 0 = Do not print newline character after string, all else prints new line character including 'undef'.
5678            
5679             Output:
5680            
5681             None
5682            
5683             Example:
5684            
5685             use Word2vec::Interface:
5686            
5687             my $interface = Word2vec::Interface->new();
5688             $interface->WriteLog( "Hello World" );
5689            
5690             undef( $interface );
5691            
5692             =head2 Util Main Functions
5693            
5694             =head3 IsFileOrDirectory
5695            
5696             Description:
5697            
5698             Given a path, returns a string specifying whether this path represents a file or directory.
5699            
5700             Input:
5701            
5702             $path -> String representing path to check
5703            
5704             Output:
5705            
5706             $string -> Returns "file", "dir" or "unknown".
5707            
5708             Example:
5709            
5710             use Word2vec::Interface;
5711            
5712             my $interface = Word2vec::Interface->new();
5713            
5714             my $result = $interface->IsFileOrDirectory( "../samples/stoplist" );
5715            
5716             print( "Path Type Is A File\n" ) if $result eq "file";
5717             print( "Path Type Is A Directory\n" ) if $result eq "dir";
5718             print( "Path Type Is Unknown\n" ) if $result eq "unknown";
5719            
5720             undef( $interface );
5721            
5722             =head3 GetFilesInDirectory
5723            
5724             Description:
5725            
5726             Given a path and file tag string, returns a string of files consisting of the file tag string in the specified path.
5727            
5728             Input:
5729            
5730             $path -> String representing path
5731             $fileTag -> String consisting of file tag to fetch.
5732            
5733             Output:
5734            
5735             $string -> Returns string of file names consisting of $fileTag.
5736            
5737             Example:
5738            
5739             use Word2vec::Interface;
5740            
5741             my $interface = Word2vec::Interface->new();
5742            
5743             # Looks in specified path for files including ".sval" in their file name.
5744             my $result = $interface->GetFilesInDirectory( "../samples/", ".sval" );
5745            
5746             print( "Found File Name(s): $result\n" ) if defined( $result );
5747            
5748             undef( $interface );
5749            
5750             =head2 Spearmans Main Functions
5751            
5752             =head3 SpCalculateSpearmans
5753            
5754             Calculates Spearman's Rank Correlation Score between two data-sets.
5755            
5756             Input:
5757            
5758             $fileA -> Data set to compare
5759             $fileB -> Data set to compare
5760             $includeCountsInResults -> Specifies whether to return file counts in score. (undef = False / defined = True)
5761            
5762             Output:
5763            
5764             $value -> "undef" or Spearman's Rank Correlation Score
5765            
5766             Example:
5767            
5768             use Word2vec::Interface;
5769            
5770             my $interface = Word2vec::Interface->new();
5771             my $score = $interface->SpCalculateSpearmans( "samples/MiniMayoSRS.term.comp_results", "Similarity/MiniMayoSRS.terms.coders", undef );
5772             print "Spearman's Rank Correlation Score: $score\n" if defined( $score );
5773             print "Spearman's Rank Correlation Score: undef\n" if !defined( $score );
5774            
5775             undef( $interface );
5776            
5777             =head3 SpIsFileWordOrCUIFile
5778            
5779             Description:
5780            
5781             Determines if a file is composed of CUI or word terms by checking the first line.
5782            
5783             Input:
5784            
5785             $string -> File Path
5786            
5787             Output:
5788            
5789             $string -> "undef" = Unable to determine, "cui" = CUI Term File, "word" = Word Term File
5790            
5791             Example:
5792            
5793             use Word2vec::Interface;
5794            
5795             my $interface = Word2vec::Interface->new();
5796             my $isWordOrCuiFile = $interface->SpIsFileWordOrCUIFile( "samples/MiniMayoSRS.terms" );
5797            
5798             print( "MiniMayoSRS.terms File Is A \"$isWordOrCuiFile\" File\n" ) if defined( $isWordOrCuiFile );
5799             print( "Unable To Determine Type Of File\n" ) if !defined( $isWordOrCuiFile );
5800            
5801             undef( $interface );
5802            
5803             =head3 SpGetPrecision
5804            
5805             Returns the number of decimal places after the decimal point of the Spearman's Rank Correlation Score to represent.
5806            
5807             Input:
5808            
5809             None
5810            
5811             Output:
5812            
5813             $value -> Integer
5814            
5815             Example:
5816            
5817             use Word2vec::Interface;
5818            
5819             my $interface = Word2vec::Interface->new();
5820             print "Spearman's Precision: " . $interface->SpGetPrecision() . "\n";
5821            
5822             undef( $interface );
5823            
5824             =head3 SpGetIsFileOfWords
5825            
5826             Returns the variable indicating whether the files to be parsed are files consisting of words or CUI terms.
5827            
5828             Input:
5829            
5830             None
5831            
5832             Output:
5833            
5834             $value -> "undef" = Auto-Detect, 0 = CUI Terms, 1 = Word Terms
5835            
5836             Example:
5837            
5838             use Word2vec::Interface;
5839            
5840             my $interface = Word2vec::Interface->new();
5841             my $isFileOfWords = $interface->SpGetIsFileOfWords();
5842             print "Is File Of Words?: $isFileOfWords\n" if defined( $isFileOfWords );
5843             print "Is File Of Words?: undef\n" if !defined( $isFileOfWords );
5844            
5845             undef( $interface );
5846            
5847             =head3 SpGetPrintN
5848            
5849             Returns the variable indicating whether the to print NValue.
5850            
5851             Input:
5852            
5853             None
5854            
5855             Output:
5856            
5857             $value -> "undef" = Do not print NValue, "defined" = Print NValue
5858            
5859             Example:
5860            
5861             use Word2vec::Interface;
5862            
5863             my $interface = Word2vec::Interface->new();
5864             my $printN = $interface->SpGetPrintN();
5865             print "Print N\n" if defined( $printN );
5866             print "Do Not Print N\n" if !defined( $printN );
5867            
5868             undef( $interface );
5869            
5870             =head3 SpGetACount
5871            
5872             Returns the non-negative count for file A.
5873            
5874             Input:
5875            
5876             None
5877            
5878             Output:
5879            
5880             $value -> Integer
5881            
5882             Example:
5883            
5884             use Word2vec::Interface;
5885            
5886             my $interface = Word2vec::Interface->new();
5887             print "A Count: " . $interface->SpGetACount() . "\n";
5888            
5889             undef( $interface );
5890            
5891             =head3 SpGetBCount
5892            
5893             Returns the non-negative count for file B.
5894            
5895             Input:
5896            
5897             None
5898            
5899             Output:
5900            
5901             $value -> Integer
5902            
5903             Example:
5904            
5905             use Word2vec::Interface;
5906            
5907             my $interface = Word2vec::Interface->new();
5908             print "B Count: " . $interface->SpGetBCount() . "\n";
5909            
5910             undef( $interface );
5911            
5912             =head3 SpGetNValue
5913            
5914             Returns the N value.
5915            
5916             Input:
5917            
5918             None
5919            
5920             Output:
5921            
5922             $value -> Integer
5923            
5924             Example:
5925            
5926             use Word2vec::Interface;
5927            
5928             my $interface = Word2vec::Interface->new();
5929             print "N Value: " . $interface->SpGetNValue() . "\n";
5930            
5931             undef( $interface );
5932            
5933             =head3 SpSetPrecision
5934            
5935             Sets number of decimal places after the decimal point of the Spearman's Rank Correlation Score to represent.
5936            
5937             Input:
5938            
5939             $value -> Integer
5940            
5941             Output:
5942            
5943             None
5944            
5945             Example:
5946            
5947             use Word2vec::Interface;
5948            
5949             my $interface = Word2vec::Interface->new();
5950             $interface->SpSetPrecision( 8 );
5951             my $score = $interface->SpCalculateSpearmans( "samples/MiniMayoSRS.term.comp_results", "Similarity/MiniMayoSRS.terms.coders", undef );
5952             print "Spearman's Rank Correlation Score: $score\n" if defined( $score );
5953             print "Spearman's Rank Correlation Score: undef\n" if !defined( $score );
5954            
5955             undef( $interface );
5956            
5957             =head3 SpSetIsFileOfWords
5958            
5959             Specifies the main method to auto-detect if file consists of CUI or Word terms, or manual override with user setting.
5960            
5961             Input:
5962            
5963             $value -> "undef" = Auto-Detect, 0 = CUI Terms, 1 = Word Terms
5964            
5965             Output:
5966            
5967             None
5968            
5969             Example:
5970            
5971             use Word2vec::Interface;
5972            
5973             my $interface = Word2vec::Interface->new();
5974             $interface->SpSetIsFileOfWords( undef );
5975             my $score = $interface->SpCalculateSpearmans( "samples/MiniMayoSRS.term.comp_results", "Similarity/MiniMayoSRS.terms.coders", undef );
5976             print "Spearman's Rank Correlation Score: $score\n" if defined( $score );
5977             print "Spearman's Rank Correlation Score: undef\n" if !defined( $score );
5978            
5979             undef( $interface );
5980            
5981             =head3 SpSetPrintN
5982            
5983             Specifies the main method print _NValue post Spearmans::CalculateSpearmans() function completion.
5984            
5985             Input:
5986            
5987             $value -> "undef" = Do Not Print _NValue, "defined" = Print _NValue
5988            
5989             Output:
5990            
5991             None
5992            
5993             Example:
5994            
5995             use Word2vec::Interface;
5996            
5997             my $interface = Word2vec::Interface->new();
5998             $interface->SpSetPrintN( 1 );
5999             my $score = $interface->SpCalculateSpearmans( "samples/MiniMayoSRS.term.comp_results", "Similarity/MiniMayoSRS.terms.coders", undef );
6000             print "Spearman's Rank Correlation Score: $score\n" if defined( $score );
6001             print "Spearman's Rank Correlation Score: undef\n" if !defined( $score );
6002            
6003             undef( $interface );
6004            
6005             =head2 Word2Vec Main Functions
6006            
6007             =head3 W2VExecuteTraining
6008            
6009             Executes word2vec training based on parameters. Parameter variables have higher precedence
6010             than member variables. Any parameter specified will override its respective member variable.
6011            
6012             Note: If no parameters are specified, this module executes word2vec training based on preset
6013             member variables. Returns string regarding training status.
6014            
6015             Input:
6016            
6017             $trainFilePath -> Specifies word2vec text corpus training file in a given path. (String)
6018             $outputFilePath -> Specifies word2vec trained output data file name and save path. (String)
6019             $vectorSize -> Size of word2vec word vectors. (Integer)
6020             $windowSize -> Maximum skip length between words. (Integer)
6021             $minCount -> Disregard words that appear less than $minCount times. (Integer)
6022             $sample -> Threshold for occurrence of words. Those that appear with higher frequency in the training data will be randomly down-sampled. (Float)
6023             $negative -> Number of negative examples. (Integer)
6024             $alpha -> Set that start learning rate. (Float)
6025             $hs -> Hierarchical Soft-max (Integer)
6026             $binary -> Save trained data as binary mode. (Integer)
6027             $numOfThreads -> Number of word2vec training threads. (Integer)
6028             $iterations -> Number of training iterations to run prior to completion of training. (Integer)
6029             $useCBOW -> Enable Continuous Bag Of Words model or Skip-Gram model. (Integer)
6030             $classes -> Output word classes rather than word vectors. (Integer)
6031             $readVocab -> Read vocabulary from file path without constructing from training data. (String)
6032             $saveVocab -> Save vocabulary to file path. (String)
6033             $debug -> Set word2vec debug mode. (Integer)
6034             $overwrite -> Instructs the module to either overwrite any existing text corpus files or append to the existing file. ( '1' = True / '0' = False )
6035            
6036             Note: It is not recommended to specify all new() parameters, as it has not been thoroughly tested.
6037            
6038             Output:
6039            
6040             $value -> '0' = Successful / '-1' = Un-successful
6041            
6042             Example:
6043            
6044             use Word2vec::Interface;
6045            
6046             my $interface = Word2vec::Interface->new();
6047             $interface->W2VSetTrainFilePath( "textcorpus.txt" );
6048             $interface->W2VSetOutputFilePath( "vectors.bin" );
6049             $interface->W2VSetWordVecSize( 200 );
6050             $interface->W2VSetWindowSize( 8 );
6051             $interface->W2VSetSample( 0.0001 );
6052             $interface->W2VSetNegative( 25 );
6053             $interface->W2VSetHSoftMax( 0 );
6054             $interface->W2VSetBinaryOutput( 0 );
6055             $interface->W2VSetNumOfThreads( 20 );
6056             $interface->W2VSetNumOfIterations( 15 );
6057             $interface->W2VSetUseCBOW( 1 );
6058             $interface->W2VSetOverwriteOldFile( 0 );
6059             $interface->W2VExecuteTraining();
6060            
6061             undef( $interface );
6062            
6063             # or
6064            
6065             use Word2vec::Interface;
6066            
6067             my $interface = Word2vec::Interface->new();
6068             $interface->W2VExecuteTraining( "textcorpus.txt", "vectors.bin", 200, 8, 5, 0.001, 25, 0.05, 0, 0, 20, 15, 1, 0, "", "", 2, 0 );
6069            
6070             undef( $interface );
6071            
6072             =head3 W2VExecuteStringTraining
6073            
6074             Executes word2vec training based on parameters. Parameter variables have higher precedence
6075             than member variables. Any parameter specified will override its respective member variable.
6076            
6077             Note: If no parameters are specified, this module executes word2vec training based on preset
6078             member variables. Returns string regarding training status.
6079            
6080             Input:
6081            
6082             $trainingStr -> String to train with word2vec.
6083             $outputFilePath -> Specifies word2vec trained output data file name and save path. (String)
6084             $vectorSize -> Size of word2vec word vectors. (Integer)
6085             $windowSize -> Maximum skip length between words. (Integer)
6086             $minCount -> Disregard words that appear less than $minCount times. (Integer)
6087             $sample -> Threshold for occurrence of words. Those that appear with higher frequency in the training data will be randomly down-sampled. (Float)
6088             $negative -> Number of negative examples. (Integer)
6089             $alpha -> Set that start learning rate. (Float)
6090             $hs -> Hierarchical Soft-max (Integer)
6091             $binary -> Save trained data as binary mode. (Integer)
6092             $numOfThreads -> Number of word2vec training threads. (Integer)
6093             $iterations -> Number of training iterations to run prior to completion of training. (Integer)
6094             $useCBOW -> Enable Continuous Bag Of Words model or Skip-Gram model. (Integer)
6095             $classes -> Output word classes rather than word vectors. (Integer)
6096             $readVocab -> Read vocabulary from file path without constructing from training data. (String)
6097             $saveVocab -> Save vocabulary to file path. (String)
6098             $debug -> Set word2vec debug mode. (Integer)
6099             $overwrite -> Instructs the module to either overwrite any existing text corpus files or append to the existing file. ( '1' = True / '0' = False )
6100            
6101             Note: It is not recommended to specify all new() parameters, as it has not been thoroughly tested.
6102            
6103             Output:
6104            
6105             $value -> '0' = Successful / '-1' = Un-successful
6106            
6107             Example:
6108            
6109             use Word2vec::Interface;
6110            
6111             my $interface = Word2vec::Interface->new();
6112             $interface->W2VSetOutputFilePath( "vectors.bin" );
6113             $interface->W2VSetWordVecSize( 200 );
6114             $interface->W2VSetWindowSize( 8 );
6115             $interface->W2VSetSample( 0.0001 );
6116             $interface->W2VSetNegative( 25 );
6117             $interface->W2VSetHSoftMax( 0 );
6118             $interface->W2VSetBinaryOutput( 0 );
6119             $interface->W2VSetNumOfThreads( 20 );
6120             $interface->W2VSetNumOfIterations( 15 );
6121             $interface->W2VSetUseCBOW( 1 );
6122             $interface->W2VSetOverwriteOldFile( 0 );
6123             $interface->W2VExecuteStringTraining( "string to train here" );
6124            
6125             undef( $interface );
6126            
6127             # or
6128            
6129             use Word2vec::Interface;
6130            
6131             my $interface = Word2vec::Interface->new();
6132             $interface->W2VExecuteStringTraining( "string to train here", "vectors.bin", 200, 8, 5, 0.001, 25, 0.05, 0, 0, 20, 15, 1, 0, "", "", 2, 0 );
6133            
6134             undef( $interface );
6135            
6136             =head3 W2VComputeCosineSimilarity
6137            
6138             Description:
6139            
6140             Computes cosine similarity between two words using trained word2vec vector data. Returns
6141             float value or undefined if one or more words are not in the dictionary.
6142            
6143             Note: Supports single words only and requires vector data to be in memory with W2VReadTrainedVectorDataFromFile() prior to function execution.
6144            
6145             Input:
6146            
6147             $string -> Single string word
6148             $string -> Single string word
6149            
6150             Output:
6151            
6152             $value -> Float or Undefined
6153            
6154             Example:
6155            
6156             use Word2vec::Interface;
6157            
6158             my $interface = Word2vec::Interface->new();
6159             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6160             print "Cosine similarity between words: \"of\" and \"the\": " . $interface->W2VComputeCosineSimilarity( "of", "the" ) . "\n";
6161            
6162             undef( $interface );
6163            
6164             =head3 W2VComputeAvgOfWordsCosineSimilarity
6165            
6166             Description:
6167            
6168             Computes cosine similarity between two words or compound words using trained word2vec vector data.
6169             Returns float value or undefined.
6170            
6171             Note: Supports multiple words concatenated by ' ' and requires vector data to be in memory prior
6172             to method execution. This method will not error out when a word is not located within the dictionary.
6173             It will take the average of all found words for each parameter then cosine similarity of both word vectors.
6174            
6175             Input:
6176            
6177             $string -> string of single or multiple words separated by ' ' (space).
6178             $string -> string of single or multiple words separated by ' ' (space).
6179            
6180             Output:
6181            
6182             $value -> Float or Undefined
6183            
6184             Example:
6185            
6186             use Word2vec::Interface;
6187            
6188             my $interface = Word2vec::Interface->new();
6189             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6190             print "Cosine similarity between words: \"heart attack\" and \"acute myocardial infarction\": " .
6191             $interface->W2VComputeAvgOfWordsCosineSimilarity( "heart attack", "acute myocardial infarction" ) . "\n";
6192            
6193             undef( $interface );
6194            
6195             =head3 W2VComputeMultiWordCosineSimilarity
6196            
6197             Description:
6198            
6199             Computes cosine similarity between two words or compound words using trained word2vec vector data.
6200            
6201             Note: Supports multiple words concatenated by ' ' (space) and requires vector data to be in memory prior to method execution.
6202             If $allWordsMustExist is set to true, this function will error out when a specified word is not found and return undefined.
6203            
6204             Input:
6205            
6206             $string -> string of single or multiple words separated by ' ' (space).
6207             $string -> string of single or multiple words separated by ' ' (space).
6208             $allWordsMustExist -> 1 = True, 0 or undef = False
6209            
6210             Output:
6211            
6212             $value -> Float or Undefined
6213            
6214             Example:
6215            
6216             use Word2vec::Interface;
6217            
6218             my $interface = Word2vec::Interface->new();
6219             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6220             print "Cosine similarity between words: \"heart attack\" and \"acute myocardial infarction\": " .
6221             $interface->W2VComputeMultiWordCosineSimilarity( "heart attack", "acute myocardial infarction" ) . "\n";
6222            
6223             undef( $interface );
6224            
6225             =head3 W2VComputeCosineSimilarityOfWordVectors
6226            
6227             Description:
6228            
6229             Computes cosine similarity between two word vectors.
6230             Returns float value or undefined if one or more words are not in the dictionary.
6231            
6232             Note: Function parameters require actual word vector data with words removed.
6233            
6234             Input:
6235            
6236             $string -> string of word vector representation data separated by ' ' (space).
6237             $string -> string of word vector representation data separated by ' ' (space).
6238            
6239             Output:
6240            
6241             $value -> Float or Undefined
6242            
6243             Example:
6244            
6245             use Word2vec::Interface;
6246            
6247             my $interface = Word2vec::Interface->new();
6248             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6249             my $vectorAData = $interface->W2VGetWordVector( "heart" );
6250             my $vectorBData = $interface->W2VGetWordVector( "attack" );
6251            
6252             # Remove Words From Data
6253             $vectorAData = W2VRemoveWordFromWordVectorString( $vectorAData );
6254             $vectorBData = W2VRemoveWordFromWordVectorString( $vectorBData );
6255            
6256             undef( @tempAry );
6257            
6258             print "Cosine similarity between words: \"heart\" and \"attack\": " .
6259             $interface->W2VComputeCosineSimilarityOfWordVectors( $vectorAData, $vectorBData ) . "\n";
6260            
6261             undef( $interface );
6262            
6263             =head3 W2VCosSimWithUserInput
6264            
6265             Description:
6266            
6267             Computes cosine similarity between two words using trained word2vec vector data based on user input.
6268            
6269             Note: No compound word support.
6270            
6271             Warning: Requires vector data to be in memory prior to method execution.
6272            
6273             Input:
6274            
6275             None
6276            
6277             Output:
6278            
6279             None
6280            
6281             Example:
6282            
6283             use Word2vec::Interface;
6284            
6285             my $interface = Word2vec::Interface->new();
6286             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6287             $interface->W2VCosSimWIthUserInputTest();
6288            
6289             undef( $interface );
6290            
6291             =head3 W2VMultiWordCosSimWithUserInput
6292            
6293             Description:
6294            
6295             Computes cosine similarity between two words or compound words using trained word2vec vector data based on user input.
6296            
6297             Note: Supports multiple words concatenated by ':'.
6298            
6299             Warning: Requires vector data to be in memory prior to method execution.
6300            
6301             Input:
6302            
6303             None
6304            
6305             Output:
6306            
6307             None
6308            
6309             Example:
6310            
6311             use Word2vec::Interface;
6312            
6313             my $interface = Word2vec::Interface->new();
6314             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6315             $interface->W2VMultiWordCosSimWithUserInput();
6316            
6317             undef( $interface );
6318            
6319            
6320             =head3 W2VComputeAverageOfWords
6321            
6322             Description:
6323            
6324             Computes cosine similarity average of all found words given an array reference parameter of
6325             plain text words. Returns average values (string) or undefined.
6326            
6327             Warning: Requires vector data to be in memory prior to method execution.
6328            
6329             Input:
6330            
6331             $arrayReference -> Array reference of words
6332            
6333             Output:
6334            
6335             $string -> String of word2vec word average values
6336            
6337             Example:
6338            
6339             use Word2vec::Interface;
6340            
6341             my $interface = Word2vec::Interface->new();
6342             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6343             my @wordAry = qw( of the and );
6344             my $data = $interface->W2VComputeAverageOfWords( \@wordAry );
6345             print( "Computed Average Of Words: $data" ) if defined( $data );
6346            
6347             undef( $interface );
6348            
6349             =head3 W2VAddTwoWords
6350            
6351             Description:
6352            
6353             Adds two word vectors and returns the result.
6354            
6355             Warning: This method also requires vector data to be in memory prior to method execution.
6356            
6357             Input:
6358            
6359             $string -> Word to add
6360             $string -> Word to add
6361            
6362             Output:
6363            
6364             $string -> String of word2vec summed word values
6365            
6366             Example:
6367            
6368             use Word2vec::Interface;
6369            
6370             my $interface = Word2vec::Interface->new();
6371             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6372            
6373             my $data = $interface->W2VAddTwoWords( "heart", "attack" );
6374             print( "Computed Sum Of Words: $data" ) if defined( $data );
6375            
6376             undef( $interface );
6377            
6378             =head3 W2VSubtractTwoWords
6379            
6380             Description:
6381            
6382             Subtracts two word vectors and returns the result.
6383            
6384             Warning: This method also requires vector data to be in memory prior to method execution.
6385            
6386             Input:
6387            
6388             $string -> Word to subtract
6389             $string -> Word to subtract
6390            
6391             Output:
6392            
6393             $string -> String of word2vec difference between word values
6394            
6395             Example:
6396            
6397             use Word2vec::Interface;
6398            
6399             my $interface = Word2vec::Interface->new();
6400             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6401            
6402             my $data = $interface->W2VSubtractTwoWords( "king", "man" );
6403             print( "Computed Difference Of Words: $data" ) if defined( $data );
6404            
6405             undef( $interface );
6406            
6407            
6408             =head3 W2VAddTwoWordVectors
6409            
6410             Description:
6411            
6412             Adds two vector data strings and returns the result.
6413            
6414             Warning: Text word must be removed from vector data prior to calling this method. This method
6415             also requires vector data to be in memory prior to method execution.
6416            
6417             Input:
6418            
6419             $string -> Word2vec word vector data (with string word removed)
6420             $string -> Word2vec word vector data (with string word removed)
6421            
6422             Output:
6423            
6424             $string -> String of word2vec summed word values
6425            
6426             Example:
6427            
6428             use Word2vec::Interface;
6429            
6430             my $interface = Word2vec::Interface->new();
6431             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6432             my $wordAData = $interface->W2VGetWordVector( "of" );
6433             my $wordBData = $interface->W2VGetWordVector( "the" );
6434            
6435             # Removing Words From Vector Data
6436             $wordAData = W2VRemoveWordFromWordVectorString( $wordAData );
6437             $wordBData = W2VRemoveWordFromWordVectorString( $wordBData );
6438            
6439             my $data = $interface->W2VAddTwoWordVectors( $wordAData, $wordBData );
6440             print( "Computed Sum Of Words: $data" ) if defined( $data );
6441            
6442             undef( $interface );
6443            
6444             =head3 W2VSubtractTwoWordVectors
6445            
6446             Description:
6447            
6448             Subtracts two vector data strings and returns the result.
6449            
6450             Warning: Text word must be removed from vector data prior to calling this method. This method
6451             also requires vector data to be in memory prior to method execution.
6452            
6453             Input:
6454            
6455             $string -> Word2vec word vector data (with string word removed)
6456             $string -> Word2vec word vector data (with string word removed)
6457            
6458             Output:
6459            
6460             $string -> String of word2vec difference between word values
6461            
6462             Example:
6463            
6464             use Word2vec::Interface;
6465            
6466             my $interface = Word2vec::Interface->new();
6467             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6468             my $wordAData = $interface->W2VGetWordVector( "of" );
6469             my $wordBData = $interface->W2VGetWordVector( "the" );
6470            
6471             # Removing Words From Vector Data
6472             $wordAData = W2VRemoveWordFromWordVectorString( $wordAData );
6473             $wordBData = W2VRemoveWordFromWordVectorString( $wordBData );
6474            
6475             my $data = $interface->W2VSubtractTwoWordVectors( $wordAData, $wordBData );
6476             print( "Computed Difference Of Words: $data" ) if defined( $data );
6477            
6478             undef( $interface );
6479            
6480             =head3 W2VAverageOfTwoWordVectors
6481            
6482             Description:
6483            
6484             Computes the average of two vector data strings and returns the result.
6485            
6486             Warning: Text word must be removed from vector data prior to calling this method. This method
6487             also requires vector data to be in memory prior to method execution.
6488            
6489             Input:
6490            
6491             $string -> Word2vec word vector data (with string word removed)
6492             $string -> Word2vec word vector data (with string word removed)
6493            
6494             Output:
6495            
6496             $string -> String of word2vec average between word values
6497            
6498             Example:
6499            
6500             use Word2vec::Interface;
6501            
6502             my $interface = Word2vec::Interface->new();
6503             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6504             my $wordAData = $interface->W2VGetWordVector( "of" );
6505             my $wordBData = $interface->W2VGetWordVector( "the" );
6506            
6507             # Removing Words From Vector Data
6508             $wordAData = W2VRemoveWordFromWordVectorString( $wordAData );
6509             $wordBData = W2VRemoveWordFromWordVectorString( $wordBData );
6510            
6511             my $data = $interface->W2VAverageOfTwoWordVectors( $wordAData, $wordBData );
6512             print( "Computed Average Of Words: $data" ) if defined( $data );
6513            
6514             undef( $interface );
6515            
6516             =head3 W2VGetWordVector
6517            
6518             Description:
6519            
6520             Searches dictionary in memory for the specified string argument and returns the vector data.
6521             Returns undefined if not found.
6522            
6523             Warning: Requires vector data to be in memory prior to method execution.
6524            
6525             Input:
6526            
6527             $string -> Word to locate in word2vec vocabulary/dictionary
6528            
6529             Output:
6530            
6531             $string -> Found word2vec word + word vector data or undefined.
6532            
6533             Example:
6534            
6535             use Word2vec::Interface;
6536            
6537             my $interface = Word2vec::Interface->new();
6538             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6539             my $wordData = $interface->W2VGetWordVector( "of" );
6540             print( "Word2vec Word Data: $wordData\n" ) if defined( $wordData );
6541            
6542             undef( $interface );
6543            
6544             =head3 W2VIsVectorDataInMemory
6545            
6546             Description:
6547            
6548             Checks to see if vector data has been loaded in memory.
6549            
6550             Input:
6551            
6552             None
6553            
6554             Output:
6555            
6556             $value -> '1' = True / '0' = False
6557            
6558             Example:
6559            
6560             use Word2vec::Interface;
6561            
6562             my $interface = Word2vec::Interface->new();
6563             my $result = $interface->W2VIsVectorDataInMemory();
6564            
6565             print( "No vector data in memory\n" ) if $result == 0;
6566             print( "Yes vector data in memory\n" ) if $result == 1;
6567            
6568             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6569            
6570             print( "No vector data in memory\n" ) if $result == 0;
6571             print( "Yes vector data in memory\n" ) if $result == 1;
6572            
6573             undef( $interface );
6574            
6575             =head3 W2VIsWordOrCUIVectorData
6576            
6577             Description:
6578            
6579             Checks to see if vector data consists of word or CUI terms.
6580            
6581             Input:
6582            
6583             None
6584            
6585             Output:
6586            
6587             $string -> 'cui', 'word' or undef
6588            
6589             Example:
6590            
6591             use Word2vec::Interface;
6592            
6593             my $interface = Word2vec::Interface->new();
6594             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6595             my $isWordOrCUIData = $interface->W2VIsWordOrCUIVectorData();
6596            
6597             print( "Vector Data Consists Of \"$isWordOrCUIData\" Terms\n" ) if defined( $isWordOrCUIData );
6598             print( "Cannot Determine Type Of Terms\n" ) if !defined( $isWordOrCUIData );
6599            
6600             undef( $interface );
6601            
6602             =head3 W2VIsVectorDataSorted
6603            
6604             Description:
6605            
6606             Checks to see if vector data header is signed as sorted in memory.
6607            
6608             Input:
6609            
6610             None
6611            
6612             Output:
6613            
6614             $value -> '1' = True / '0' = False
6615            
6616             Example:
6617            
6618             use Word2vec::Interface;
6619            
6620             my $interface = Word2vec::Interface->new();
6621             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6622            
6623             my $result = $interface->IsVectorDataSorted();
6624            
6625             print( "No vector data is not sorted\n" ) if $result == 0;
6626             print( "Yes vector data is sorted\n" ) if $result == 1;
6627            
6628             undef( $interface );
6629            
6630             =head3 W2VCheckWord2VecDataFileType
6631            
6632             Description:
6633            
6634             Checks specified file to see if vector data is in binary or plain text format. Returns 'text'
6635             for plain text and 'binary' for binary data.
6636            
6637             Input:
6638            
6639             $string -> File path
6640            
6641             Output:
6642            
6643             $string -> File Type ( "text" = Plain text file / "binary" = Binary data file )
6644            
6645             Example:
6646            
6647             use Word2vec::Interface;
6648            
6649             my $interface = Word2vec::Interface->new();
6650             my $fileType = $interface->W2VCheckWord2VecDataFileType( "samples/samplevectors.bin" );
6651            
6652             print( "FileType: $fileType\n" ) if defined( $fileType );
6653            
6654             undef( $fileType );
6655            
6656             =head3 W2VReadTrainedVectorDataFromFile
6657            
6658             Description:
6659            
6660             Reads trained vector data from file path in memory or searches for vector data from file. This function supports and
6661             automatically detects word2vec binary, plain text and sparse vector data formats.
6662            
6663             Note: If search word is undefined, the entire vector file is loaded in memory. If a search word is defined only the vector data is returned or undef.
6664            
6665             Input:
6666            
6667             $string -> Word2vec trained vector data file path
6668             $searchWord -> Searches trained vector data file for specific word vector
6669            
6670             Output:
6671            
6672             $value -> '0' = Successful / '-1' = Un-successful
6673            
6674             Example:
6675            
6676             # Loading data in memory
6677             use Word2vec::Interface;
6678            
6679             my $interface = Word2vec::Interface->new();
6680             my $result = $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6681            
6682             print( "Success Loading Data\n" ) if $result == 0;
6683             print( "Un-successful, Data Not Loaded\n" ) if $result == -1;
6684            
6685             undef( $interface );
6686            
6687             # or
6688            
6689             # Searching vector data file for a specific word vector
6690             use Word2vec::Interface;
6691            
6692             my $interface = Word2vec::Interface->new();
6693             my $result = $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin", "medical" );
6694            
6695             print( "Found Vector Data In File\n" ) if $result != -1;
6696             print( "Vector Data Not Found\n" ) if $result == -1;
6697            
6698             undef( $interface );
6699            
6700             =head3 W2VSaveTrainedVectorDataToFile
6701            
6702             Description:
6703            
6704             Saves trained vector data at the location in specified format.
6705            
6706             Note: Leaving 'saveFormat' undefined will automatically save as plain text format.
6707            
6708             Input:
6709            
6710             $string -> Save Path
6711             $saveFormat -> Integer ( '0' = Save as plain text / '1' = Save data in word2vec binary format / '2' = Sparse vector data Ffrmat )
6712            
6713             Note: Leaving $saveFormat as undefined will save the file in plain text format.
6714            
6715             Warning: If the vector data is stored as a binary search tree, this method will error out gracefully.
6716            
6717             Output:
6718            
6719             $value -> '0' = Successful / '-1' = Un-successful
6720            
6721             Example:
6722            
6723             use Word2vec::Interface;
6724            
6725             my $interface = Word2vec::Interface->new();
6726            
6727             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
6728             $interface->W2VSaveTrainedVectorDataToFile( "samples/newvectors.bin" );
6729            
6730             undef( $interface );
6731            
6732             =head3 W2VStringsAreEqual
6733            
6734             Description:
6735            
6736             Compares two strings to check for equality, ignoring case-sensitivity.
6737            
6738             Note: This method is not case-sensitive. ie. "string" equals "StRiNg"
6739            
6740             Input:
6741            
6742             $string -> String to compare
6743             $string -> String to compare
6744            
6745             Output:
6746            
6747             $value -> '1' = Strings are equal / '0' = Strings are not equal
6748            
6749             Example:
6750            
6751             use Word2vec::Interface;
6752            
6753             my $interface = Word2vec::Interface->new();
6754             my $result = $interface->W2VStringsAreEqual( "hello world", "HeLlO wOrLd" );
6755            
6756             print( "Strings are equal!\n" )if $result == 1;
6757             print( "Strings are not equal!\n" ) if $result == 0;
6758            
6759             undef( $interface );
6760            
6761             =head3 W2VRemoveWordFromWordVectorString
6762            
6763             Description:
6764            
6765             Given a vector data string as input, it removed the vector word from its data returning only data.
6766            
6767             Input:
6768            
6769             $string -> Vector word & data string.
6770            
6771             Output:
6772            
6773             $string -> Vector data string.
6774            
6775             Example:
6776            
6777             use Word2vec::Interface;
6778            
6779             my $interface = Word2vec::Interface->new();
6780             my $str = "cookie 1 0.234 9 0.0002 13 0.234 17 -0.0023 19 1.0000";
6781            
6782             my $vectorData = $interface->W2VRemoveWordFromWordVectorString( $str );
6783            
6784             print( "Success!\n" ) if length( vectorData ) < length( $str );
6785            
6786             undef( $interface );
6787            
6788             =head3 W2VConvertRawSparseTextToVectorDataAry
6789            
6790             Description:
6791            
6792             Converts sparse vector string to a dense vector format data array.
6793            
6794             Input:
6795            
6796             $string -> Vector data string.
6797            
6798             Output:
6799            
6800             $arrayReference -> Reference to array of vector data.
6801            
6802             Example:
6803            
6804             use Word2vec::Interface;
6805            
6806             my $interface = Word2vec::Interface->new();
6807             my $str = "cookie 1 0.234 9 0.0002 13 0.234 17 -0.0023 19 1.0000";
6808            
6809             my @vectorData = @{ $interface->W2VConvertRawSparseTextToVectorDataAry( $str ) };
6810            
6811             print( "Data conversion successful!\n" ) if @vectorData > 0;
6812             print( "Data conversion un-successful!\n" ) if @vectorData == 0;
6813            
6814             undef( $interface );
6815            
6816             =head3 W2VConvertRawSparseTextToVectorDataHash
6817            
6818             Description:
6819            
6820             Converts sparse vector string to a dense vector format data hash.
6821            
6822             Input:
6823            
6824             $string -> Vector data string.
6825            
6826             Output:
6827            
6828             $hashReference -> Reference to hash of vector data.
6829            
6830             Example:
6831            
6832             use Word2vec::Interface;
6833            
6834             my $interface = Word2vec::Interface->new();
6835             my $str = "cookie 1 0.234 9 0.0002 13 0.234 17 -0.0023 19 1.0000";
6836            
6837             my %vectorData = %{ $interface->W2VConvertRawSparseTextToVectorDataHash( $str ) };
6838            
6839             print( "Data conversion successful!\n" ) if ( keys %vectorData ) > 0;
6840             print( "Data conversion un-successful!\n" ) if ( keys %vectorData ) == 0;
6841            
6842             undef( $interface );
6843            
6844             =head2 Word2Vec Accessor Functions
6845            
6846             =head3 W2VGetDebugLog
6847            
6848             Description:
6849            
6850             Returns the _debugLog member variable set during Word2vec::Word2vec object initialization of new function.
6851            
6852             Input:
6853            
6854             None
6855            
6856             Output:
6857            
6858             $value -> '0' = False, '1' = True
6859            
6860             Example:
6861            
6862             use Word2vec::Interface;
6863            
6864             my $interface = Word2vec::Interface->new()
6865             my $debugLog = $interface->W2VGetDebugLog();
6866            
6867             print( "Debug Logging Enabled\n" ) if $debugLog == 1;
6868             print( "Debug Logging Disabled\n" ) if $debugLog == 0;
6869            
6870            
6871             undef( $interface );
6872            
6873             =head3 W2VGetWriteLog
6874            
6875             Description:
6876            
6877             Returns the _writeLog member variable set during Word2vec::Word2vec object initialization of new function.
6878            
6879             Input:
6880            
6881             None
6882            
6883             Output:
6884            
6885             $value -> '0' = False, '1' = True
6886            
6887             Example:
6888            
6889             use Word2vec::Interface;
6890            
6891             my $interface = Word2vec::Interface->new();
6892             my $writeLog = $interface->W2VGetWriteLog();
6893            
6894             print( "Write Logging Enabled\n" ) if $writeLog == 1;
6895             print( "Write Logging Disabled\n" ) if $writeLog == 0;
6896            
6897             undef( $interface );
6898            
6899             =head3 W2VGetFileHandle
6900            
6901             Description:
6902            
6903             Returns the _fileHandle member variable set during Word2vec::Word2vec object instantiation of new function.
6904            
6905             Warning: This is a private function. File handle is used by WriteLog() method. Do not manipulate this file handle as errors can result.
6906            
6907             Input:
6908            
6909             None
6910            
6911             Output:
6912            
6913             $fileHandle -> Returns file handle for WriteLog() method or undefined.
6914            
6915             Example:
6916            
6917             use Word2vec::Interface;
6918            
6919             my $interface = Word2vec::Interface->new();
6920             my $fileHandle = $interface->W2VGetFileHandle();
6921            
6922             undef( $interface );
6923            
6924             =head3 W2VGetTrainFilePath
6925            
6926             Description:
6927            
6928             Returns the _trainFilePath member variable set during Word2vec::Word2vec object instantiation of new function.
6929            
6930             Input:
6931            
6932             None
6933            
6934             Output:
6935            
6936             $string -> Returns word2vec training text corpus file path.
6937            
6938             Example:
6939            
6940             use Word2vec::Interface;
6941            
6942             my $interface = Word2vec::Interface->new();
6943             my $filePath = $interface->W2VGetTrainFilePath();
6944             print( "Training File Path: $filePath\n" );
6945            
6946             undef( $interface );
6947            
6948             =head3 W2VGetOutputFilePath
6949            
6950             Description:
6951            
6952             Returns the _outputFilePath member variable set during Word2vec::Word2vec object instantiation of new function.
6953            
6954             Input:
6955            
6956             None
6957            
6958             Output:
6959            
6960             $string -> Returns post word2vec training output file path.
6961            
6962             Example:
6963            
6964             use Word2vec::Interface;
6965            
6966             my $interface = Word2vec::Interface->new();
6967             my $filePath = $interface->W2VGetOutputFilePath();
6968             print( "File Path: $filePath\n" );
6969            
6970             undef( $interface );
6971            
6972             =head3 W2VGetWordVecSize
6973            
6974             Description:
6975            
6976             Returns the _wordVecSize member variable set during Word2vec::Word2vec object instantiation of new function.
6977            
6978             Input:
6979            
6980             None
6981            
6982             Output:
6983            
6984             $value -> Returns (integer) size of word2vec word vectors. Default value = 100
6985            
6986             Example:
6987            
6988             use Word2vec::Interface;
6989            
6990             my $interface = Word2vec::Interface->new();
6991             my $value = $interface->W2VGetWordVecSize();
6992             print( "Word Vector Size: $value\n" );
6993            
6994             undef( $interface );
6995            
6996             =head3 W2VGetWindowSize
6997            
6998             Description:
6999            
7000             Returns the _windowSize member variable set during Word2vec::Word2vec object instantiation of new function.
7001            
7002             Input:
7003            
7004             None
7005            
7006             Output:
7007            
7008             $value -> Returns (integer) word2vec window size. Default value = 5
7009            
7010             Example:
7011            
7012             use Word2vec::Interface;
7013            
7014             my $interface = Word2vec::Interface->new();
7015             my $value = $interface->W2VGetWindowSize();
7016             print( "Window Size: $value\n" );
7017            
7018             undef( $interface );
7019            
7020             =head3 W2VGetSample
7021            
7022             Description:
7023            
7024             Returns the _sample member variable set during Word2vec::Word2vec object instantiation of new function.
7025            
7026             Input:
7027            
7028             None
7029            
7030             Output:
7031            
7032             $value -> Returns (integer) word2vec sample size. Default value = 0.001
7033            
7034             Example:
7035            
7036             use Word2vec::Interface;
7037            
7038             my $interface = Word2vec::Interface->new();
7039             my $value = $interface->W2VGetSample();
7040             print( "Sample: $value\n" );
7041            
7042             undef( $interface );
7043            
7044             =head3 W2VGetHSoftMax
7045            
7046             Description:
7047            
7048             Returns the _hSoftMax member variable set during Word2vec::Word2vec object instantiation of new function.
7049            
7050             Input:
7051            
7052             None
7053            
7054             Output:
7055            
7056             $value -> Returns (integer) word2vec HSoftMax value. Default = 0
7057            
7058             Example:
7059            
7060             use Word2vec::Interface;
7061            
7062             my $interface = Word2vec::Interface->new();
7063             my $value = $interface->W2VGetHSoftMax();
7064             print( "HSoftMax: $value\n" );
7065            
7066             undef( $interface );
7067            
7068             =head3 W2VGetNegative
7069            
7070             Description:
7071            
7072             Returns the _negative member variable set during Word2vec::Word2vec object instantiation of new function.
7073            
7074             Input:
7075            
7076             None
7077            
7078             Output:
7079            
7080             $value -> Returns (integer) word2vec negative value. Default = 5
7081            
7082             Example:
7083            
7084             use Word2vec::Interface;
7085            
7086             my $interface = Word2vec::Interface->new();
7087             my $value = $interface->W2VGetNegative();
7088             print( "Negative: $value\n" );
7089            
7090             undef( $interface );
7091            
7092             =head3 W2VGetNumOfThreads
7093            
7094             Description:
7095            
7096             Returns the _numOfThreads member variable set during Word2vec::Word2vec object instantiation of new function.
7097            
7098             Input:
7099            
7100             None
7101            
7102             Output:
7103            
7104             $value -> Returns (integer) word2vec number of threads to use during training. Default = 12
7105            
7106             Example:
7107            
7108             use Word2vec::Interface;
7109            
7110             my $interface = Word2vec::Interface->new();
7111             my $value = $interface->W2VGetNumOfThreads();
7112             print( "Number of threads: $value\n" );
7113            
7114             undef( $interface );
7115            
7116             =head3 W2VGetNumOfIterations
7117            
7118             Description:
7119            
7120             Returns the _iterations member variable set during Word2vec::Word2vec object instantiation of new function.
7121            
7122             Input:
7123            
7124             None
7125            
7126             Output:
7127            
7128             $value -> Returns (integer) word2vec number of word2vec iterations. Default = 5
7129            
7130             Example:
7131            
7132             use Word2vec::Interface;
7133            
7134             my $interface = Word2vec::Interface->new();
7135             my $value = $interface->W2VGetNumOfIterations();
7136             print( "Number of iterations: $value\n" );
7137            
7138             undef( $interface );
7139            
7140             =head3 W2VGetMinCount
7141            
7142             Description:
7143            
7144             Returns the _minCount member variable set during Word2vec::Word2vec object instantiation of new function.
7145            
7146             Input:
7147            
7148             None
7149            
7150             Output:
7151            
7152             $value -> Returns (integer) word2vec min-count value. Default = 5
7153            
7154             Example:
7155            
7156             use Word2vec::Interface;
7157            
7158             my $interface = Word2vec::Interface->new();
7159             my $value = $interface->W2VGetMinCount();
7160             print( "Min Count: $value\n" );
7161            
7162             undef( $interface );
7163            
7164             =head3 W2VGetAlpha
7165            
7166             Description:
7167            
7168             Returns the _alpha member variable set during Word2vec::Word2vec object instantiation of new function.
7169            
7170             Input:
7171            
7172             None
7173            
7174             Output:
7175            
7176             $value -> Returns (integer) word2vec alpha value. Default = 0.05 for CBOW and 0.025 for Skip-Gram.
7177            
7178             Example:
7179            
7180             use Word2vec::Interface;
7181            
7182             my $interface = Word2vec::Interface->new();
7183             my $value = $interface->W2VGetAlpha();
7184             print( "Alpha: $value\n" );
7185            
7186             undef( $interface );
7187            
7188             =head3 W2VGetClasses
7189            
7190             Description:
7191            
7192             Returns the _classes member variable set during Word2vec::Word2vec object instantiation of new function.
7193            
7194             Input:
7195            
7196             None
7197            
7198             Output:
7199            
7200             $value -> Returns (integer) word2vec classes value. Default = 0
7201            
7202             Example:
7203            
7204             use Word2vec::Interface;
7205            
7206             my $interface = Word2vec::Interface->new();
7207             my $value = $interface->W2VGetClasses();
7208             print( "Classes: $value\n" );
7209            
7210             undef( $interface );
7211            
7212             =head3 W2VGetDebugTraining
7213            
7214             Description:
7215            
7216             Returns the _debug member variable set during Word2vec::Word2vec object instantiation of new function.
7217            
7218             Note: 0 = No debug output, 1 = Enable debug output, 2 = Even more debug output
7219            
7220             Input:
7221            
7222             None
7223            
7224             Output:
7225            
7226             $value -> Returns (integer) word2vec debug value. Default = 2
7227            
7228             Example:
7229            
7230             use Word2vec::Interface;
7231            
7232             my $interface = Word2vec::Interface->new();
7233             my $value = $interface->W2VGetDebugTraining();
7234             print( "Debug: $value\n" );
7235            
7236             undef( $interface );
7237            
7238             =head3 W2VGetBinaryOutput
7239            
7240             Description:
7241            
7242             Returns the _binaryOutput member variable set during Word2vec::Word2vec object instantiation of new function.
7243            
7244             Note: 1 = Save trained vector data in binary format, 2 = Save trained vector data in plain text format.
7245            
7246             Input:
7247            
7248             None
7249            
7250             Output:
7251            
7252             $value -> Returns (integer) word2vec binary flag. Default = 0
7253            
7254             Example:
7255            
7256             use Word2vec::Interface;
7257            
7258             my $interface = Word2vec::Interface->new();
7259             my $value = $interface->W2VGetBinaryOutput();
7260             print( "Binary Output: $value\n" );
7261            
7262             undef( $interface );
7263            
7264             =head3 W2VGetReadVocabFilePath
7265            
7266             Description:
7267            
7268             Returns the _readVocab member variable set during Word2vec::Word2vec object instantiation of new function.
7269            
7270             Input:
7271            
7272             None
7273            
7274             Output:
7275            
7276             $string -> Returns (string) word2vec read vocabulary file name or empty string if not set.
7277            
7278             Example:
7279            
7280             use Word2vec::Interface;
7281            
7282             my $interface = Word2vec::Interface->new();
7283             my $str = $interface->W2VGetReadVocabFilePath();
7284             print( "Read Vocab File Path: $str\n" );
7285            
7286             undef( $interface );
7287            
7288             =head3 W2VGetSaveVocabFilePath
7289            
7290             Description:
7291            
7292             Returns the _saveVocab member variable set during Word2vec::Word2vec object instantiation of new function.
7293            
7294             Input:
7295            
7296             None
7297            
7298             Output:
7299            
7300             $string -> Returns (string) word2vec save vocabulary file name or empty string if not set.
7301            
7302             Example:
7303            
7304             use Word2vec::Interface;
7305            
7306             my $interface = Word2vec::Interface->new();
7307             my $str = $interface->W2VGetSaveVocabFilePath();
7308             print( "Save Vocab File Path: $str\n" );
7309            
7310             undef( $interface );
7311            
7312             =head3 W2VGetUseCBOW
7313            
7314             Description:
7315            
7316             Returns the _useCBOW member variable set during Word2vec::Word2vec object instantiation of new function.
7317            
7318             Note: 0 = Skip-Gram Model, 1 = Continuous Bag Of Words Model.
7319            
7320             Input:
7321            
7322             None
7323            
7324             Output:
7325            
7326             $value -> Returns (integer) word2vec Continuous-Bag-Of-Words flag. Default = 1
7327            
7328             Example:
7329            
7330             use Word2vec::Interface;
7331            
7332             my $interface = Word2vec::Interface->new();
7333             my $value = $interface->W2VGetUseCBOW();
7334             print( "Use CBOW?: $value\n" );
7335            
7336             undef( $interface );
7337            
7338             =head3 W2VGetWorkingDir
7339            
7340             Description:
7341            
7342             Returns the _workingDir member variable set during Word2vec::Word2vec object instantiation of new function.
7343            
7344             Input:
7345            
7346             None
7347            
7348             Output:
7349            
7350             $value -> Returns (string) working directory path or current directory if not specified.
7351            
7352             Example:
7353            
7354             use Word2vec::Interface;
7355            
7356             my $interface = Word2vec::Interface->new();
7357             my $str = $interface->W2VGetWorkingDir();
7358             print( "Working Directory: $str\n" );
7359            
7360             undef( $interface );
7361            
7362             =head3 W2VGetWord2VecExeDir
7363            
7364             Description:
7365            
7366             Returns the _word2VecExeDir member variable set during Word2vec::Word2vec object instantiation of new function.
7367            
7368             Input:
7369            
7370             None
7371            
7372             Output:
7373            
7374             $value -> Returns (string) word2vec executable directory path or empty string if not specified.
7375            
7376             Example:
7377            
7378             use Word2vec::Interface;
7379            
7380             my $interface = Word2vec::Interface->new();
7381             my $str = $interface->W2VGetWord2VecExeDir();
7382             print( "Word2Vec Executable File Directory: $str\n" );
7383            
7384             undef( $interface );
7385            
7386             =head3 W2VGetVocabularyHash
7387            
7388             Description:
7389            
7390             Returns the _hashRefOfWordVectors member variable set during Word2vec::Word2vec object instantiation of new function.
7391            
7392             Input:
7393            
7394             None
7395            
7396             Output:
7397            
7398             $value -> Returns hash reference of vocabulary/dictionary words. (Word2vec trained data in memory)
7399            
7400             Example:
7401            
7402             use Word2vec::Interface;
7403            
7404             my $interface = Word2vec::Interface->new();
7405             my @vocabulary = $interface->W2VGetVocabularyHash();
7406            
7407             undef( $interface );
7408            
7409             =head3 W2VGetOverwriteOldFile
7410            
7411             Description:
7412            
7413             Returns the _overwriteOldFile member variable set during Word2vec::Word2vec object instantiation of new function.
7414            
7415             Input:
7416            
7417             None
7418            
7419             Output:
7420            
7421             $value -> Returns 1 = True or 0 = False.
7422            
7423             Example:
7424            
7425             use Word2vec::Interface;
7426            
7427             my $interface = Word2vec::Interface->new();
7428             my $value = $interface->W2VGetOverwriteOldFile();
7429             print( "Overwrite Exiting File?: $value\n" );
7430            
7431             undef( $interface );
7432            
7433             =head2 Word2Vec Mutator Functions
7434            
7435             =head3 W2VSetTrainFilePath
7436            
7437             Description:
7438            
7439             Sets member variable to string parameter. Sets training file path.
7440            
7441             Input:
7442            
7443             $string -> Text corpus training file path
7444            
7445             Output:
7446            
7447             None
7448            
7449             Example:
7450            
7451             use Word2vec::Interface;
7452            
7453             my $interface = Word2vec::Interface->new();
7454             $interface->W2VSetTrainFilePath( "samples/textcorpus.txt" );
7455            
7456             undef( $interface );
7457            
7458             =head3 W2VSetOutputFilePath
7459            
7460             Description:
7461            
7462             Sets member variable to string parameter. Sets output file path.
7463            
7464             Input:
7465            
7466             $string -> Post word2vec training save file path
7467            
7468             Output:
7469            
7470             None
7471            
7472             Example:
7473            
7474             use Word2vec::Interface;
7475            
7476             my $interface = Word2vec::Interface->new();
7477             $interface->W2VSetOutputFilePath( "samples/tempvectors.bin" );
7478            
7479             undef( $interface );
7480            
7481             =head3 W2VSetWordVecSize
7482            
7483             Description:
7484            
7485             Sets member variable to integer parameter. Sets word2vec word vector size.
7486            
7487             Input:
7488            
7489             $value -> Word2vec word vector size
7490            
7491             Output:
7492            
7493             None
7494            
7495             Example:
7496            
7497             use Word2vec::Interface;
7498            
7499             my $interface = Word2vec::Interface->new();
7500             $interface->W2VSetWordVecSize( 100 );
7501            
7502             undef( $interface );
7503            
7504             =head3 W2VSetWindowSize
7505            
7506             Description:
7507            
7508             Sets member variable to integer parameter. Sets word2vec window size.
7509            
7510             Input:
7511            
7512             $value -> Word2vec window size
7513            
7514             Output:
7515            
7516             None
7517            
7518             Example:
7519            
7520             use Word2vec::Interface;
7521            
7522             my $interface = Word2vec::Interface->new();
7523             $interface->W2VSetWindowSize( 8 );
7524            
7525             undef( $interface );
7526            
7527             =head3 W2VSetSample
7528            
7529             Description:
7530            
7531             Sets member variable to integer parameter. Sets word2vec sample size.
7532            
7533             Input:
7534            
7535             $value -> Word2vec sample size
7536            
7537             Output:
7538            
7539             None
7540            
7541             Example:
7542            
7543             use Word2vec::Interface;
7544            
7545             my $interface = Word2vec::Interface->new();
7546             $interface->W2VSetSample( 3 );
7547            
7548             undef( $interface );
7549            
7550             =head3 W2VSetHSoftMax
7551            
7552             Description:
7553            
7554             Sets member variable to integer parameter. Sets word2vec HSoftMax value.
7555            
7556             Input:
7557            
7558             $value -> Word2vec HSoftMax size
7559            
7560             Output:
7561            
7562             None
7563            
7564             Example:
7565            
7566             use Word2vec::Interface;
7567            
7568             my $interface = Word2vec::Interface->new();
7569             $interface->W2VSetHSoftMax( 12 );
7570            
7571             undef( $interface );
7572            
7573             =head3 W2VSetNegative
7574            
7575             Description:
7576            
7577             Sets member variable to integer parameter. Sets word2vec negative value.
7578            
7579             Input:
7580            
7581             $value -> Word2vec negative value
7582            
7583             Output:
7584            
7585             None
7586            
7587             Example:
7588            
7589             use Word2vec::Interface;
7590            
7591             my $interface = Word2vec::Interface->new();
7592             $interface->W2VSetNegative( 12 );
7593            
7594             undef( $interface );
7595            
7596             =head3 W2VSetNumOfThreads
7597            
7598             Description:
7599            
7600             Sets member variable to integer parameter. Sets word2vec number of training threads to specified value.
7601            
7602             Input:
7603            
7604             $value -> Word2vec number of threads value
7605            
7606             Output:
7607            
7608             None
7609            
7610             Example:
7611            
7612             use Word2vec::Interface;
7613            
7614             my $interface = Word2vec::Interface->new();
7615             $interface->W2VSetNumOfThreads( 12 );
7616            
7617             undef( $interface );
7618            
7619             =head3 W2VSetNumOfIterations
7620            
7621             Description:
7622            
7623             Sets member variable to integer parameter. Sets word2vec iterations value.
7624            
7625             Input:
7626            
7627             $value -> Word2vec number of iterations value
7628            
7629             Output:
7630            
7631             None
7632            
7633             Example:
7634            
7635             use Word2vec::Interface;
7636            
7637             my $interface = Word2vec::Interface->new();
7638             $interface->W2VSetNumOfIterations( 12 );
7639            
7640             undef( $interface );
7641            
7642             =head3 W2VSetMinCount
7643            
7644             Description:
7645            
7646             Sets member variable to integer parameter. Sets word2vec min-count value.
7647            
7648             Input:
7649            
7650             $value -> Word2vec min-count value
7651            
7652             Output:
7653            
7654             None
7655            
7656             Example:
7657            
7658             use Word2vec::Interface;
7659            
7660             my $interface = Word2vec::Interface->new();
7661             $interface->W2VSetMinCount( 7 );
7662            
7663             undef( $interface );
7664            
7665             =head3 W2VSetAlpha
7666            
7667             Description:
7668            
7669             Sets member variable to float parameter. Sets word2vec alpha value.
7670            
7671             Input:
7672            
7673             $value -> Word2vec alpha value. (Float)
7674            
7675             Output:
7676            
7677             None
7678            
7679             Example:
7680            
7681             use Word2vec::Interface;
7682            
7683             my $interface = Word2vec::Interface->new();
7684             $interface->SetAlpha( 0.0012 );
7685            
7686             undef( $interface );
7687            
7688             =head3 W2VSetClasses
7689            
7690             Description:
7691            
7692             Sets member variable to integer parameter. Sets word2vec classes value.
7693            
7694             Input:
7695            
7696             $value -> Word2vec classes value.
7697            
7698             Output:
7699            
7700             None
7701            
7702             Example:
7703            
7704             use Word2vec::Interface;
7705            
7706             my $interface = Word2vec::Interface->new();
7707             $interface->W2VSetClasses( 0 );
7708            
7709             undef( $interface );
7710            
7711             =head3 W2VSetDebugTraining
7712            
7713             Description:
7714            
7715             Sets member variable to integer parameter. Sets word2vec debug parameter value.
7716            
7717             Input:
7718            
7719             $value -> Word2vec debug training value.
7720            
7721             Output:
7722            
7723             None
7724            
7725             Example:
7726            
7727             use Word2vec::Interface;
7728            
7729             my $interface = Word2vec::Interface->new();
7730             $interface->W2VSetDebugTraining( 0 );
7731            
7732             undef( $interface );
7733            
7734             =head3 W2VSetBinaryOutput
7735            
7736             Description:
7737            
7738             Sets member variable to integer parameter. Sets word2vec binary parameter value.
7739            
7740             Input:
7741            
7742             $value -> Word2vec binary output mode value. ( '1' = Binary Output / '0' = Plain Text )
7743            
7744             Output:
7745            
7746             None
7747            
7748             Example:
7749            
7750             use Word2vec::Interface;
7751            
7752             my $interface = Word2vec::Interface->new();
7753             $interface->W2VSetBinaryOutput( 1 );
7754            
7755             undef( $interface );
7756            
7757             =head3 W2VSetSaveVocabFilePath
7758            
7759             Description:
7760            
7761             Sets member variable to string parameter. Sets word2vec save vocabulary file name.
7762            
7763             Input:
7764            
7765             $string -> Word2vec save vocabulary file name and path.
7766            
7767             Output:
7768            
7769             None
7770            
7771             Example:
7772            
7773             use Word2vec::Interface;
7774            
7775             my $interface = Word2vec::Interface->new();
7776             $interface->W2VSetSaveVocabFilePath( "samples/vocab.txt" );
7777            
7778             undef( $interface );
7779            
7780             =head3 W2VSetReadVocabFilePath
7781            
7782             Description:
7783            
7784             Sets member variable to string parameter. Sets word2vec read vocabulary file name.
7785            
7786             Input:
7787            
7788             $string -> Word2vec read vocabulary file name and path.
7789            
7790             Output:
7791            
7792             None
7793            
7794             Example:
7795            
7796             use Word2vec::Interface;
7797            
7798             my $interface = Word2vec::Interface->new();
7799             $interface->W2VSetReadVocabFilePath( "samples/vocab.txt" );
7800            
7801             undef( $interface );
7802            
7803             =head3 W2VSetUseCBOW
7804            
7805             Description:
7806            
7807             Sets member variable to integer parameter. Sets word2vec CBOW parameter value.
7808            
7809             Input:
7810            
7811             $value -> Word2vec CBOW mode value.
7812            
7813             Output:
7814            
7815             None
7816            
7817             Example:
7818            
7819             use Word2vec::Interface;
7820            
7821             my $interface = Word2vec::Interface->new();
7822             $interface->W2VSetUseCBOW( 1 );
7823            
7824             undef( $interface );
7825            
7826             =head3 W2VSetWorkingDir
7827            
7828             Description:
7829            
7830             Sets member variable to string parameter. Sets working directory.
7831            
7832             Input:
7833            
7834             $string -> Working directory
7835            
7836             Output:
7837            
7838             None
7839            
7840             Example:
7841            
7842             use Word2vec::Interface;
7843            
7844             my $interface = Word2vec::Interface->new();
7845             $interface->W2VSetWorkingDir( "/samples" );
7846            
7847             undef( $interface );
7848            
7849             =head3 W2VSetWord2VecExeDir
7850            
7851             Description:
7852            
7853             Sets member variable to string parameter. Sets word2vec executable file directory.
7854            
7855             Input:
7856            
7857             $string -> Word2vec directory
7858            
7859             Output:
7860            
7861             None
7862            
7863             Example:
7864            
7865             use Word2vec::Interface;
7866            
7867             my $interface = Word2vec::Interface->new();
7868             $interface->W2VSetWord2VecExeDir( "/word2vec" );
7869            
7870             undef( $interface );
7871            
7872             =head3 W2VSetVocabularyHash
7873            
7874             Description:
7875            
7876             Sets vocabulary/dictionary hash reference to hash reference parameter.
7877            
7878             Warning: This will overwrite any existing vocabulary/dictionary data in memory.
7879            
7880             Input:
7881            
7882             $hashReference -> Vocabulary/Dictionary hash reference of word2vec word vectors.
7883            
7884             Output:
7885            
7886             None
7887            
7888             Example:
7889            
7890             use Word2vec::Interface;
7891            
7892             my $interface = Word2vec::Interface->new();
7893             $interface->W2VReadTrainedVectorDataFromFile( "samples/samplevectors.bin" );
7894             my $vocabularyHasReference = $interface->W2VGetVocabularyHash();
7895             $interface->W2VSetVocabularyHash( $vocabularyHasReference );
7896            
7897             undef( $interface );
7898            
7899             =head3 W2VClearVocabularyHash
7900            
7901             Description:
7902            
7903             Clears vocabulary/dictionary hash.
7904            
7905             Input:
7906            
7907             None
7908            
7909             Output:
7910            
7911             None
7912            
7913             Example:
7914            
7915             use Word2vec::Interface;
7916            
7917             my $interface = Word2vec::Interface->new();
7918             $interface->W2VClearVocabularyHash();
7919            
7920             undef( $interface );
7921            
7922             =head3 W2VAddWordVectorToVocabHash
7923            
7924             Description:
7925            
7926             Adds word vector string to vocabulary/dictionary.
7927            
7928             Input:
7929            
7930             $string -> Word2vec word vector string
7931            
7932             Output:
7933            
7934             None
7935            
7936             Example:
7937            
7938             use Word2vec::Interface;
7939            
7940             my $interface = Word2vec::Interface->new();
7941            
7942             # Note: This is representational data of word2vec's word vector format and not actual data.
7943             $interface->W2VAddWordVectorToVocabHash( "of 0.4346 -0.1235 0.5789 0.2347 -0.0056 -0.0001" );
7944            
7945             undef( $interface );
7946            
7947             =head3 W2VSetOverwriteOldFile
7948            
7949             Description:
7950            
7951             Sets member variable to integer parameter. Enables overwriting output file if one already exists.
7952            
7953             Input:
7954            
7955             $value -> '1' = Overwrite exiting file / '0' = Graceful termination when file with same name exists
7956            
7957             Output:
7958            
7959             None
7960            
7961             Example:
7962            
7963             use Word2vec::Interface;
7964            
7965             my $interface = Word2vec::Interface->new();
7966             $interface->W2VSetOverwriteOldFile( 1 );
7967            
7968             undef( $interface );
7969            
7970             =head2 Word2Phrase Main Functions
7971            
7972             =head3 W2PExecuteTraining
7973            
7974             Description:
7975            
7976             Executes word2phrase training based on parameters. Parameter variables have higher precedence than member variables.
7977             Any parameter specified will override its respective member variable.
7978            
7979             Note: If no parameters are specified, this module executes word2phrase training based on preset member
7980             variables. Returns string regarding training status.
7981            
7982             Input:
7983            
7984             $trainFilePath -> Training text corpus file path
7985             $outputFilePath -> Vector binary file path
7986             $minCount -> Minimum bi-gram frequency (Positive Integer)
7987             $threshold -> Maximum bi-gram frequency (Positive Integer)
7988             $debug -> Displays word2phrase debug information during training. (0 = None, 1 = Show Debug Information, 2 = Show Even More Debug Information)
7989             $overwrite -> Overwrites old training file when executing training. (0 = False / 1 = True)
7990            
7991             Output:
7992            
7993             $value -> '0' = Successful / '-1' = Un-successful
7994            
7995             Example:
7996            
7997             use Word2vec::Interface;
7998            
7999             my $interface = Word2vec::Interface->new();
8000             $interface->W2PSetMinCount( 12 );
8001             $interface->W2PSetMaxCount( 20 );
8002             $interface->W2PSetTrainFilePath( "textCorpus.txt" );
8003             $interface->W2PSetOutputFilePath( "phraseTextCorpus.txt" );
8004             $interface->W2PExecuteTraining();
8005             undef( $interface );
8006            
8007             # Or
8008            
8009             use Word2vec::Interface;
8010            
8011             my $interface = Word2vec::Interface->new();
8012             $interface->W2PExecuteTraining( "textCorpus.txt", "phraseTextCorpus.txt", 12, 20, 2, 1 );
8013             undef( $interface );
8014            
8015             =head3 W2PExecuteStringTraining
8016            
8017             Description:
8018            
8019             Executes word2phrase training based on parameters. Parameter variables have higher precedence than member variables.
8020             Any parameter specified will override its respective member variable.
8021            
8022             Note: If no parameters are specified, this module executes word2phrase training based on preset member
8023             variables. Returns string regarding training status.
8024            
8025             Input:
8026            
8027             $trainingString -> String to train
8028             $outputFilePath -> Vector binary file path
8029             $minCount -> Minimum bi-gram frequency (Positive Integer)
8030             $threshold -> Maximum bi-gram frequency (Positive Integer)
8031             $debug -> Displays word2phrase debug information during training. (0 = None, 1 = Show Debug Information, 2 = Show Even More Debug Information)
8032             $overwrite -> Overwrites old training file when executing training. (0 = False / 1 = True)
8033            
8034             Output:
8035            
8036             $value -> '0' = Successful / '-1' = Un-successful
8037            
8038             Example:
8039            
8040             use Word2vec::Interface;
8041            
8042             my $interface = Word2vec::Interface->new();
8043             $interface->W2PSetMinCount( 12 );
8044             $interface->W2PSetMaxCount( 20 );
8045             $interface->W2PSetTrainFilePath( "large string to train here" );
8046             $interface->W2PSetOutputFilePath( "phraseTextCorpus.txt" );
8047             $interface->W2PExecuteTraining();
8048             undef( $interface );
8049            
8050             # Or
8051            
8052             use Word2vec::Interface;
8053            
8054             my $interface = Word2vec::Interface->new();
8055             $interface->W2PExecuteTraining( "large string to train here", "phraseTextCorpus.txt", 12, 20, 2, 1 );
8056             undef( $interface );
8057            
8058             =head2 Word2Phrase Accessor Functions
8059            
8060             =head3 W2PGetDebugLog
8061            
8062             Description:
8063            
8064             Returns the _debugLog member variable set during Word2vec::Interface object initialization of new function.
8065            
8066             Input:
8067            
8068             None
8069            
8070             Output:
8071            
8072             $value -> 0 = False, 1 = True
8073            
8074             Example:
8075            
8076             use Word2vec::Interface;
8077            
8078             my $interface = Word2vec::Interface->new();
8079             my $debugLog = $interface->W2PGetDebugLog();
8080            
8081             print( "Debug Logging Enabled\n" ) if $debugLog == 1;
8082             print( "Debug Logging Disabled\n" ) if $debugLog == 0;
8083            
8084             undef( $interface );
8085            
8086             =head3 W2PGetWriteLog
8087            
8088             Description:
8089            
8090             Returns the _writeLog member variable set during Word2vec::Interface object initialization of new function.
8091            
8092             Input:
8093            
8094             None
8095            
8096             Output:
8097            
8098             $value -> 0 = False, 1 = True
8099            
8100             Example:
8101            
8102             use Word2vec::Interface;
8103            
8104             my $interface = Word2vec::Interface->new();
8105             my $writeLog = $interface->W2PGetWriteLog();
8106            
8107             print( "Write Logging Enabled\n" ) if $writeLog == 1;
8108             print( "Write Logging Disabled\n" ) if $writeLog == 0;
8109            
8110             undef( $interface );
8111            
8112             =head3 W2PGetFileHandle
8113            
8114             Description:
8115            
8116             Returns file handle used by word2phrase::WriteLog() method.
8117            
8118             Input:
8119            
8120             None
8121            
8122             Output:
8123            
8124             $fileHandle -> Returns file handle blob used by 'WriteLog()' function or undefined.
8125            
8126             Example:
8127            
8128            
8129            
8130             =head3 W2PGetTrainFilePath
8131            
8132             Description:
8133            
8134             Returns (string) training file path.
8135            
8136             Input:
8137            
8138             None
8139            
8140             Output:
8141            
8142             $string -> word2phrase training file path
8143            
8144             Example:
8145            
8146             use Word2vec::Interface;
8147            
8148             my $interface = Word2vec::Interface->new();
8149             my $filePath = $interface->W2PGetTrainFilePath();
8150            
8151             print( "Output File Path: $filePath\n" ) if defined( $filePath );
8152             undef( $interface );
8153            
8154             =head3 W2PGetOutputFilePath
8155            
8156             Description:
8157            
8158             Returns (string) output file path.
8159            
8160             Input:
8161            
8162             None
8163            
8164             Output:
8165            
8166             $string -> word2phrase output file path
8167            
8168             Example:
8169            
8170             use Word2vec::Interface;
8171            
8172             my $interface = Word2vec::Interface->new();
8173             my $filePath = $interface->W2PGetOutputFilePath();
8174            
8175             print( "Output File Path: $filePath\n" ) if defined( $filePath );
8176             undef( $interface );
8177            
8178             =head3 W2PGetMinCount
8179            
8180             Description:
8181            
8182             Returns (integer) minimum bi-gram range.
8183            
8184             Input:
8185            
8186             None
8187            
8188             Output:
8189            
8190             $value -> Minimum bi-gram frequency (Positive Integer)
8191            
8192             Example:
8193            
8194             use Word2vec::Interface;
8195            
8196             my $interface = Word2vec::Interface->new();
8197             my $mincount = $interface->W2PGetMinCount();
8198            
8199             print( "MinCount: $mincount\n" ) if defined( $mincount );
8200             undef( $interface );
8201            
8202             =head3 W2PGetThreshold
8203            
8204             Description:
8205            
8206             Returns (integer) maximum bi-gram range.
8207            
8208             Input:
8209            
8210             None
8211            
8212             Output:
8213            
8214             $value -> Maximum bi-gram frequency (Positive Integer)
8215            
8216             Example:
8217            
8218             use Word2vec::Interface;
8219            
8220             my $interface = Word2vec::Interface->new();
8221             my $mincount = $interface->W2PGetThreshold();
8222            
8223             print( "MinCount: $mincount\n" ) if defined( $mincount );
8224             undef( $interface );
8225            
8226             =head3 W2PGetW2PDebug
8227            
8228             Description:
8229            
8230             Returns word2phrase debug parameter value.
8231            
8232             Input:
8233            
8234             None
8235            
8236             Output:
8237            
8238             $value -> 0 = No debugging, 1 = Show debugging, 2 = Show even more debugging
8239            
8240             Example:
8241            
8242             use Word2vec::Interface;
8243            
8244             my $interface = Word2vec::Interface->new();
8245             my $interfacedebug = $interface->W2PGetW2PDebug();
8246            
8247             print( "Word2Phrase Debug Level: $interfacedebug\n" ) if defined( $interfacedebug );
8248            
8249             undef( $interface );
8250            
8251             =head3 W2PGetWorkingDir
8252            
8253             Description:
8254            
8255             Returns (string) working directory path.
8256            
8257             Input:
8258            
8259             None
8260            
8261             Output:
8262            
8263             $string -> Current working directory path
8264            
8265             Example:
8266            
8267             use Word2vec::Interface;
8268            
8269             my $interface = Word2vec::Interface->new();
8270             my $workingDir = $interface->W2PGetWorkingDir();
8271            
8272             print( "Working Directory: $workingDir\n" ) if defined( $workingDir );
8273            
8274             undef( $interface );
8275            
8276             =head3 W2PGetWord2PhraseExeDir
8277            
8278             Description:
8279            
8280             Returns (string) word2phrase executable directory path.
8281            
8282             Input:
8283            
8284             None
8285            
8286             Output:
8287            
8288             $string -> Word2Phrase executable directory path
8289            
8290             Example:
8291            
8292             use Word2vec::Interface;
8293            
8294             my $interface = Word2vec::Interface->new();
8295             my $workingDir = $interface->W2PGetWord2PhraseExeDir();
8296            
8297             print( "Word2Phrase Executable Directory: $workingDir\n" ) if defined( $workingDir );
8298            
8299             undef( $interface );
8300            
8301             =head3 W2PGetOverwriteOldFile
8302            
8303             Description:
8304            
8305             Returns the current value of the overwrite training file variable.
8306            
8307             Input:
8308            
8309             None
8310            
8311             Output:
8312            
8313             $value -> 1 = True/Overwrite or 0 = False/Append to current file
8314            
8315             Example:
8316            
8317             use Word2vec::Interface;
8318            
8319             my $interface = Word2vec::Interface->new();
8320             my $overwrite = $interface->W2PGetOverwriteOldFile();
8321            
8322             if defined( $overwrite )
8323             {
8324             print( "Overwrite Old File: " );
8325             print( "Yes\n" ) if $overwrite == 1;
8326             print( "No\n" ) if $overwrite == 0;
8327             }
8328            
8329             undef( $interface );
8330            
8331             =head2 Word2Phrase Mutator Functions
8332            
8333             =head3 W2PSetTrainFilePath
8334            
8335             Description:
8336            
8337             Sets training file path.
8338            
8339             Input:
8340            
8341             $string -> Training file path
8342            
8343             Output:
8344            
8345             None
8346            
8347             Example:
8348            
8349             use Word2vec::Interface;
8350            
8351             my $interface = Word2vec::Interface->new();
8352             $interface->W2PSetTrainFilePath( "filePath" );
8353            
8354             undef( $interface );
8355            
8356             =head3 W2PSetOutputFilePath
8357            
8358             Description:
8359            
8360             Sets word2phrase output file path.
8361            
8362             Input:
8363            
8364             $string -> word2phrase output file path
8365            
8366             Output:
8367            
8368             None
8369            
8370             Example:
8371            
8372             use Word2vec::Interface;
8373            
8374             my $interface = Word2vec::Interface->new();
8375             $interface->W2PSetOutputFilePath( "filePath" );
8376            
8377             undef( $interface );
8378            
8379             =head3 W2PSetMinCount
8380            
8381             Description:
8382            
8383             Sets minimum range value.
8384            
8385             Input:
8386            
8387             $value -> Minimum frequency value (Positive integer)
8388            
8389             Output:
8390            
8391             None
8392            
8393             Example:
8394            
8395             use Word2vec::Interface:
8396            
8397             my $interface = Word2vec::Interface->new();
8398             $interface->W2PSetMinCount( 1 );
8399            
8400             undef( $interface );
8401            
8402             =head3 W2PSetThreshold
8403            
8404             Description:
8405            
8406             Sets maximum range value.
8407            
8408             Input:
8409            
8410             $value -> Maximum frequency value (Positive integer)
8411            
8412             Output:
8413            
8414             None
8415            
8416             Example:
8417            
8418             use Word2vec::Interface:
8419            
8420             my $interface = Word2vec::Interface->new();
8421             $interface->W2PSetThreshold( 100 );
8422            
8423             undef( $interface );
8424            
8425             =head3 W2PSetW2PDebug
8426            
8427             Description:
8428            
8429             Sets word2phrase debug parameter.
8430            
8431             Input:
8432            
8433             $value -> word2phrase debug parameter (0 = No debug info, 1 = Show debug info, 2 = Show more debug info.)
8434            
8435             Output:
8436            
8437             None
8438            
8439             Example:
8440            
8441             use Word2vec::Interface:
8442            
8443             my $interface = Word2vec::Interface->new();
8444             $interface->W2PSetW2PDebug( 2 );
8445            
8446             undef( $interface );
8447            
8448             =head3 W2PSetWorkingDir
8449            
8450             Description:
8451            
8452             Sets working directory path.
8453            
8454             Input:
8455            
8456             $string -> Current working directory path.
8457            
8458             Output:
8459            
8460             None
8461            
8462             Example:
8463            
8464             use Word2vec::Interface:
8465            
8466             my $interface = Word2vec::Interface->new();
8467             $interface->W2PSetWorkingDir( "filePath" );
8468            
8469             undef( $interface );
8470            
8471             =head3 W2PSetWord2PhraseExeDir
8472            
8473             Description:
8474            
8475             Sets word2phrase executable file directory path.
8476            
8477             Input:
8478            
8479             $string -> Word2Phrase executable directory path.
8480            
8481             Output:
8482            
8483             None
8484            
8485             Example:
8486            
8487             use Word2vec::Interface:
8488            
8489             my $interface = Word2vec::Interface->new();
8490             $interface->W2PSetWord2PhraseExeDir( "filePath" );
8491            
8492             undef( $interface );
8493            
8494             =head3 W2PSetOverwriteOldFile
8495            
8496             Description:
8497            
8498             Enables overwriting word2phrase output file if one already exists with the same output file name.
8499            
8500             Input:
8501            
8502             $value -> Integer: 1 = Overwrite old file, 0 = No not overwrite old file.
8503            
8504             Output:
8505            
8506             None
8507            
8508             Example:
8509            
8510             use Word2vec::Interface:
8511            
8512             my $interface = Word2vec::Interface->new();
8513             $interface->W2PSetOverwriteOldFile( 1 );
8514            
8515             undef( $interface );
8516            
8517             =head2 XMLToW2V Main Functions
8518            
8519             =head3 XTWConvertMedlineXMLToW2V
8520            
8521             Description:
8522            
8523             Parses specified parameter Medline XML file or directory of files, creating a text corpus. Returns 0 if successful or -1 during an error.
8524            
8525             Note: Supports plain Medline XML or gun-zipped XML files.
8526            
8527             Input:
8528            
8529             $filePath -> XML file path to parse. (This can be a single file or directory of XML/XML.gz files).
8530            
8531             Output:
8532            
8533             $value -> '0' = Successful / '-1' = Un-Successful
8534            
8535             Example:
8536            
8537             use Word2vec::Interface;
8538            
8539             $interface = Word2vec::Interface->new(); # Note: Specifying no parameters implies default settings
8540             $interface->XTWSetSavePath( "testCorpus.txt" );
8541             $interface->XTWSetStoreTitle( 1 );
8542             $interface->XTWSetStoreAbstract( 1 );
8543             $interface->XTWSetBeginDate( "01/01/2004" );
8544             $interface->XTWSetEndDate( "08/13/2016" );
8545             $interface->XTWSetOverwriteExistingFile( 1 );
8546             $interface->XTWConvertMedlineXMLToW2V( "/xmlDirectory/" );
8547             undef( $interface );
8548            
8549             =head3 XTWCreateCompoundWordBST
8550            
8551             Description:
8552            
8553             Creates a binary search tree using compound word data in memory and stores root node. This also clears the compound word array afterwards.
8554            
8555             Warning: Compound word file must be loaded into memory using XTWReadCompoundWordDataFromFile() prior to calling this method. This function
8556             will also delete the compound word array upon completion as it will no longer be necessary.
8557            
8558             Input:
8559            
8560             None
8561            
8562             Output:
8563            
8564             $value -> '0' = Successful / '-1' = Un-successful
8565            
8566             Example:
8567            
8568             use Word2vec::Interface;
8569            
8570             my $interface = Word2vec::Interface->new();
8571             $interface->XTWReadCompoundWordDataFromFile( "samples/compoundword.txt" );
8572             $interface->CreateCompoundWordBST();
8573            
8574             =head3 XTWCompoundifyString
8575            
8576             Description:
8577            
8578             Compoundifies string parameter based on compound word data in memory using the compound word binary search tree.
8579            
8580             Warning: Compound word file must be loaded into memory using XTWReadCompoundWordDataFromFile() prior to calling this method.
8581            
8582             Input:
8583            
8584             $string -> String to compoundify
8585            
8586             Output:
8587            
8588             $string -> Compounded string or "(null)" if string parameter is not defined.
8589            
8590             Example:
8591            
8592             use Word2vec::Interface;
8593            
8594             my $interface = Word2vec::Interface->new();
8595             $interface->XTWReadCompoundWordDataFromFile( "samples/compoundword.txt" );
8596             $interface->CreateCompoundWordBST();
8597             my $compoundedString = $interface->CompoundifyString( "String to compoundify" );
8598             print( "Compounded String: $compoundedString\n" );
8599            
8600             undef( $interface );
8601            
8602             =head3 XTWReadCompoundWordDataFromFile
8603            
8604             Description:
8605            
8606             Reads compound word file and stores in memory. $autoSetMaxCompWordLength parameter is not required to be set. This
8607             parameter instructs the method to auto set the maximum compound word length dependent on the longest compound word found.
8608            
8609             Note: $autoSetMaxCompWordLength options: defined = True and Undefined = False.
8610            
8611             Input:
8612            
8613             $filePath -> Compound word file path
8614             $autoSetMaxCompWordLength -> Maximum length of a given compoundified phrase the module's compoundify algorithm will permit.
8615            
8616             Note: Calling this method with $autoSetMaxCompWordLength defined will automatically set the maxCompoundWordLength variable to the longest compound phrase.
8617            
8618             Output:
8619            
8620             $value -> '0' = Successful / '-1' = Un-successful
8621            
8622             Example:
8623            
8624             use Word2vec::Interface;
8625            
8626             my $interface = Word2vec::Interface->new();
8627             $interface->XTWReadCompoundWordDataFromFile( "samples/compoundword.txt", 1 );
8628            
8629             undef( $interface );
8630            
8631             =head3 XTWSaveCompoundWordListToFile
8632            
8633             Description:
8634            
8635             Saves compound word data in memory to a specified file location.
8636            
8637             Input:
8638            
8639             $savePath -> Path to save compound word list to file.
8640            
8641             Output:
8642            
8643             $value -> '0' = Successful / '-1' = Un-successful
8644            
8645             Example:
8646            
8647             use Word2vec::Interface;
8648            
8649             my $interface = Word2vec::Interface->new();
8650             $interface->XTWReadCompoundWordDataFromFile( "samples/compoundword.txt" );
8651             $interface->XTWSaveCompoundWordDataFromFile( "samples/newcompoundword.txt" );
8652             undef( $interface );
8653            
8654             =head3 XTWReadTextFromFile
8655            
8656             Description:
8657            
8658             Reads a plain text file with utf8 encoding in memory. Returns string data if successful and "(null)" if unsuccessful.
8659            
8660             Input:
8661            
8662             $filePath -> Text file to read into memory
8663            
8664             Output:
8665            
8666             $string -> String data if successful or "(null)" if un-successful.
8667            
8668             Example:
8669            
8670             use Word2vec::Interface;
8671            
8672             my $interface = Word2vec::Interface->new();
8673             my $textData = $interface->XTWReadTextFromFile( "samples/textcorpus.txt" );
8674             print( "Text Data: $textData\n" );
8675             undef( $interface );
8676            
8677             =head3 XTWSaveTextToFile
8678            
8679             Description:
8680            
8681             Saves a plain text file with utf8 encoding in a specified location.
8682            
8683             Input:
8684            
8685             $savePath -> Path to save string data.
8686             $string -> String to save
8687            
8688             Output:
8689            
8690             $value -> '0' = Successful / '-1' = Un-successful
8691            
8692             Example:
8693            
8694             use Word2vec::Interface;
8695            
8696             my $interface = Word2vec::Interface->new();
8697             my $result = $interface->XTWSaveTextToFile( "text.txt", "Hello world!" );
8698            
8699             print( "File saved\n" ) if $result == 0;
8700             print( "File unable to save\n" ) if $result == -1;
8701            
8702             undef( $interface );
8703            
8704             =head3 XTWReadXMLDataFromFile
8705            
8706             Description:
8707            
8708             Reads an XML file from a specified location. Returns string in memory if successful and "(null)" if unsuccessful.
8709            
8710             Input:
8711            
8712             $filePath -> File to read given path
8713            
8714             Output:
8715            
8716             $value -> '0' = Successful / '-1' = Un-successful
8717            
8718             Example:
8719            
8720             Warning: This is a private function and is called by XML::Twig parsing functions. It should not be called outside of xmltow2v module.
8721            
8722             =head3 XTWSaveTextCorpusToFile
8723            
8724             Description:
8725            
8726             Saves text corpus data to specified file path. This method will append to any existing file if $appendToFile parameter
8727             is defined or "overwrite" option is disabled. Enabling "overwrite" option will overwrite any existing files.
8728            
8729             Input:
8730            
8731             $savePath -> Path to save the text corpus
8732             $appendToFile -> Specifies whether the module will overwrite any existing data or append to existing text corpus data.
8733            
8734             Note: Leaving this variable undefined will fetch the "Overwrite" member variable and set the value to this parameter.
8735            
8736             Output:
8737            
8738             $value -> '0' = Successful / '-1' = Un-successful
8739            
8740             Example:
8741            
8742             Warning: This is a private function and is called by XML::Twig parsing functions. It should not be called outside of xmltow2v module.
8743            
8744             =head3 XTWIsDateInSpecifiedRange
8745            
8746             Description:
8747            
8748             Checks to see if $date is within $beginDate and $endDate range. Returns 1 if true and 0 if false.
8749            
8750             Note: Date Format: XX/XX/XXXX (Month/Day/Year)
8751            
8752             Input:
8753            
8754             $date -> Date to check against minimum and maximum data range. (String)
8755             $beginDate -> Minimum date range (String)
8756             $endDate -> Maximum date range (String)
8757            
8758             Output:
8759            
8760             $value -> '1' = True/Date is within specified range Or '0' = False/Date is not within specified range.
8761            
8762             Example:
8763            
8764             use Word2vec::Interface;
8765            
8766             my $interface = Word2vec::Interface->new();
8767             print( "Is \"01/01/2004\" within the date range: \"02/21/1985\" to \"08/13/2016\"?\n" );
8768             print( "Yes\n" ) if $interface->XTWIsDateInSpecifiedRange( "01/01/2004", "02/21/1985", "08/13/2016" ) == 1;
8769             print( "No\n" ) if $interface->XTWIsDateInSpecifiedRange( "01/01/2004", "02/21/1985", "08/13/2016" ) == 0;
8770            
8771             undef( $interface );
8772            
8773             =head3 XTWIsFileOrDirectory
8774            
8775             Description:
8776            
8777             Checks to see if specified path is a file or directory.
8778            
8779             Input:
8780            
8781             $path -> File or directory path. (String)
8782            
8783             Output:
8784            
8785             $string -> Returns: "file" = file, "dir" = directory and "unknown" if the path is not a file or directory (undefined).
8786            
8787             Example:
8788            
8789             use Word2vec::Interface;
8790            
8791             my $interface = Word2vec::Interface->new();
8792             my $path = "path/to/a/directory";
8793            
8794             print( "Is \"$path\" a file or directory? " . $interface->XTWIsFileOrDirectory( $path ) . "\n" );
8795            
8796             $path = "path/to/a/file.file";
8797            
8798             print( "Is \"$path\" a file or directory? " . $interface->XTWIsFileOrDirectory( $path ) . "\n" );
8799            
8800             undef( $interface );
8801            
8802             =head3 XTWRemoveSpecialCharactersFromString
8803            
8804             Description:
8805            
8806             Removes special characters from string parameter, removes extra spaces and converts text to lowercase.
8807            
8808             Note: This method is called when parsing and compiling Medline title/abstract data.
8809            
8810             Input:
8811            
8812             $string -> String passed to remove special characters from and convert to lowercase.
8813            
8814             Output:
8815            
8816             $string -> String with all special characters removed and converted to lowercase.
8817            
8818             Example:
8819            
8820             use Word2vec::Interface;
8821            
8822             my $interface = Word2vec::Interface->new();
8823            
8824             my $str = "Heart Attack is$ an!@ also KNOWN as an Acute MYOCARDIAL inFARCTion!";
8825            
8826             print( "Original String: $str\n" );
8827            
8828             $str = $interface->XTWRemoveSpecialCharactersFromString( $str );
8829            
8830             print( "Modified String: $str\n" );
8831            
8832             undef( $interface );
8833            
8834             =head3 XTWGetFileType
8835            
8836             Description:
8837            
8838             Returns file data type (string).
8839            
8840             Input:
8841            
8842             $filePath -> File to check located at file path
8843            
8844             Output:
8845            
8846             $string -> File type
8847            
8848             Example:
8849            
8850             use Word2vec::Interface;
8851            
8852             my $interface = Word2vec::Interface->new()
8853             my $fileType = $interface->XTWGetFileType( "samples/textcorpus.txt" );
8854            
8855             undef( $interface );
8856            
8857             =head3 XTWDateCheck
8858            
8859             Description:
8860            
8861             Checks specified begin and end date strings for formatting and logic errors.
8862            
8863             Input:
8864            
8865             None
8866            
8867             Output:
8868            
8869             $value -> "0" = Passed Checks / "-1" = Failed Checks
8870            
8871             Example:
8872            
8873             use Word2vec::Interface;
8874            
8875             my $interface = Word2vec::Interface->new()
8876             print "Passed Date Checks\n" if ( $interface->_DateCheck() == 0 );
8877             print "Failed Date Checks\n" if ( $interface->_DateCheck() == -1 );
8878            
8879             undef( $interface );
8880            
8881             =head2 XMLToW2V Accessor Functions
8882            
8883             =head3 XTWGetDebugLog
8884            
8885             Description:
8886            
8887             Returns the _debugLog member variable set during Word2vec::Interface object initialization of new function.
8888            
8889             Input:
8890            
8891             None
8892            
8893             Output:
8894            
8895             $value -> '0' = False, '1' = True
8896            
8897             Example:
8898            
8899             use Word2vec::Interface;
8900            
8901             my $interface = Word2vec::Interface->new()
8902             my $debugLog = $interface->XTWGetDebugLog();
8903            
8904             print( "Debug Logging Enabled\n" ) if $debugLog == 1;
8905             print( "Debug Logging Disabled\n" ) if $debugLog == 0;
8906            
8907            
8908             undef( $interface );
8909            
8910             =head3 XTWGetWriteLog
8911            
8912             Description:
8913            
8914             Returns the _writeLog member variable set during Word2vec::Interface object initialization of new function.
8915            
8916             Input:
8917            
8918             None
8919            
8920             Output:
8921            
8922             $value -> '0' = False, '1' = True
8923            
8924             Example:
8925            
8926             use Word2vec::Interface;
8927            
8928             my $interface = Word2vec::Interface->new();
8929             my $writeLog = $interface->XTWGetWriteLog();
8930            
8931             print( "Write Logging Enabled\n" ) if $writeLog == 1;
8932             print( "Write Logging Disabled\n" ) if $writeLog == 0;
8933            
8934             undef( $interface );
8935            
8936             =head3 XTWGetStoreTitle
8937            
8938             Description:
8939            
8940             Returns the _storeTitle member variable set during Word2vec::Interface object instantiation of new function.
8941            
8942             Input:
8943            
8944             None
8945            
8946             Output:
8947            
8948             $value -> '1' = True / '0' = False
8949            
8950             Example:
8951            
8952             use Word2vec::Interface;
8953            
8954             my $interface = Word2vec::Interface->new();
8955             my $storeTitle = $interface->XTWGetStoreTitle();
8956            
8957             print( "Store Title Option: Enabled\n" ) if $storeTitle == 1;
8958             print( "Store Title Option: Disabled\n" ) if $storeTitle == 0;
8959            
8960             undef( $interface );
8961            
8962             =head3 XTWGetStoreAbstract
8963            
8964             Description:
8965            
8966             Returns the _storeAbstract member variable set during Word2vec::Interface object instantiation of new function.
8967            
8968             Input:
8969            
8970             None
8971            
8972             Output:
8973            
8974             $value -> '1' = True / '0' = False
8975            
8976             Example:
8977            
8978             use Word2vec::Interface;
8979            
8980             my $interface = Word2vec::Interface->new();
8981             my $storeAbstract = $interface->XTWGetStoreAbstract();
8982            
8983             print( "Store Abstract Option: Enabled\n" ) if $storeAbsract == 1;
8984             print( "Store Abstract Option: Disabled\n" ) if $storeAbstract == 0;
8985            
8986             undef( $interface );
8987            
8988             =head3 XTWGetQuickParse
8989            
8990             Description:
8991            
8992             Returns the _quickParse member variable set during Word2vec::Interface object instantiation of new function.
8993            
8994             Input:
8995            
8996             None
8997            
8998             Output:
8999            
9000             $value -> '1' = True / '0' = False
9001            
9002             Example:
9003            
9004             use Word2vec::Interface;
9005            
9006             my $interface = Word2vec::Interface->new();
9007             my $quickParse = $interface->XTWGetQuickParse();
9008            
9009             print( "Quick Parse Option: Enabled\n" ) if $quickParse == 1;
9010             print( "Quick Parse Option: Disabled\n" ) if $quickParse == 0;
9011            
9012             undef( $interface );
9013            
9014             =head3 XTWGetCompoundifyText
9015            
9016             Description:
9017            
9018             Returns the _compoundifyText member variable set during Word2vec::Interface object instantiation of new function.
9019            
9020             Input:
9021            
9022             None
9023            
9024             Output:
9025            
9026             $value -> '1' = True / '0' = False
9027            
9028             Example:
9029            
9030             use Word2vec::Interface;
9031            
9032             my $interface = Word2vec::Interface->new();
9033             my $compoundify = $interface->XTWGetCompoundifyText();
9034            
9035             print( "Compoundify Text Option: Enabled\n" ) if $compoundify == 1;
9036             print( "Compoundify Text Option: Disabled\n" ) if $compoundify == 0;
9037            
9038             undef( $interface );
9039            
9040             =head3 XTWGetStoreAsSentencePerLine
9041            
9042             Description:
9043            
9044             Returns the _storeAsSentencePerLine member variable set during Word2vec::Xmltow2v object instantiation of new function.
9045            
9046             Input:
9047            
9048             None
9049            
9050             Output:
9051            
9052             $value -> '1' = True / '0' = False
9053            
9054             Example:
9055            
9056             use Word2vec::Interface;
9057            
9058             my $interface = Word2vec::Interface->new();
9059             my $storeAsSentencePerLine = $interface->GetStoreAsSentencePerLine();
9060            
9061             print( "Store As Sentence Per Line: Enabled\n" ) if $storeAsSentencePerLine == 1;
9062             print( "Store As Sentence Per Line: Disabled\n" ) if $storeAsSentencePerLine == 0;
9063            
9064             undef( $interface );
9065            
9066             =head3 XTWGetNumOfThreads
9067            
9068             Description:
9069            
9070             Returns the _numOfThreads member variable set during Word2vec::Interface object instantiation of new function.
9071            
9072             Input:
9073            
9074             None
9075            
9076             Output:
9077            
9078             $value -> Number of threads
9079            
9080             Example:
9081            
9082             use Word2vec::Interface;
9083            
9084             my $interface = Word2vec::Interface->new();
9085             my $numOfThreads = $interface->XTWGetNumOfThreads();
9086            
9087             print( "Number of threads: $numOfThreads\n" );
9088            
9089             undef( $interface );
9090            
9091             =head3 XTWGetWorkingDir
9092            
9093             Description:
9094            
9095             Returns the _workingDir member variable set during Word2vec::Interface object instantiation of new function.
9096            
9097             Input:
9098            
9099             None
9100            
9101             Output:
9102            
9103             $string -> Working directory string
9104            
9105             Example:
9106            
9107             use Word2vec::Interface;
9108            
9109             my $interface = Word2vec::Interface->new();
9110             my $workingDirectory = $interface->XTWGetWorkingDir();
9111            
9112             print( "Working Directory: $workingDirectory\n" );
9113            
9114             undef( $interface );
9115            
9116             =head3 XTWGetSavePath
9117            
9118             Description:
9119            
9120             Returns the _saveDir member variable set during Word2vec::Interface object instantiation of new function.
9121            
9122             Input:
9123            
9124             None
9125            
9126             Output:
9127            
9128             $string -> Save directory string
9129            
9130             Example:
9131            
9132             use Word2vec::Interface;
9133            
9134             my $interface = Word2vec::Interface->new();
9135             my $savePath = $interface->XTWGetSavePath();
9136            
9137             print( "Save Directory: $savePath\n" );
9138            
9139             undef( $interface );
9140            
9141             =head3 XTWGetBeginDate
9142            
9143             Description:
9144            
9145             Returns the _beginDate member variable set during Word2vec::Interface object instantiation of new function.
9146            
9147             Input:
9148            
9149             None
9150            
9151             Output:
9152            
9153             $date -> Beginning date range - Format: XX/XX/XXXX (Mon/Day/Year)
9154            
9155             Example:
9156            
9157             use Word2vec::Interface;
9158            
9159             my $interface = Word2vec::Interface->new();
9160             my $date = $interface->XTWGetBeginDate();
9161            
9162             print( "Date: $date\n" );
9163            
9164             undef( $interface );
9165            
9166             =head3 XTWGetEndDate
9167            
9168             Description:
9169            
9170             Returns the _endDate member variable set during Word2vec::Interface object instantiation of new function.
9171            
9172             Input:
9173            
9174             None
9175            
9176             Output:
9177            
9178             $date -> End date range - Format: XX/XX/XXXX (Mon/Day/Year).
9179            
9180             Example:
9181            
9182             use Word2vec::Interface;
9183            
9184             my $interface = Word2vec::Interface->new();
9185             my $date = $interface->XTWGetEndDate();
9186            
9187             print( "Date: $date\n" );
9188            
9189             undef( $interface );
9190            
9191             =head3 XTWGetXMLStringToParse
9192            
9193             Returns the XML data (string) to be parsed.
9194            
9195             Description:
9196            
9197             Returns the _xmlStringToParse member variable set during Word2vec::Interface object instantiation of new function.
9198            
9199             Input:
9200            
9201             None
9202            
9203             Output:
9204            
9205             $string -> Medline XML data string
9206            
9207             Example:
9208            
9209             use Word2vec::Interface;
9210            
9211             my $interface = Word2vec::Interface->new();
9212             my $xmlStr = $interface->XTWGetXMLStringToParse();
9213            
9214             print( "XML String: $xmlStr\n" );
9215            
9216             undef( $interface );
9217            
9218             =head3 XTWGetTextCorpusStr
9219            
9220             Description:
9221            
9222             Returns the _textCorpusStr member variable set during Word2vec::Interface object instantiation of new function.
9223            
9224             Input:
9225            
9226             None
9227            
9228             Output:
9229            
9230             $string -> Text corpus string
9231            
9232             Example:
9233            
9234             use Word2vec::Interface;
9235            
9236             my $interface = Word2vec::Interface->new();
9237             my $str = $interface->XTWGetTextCorpusStr();
9238            
9239             print( "Text Corpus: $str\n" );
9240            
9241             undef( $interface );
9242            
9243             =head3 XTWGetFileHandle
9244            
9245             Description:
9246            
9247             Returns the _fileHandle member variable set during Word2vec::Interface object instantiation of new function.
9248            
9249             Warning: This is a private function. File handle is used by 'xmltow2v::WriteLog()' method. Do not manipulate this file handle as errors can result.
9250            
9251             Input:
9252            
9253             None
9254            
9255             Output:
9256            
9257             $fileHandle -> Returns file handle for WriteLog() method.
9258            
9259             Example:
9260            
9261             use Word2vec::Interface;
9262            
9263             my $interface = Word2vec::Interface->new();
9264             my $fileHandle = $interface->XTWGetFileHandle();
9265            
9266             undef( $interface );
9267            
9268             =head3 XTWGetTwigHandler
9269            
9270             Returns XML::Twig handler.
9271            
9272             Description:
9273            
9274             Returns the _twigHandler member variable set during Word2vec::Interface object instantiation of new function.
9275            
9276             Warning: This is a private function and should not be called or manipulated.
9277            
9278             Input:
9279            
9280             None
9281            
9282             Output:
9283            
9284             $twigHandler -> XML::Twig handler.
9285            
9286             Example:
9287            
9288             use Word2vec::Interface;
9289            
9290             my $interface = Word2vec::Interface->new();
9291             my $xmlHandler = $interface->XTWGetTwigHandler();
9292            
9293             undef( $interface );
9294            
9295             =head3 XTWGetParsedCount
9296            
9297             Description:
9298            
9299             Returns the _parsedCount member variable set during Word2vec::Interface object instantiation of new function.
9300            
9301             Input:
9302            
9303             None
9304            
9305             Output:
9306            
9307             $value -> Number of parsed Medline articles.
9308            
9309             Example:
9310            
9311             use Word2vec::Interface;
9312            
9313             my $interface = Word2vec::Interface->new();
9314             my $numOfParsed = $interface->XTWGetParsedCount();
9315            
9316             print( "Number of parsed Medline articles: $numOfParsed\n" );
9317            
9318             undef( $interface );
9319            
9320             =head3 XTWGetTempStr
9321            
9322             Description:
9323            
9324             Returns the _tempStr member variable set during Word2vec::Interface object instantiation of new function.
9325            
9326             Warning: This is a private function and should not be called or manipulated. Used by module as a temporary storage
9327             location for parsed Medline 'Title' and 'Abstract' flag string data.
9328            
9329             Input:
9330            
9331             None
9332            
9333             Output:
9334            
9335             $string -> Temporary string storage location.
9336            
9337             Example:
9338            
9339             use Word2vec::Interface;
9340            
9341             my $interface = Word2vec::Interface->new();
9342             my $tempStr = $interface->XTWGetTempStr();
9343            
9344             print( "Temp String: $tempStr\n" );
9345            
9346             undef( $interface );
9347            
9348             =head3 XTWGetTempDate
9349            
9350             Description:
9351            
9352             Returns the _tempDate member variable set during Word2vec::Interface object instantiation of new function.
9353             Used by module as a temporary storage location for parsed Medline 'DateCreated' flag string data.
9354            
9355             Input:
9356            
9357             None
9358            
9359             Output:
9360            
9361             $date -> Date string - Format: XX/XX/XXXX (Mon/Day/Year).
9362            
9363             Example:
9364            
9365             use Word2vec::Interface;
9366            
9367             my $interface = Word2vec::Interface->new();
9368             my $date = $interface->XTWGetTempDate();
9369            
9370             print( "Temp Date: $date\n" );
9371            
9372             undef( $interface );
9373            
9374             =head3 XTWGetCompoundWordAry
9375            
9376             Description:
9377            
9378             Returns the _compoundWordAry member array reference set during Word2vec::Interface object instantiation of new function.
9379            
9380             Warning: Compound word data must be loaded in memory first via XTWReadCompoundWordDataFromFile().
9381            
9382             Input:
9383            
9384             None
9385            
9386             Output:
9387            
9388             $arrayReference -> Compound word array reference.
9389            
9390             Example:
9391            
9392             use Word2vec::Interface;
9393            
9394             my $interface = Word2vec::Interface->new();
9395             my $arrayReference = $interface->XTWGetCompoundWordAry();
9396             my @compoundWord = @{ $arrayReference };
9397            
9398             print( "Compound Word Array: @compoundWord\n" );
9399            
9400             undef( $interface );
9401            
9402             =head3 XTWGetCompoundWordBST
9403            
9404             Description:
9405            
9406             Returns the _compoundWordBST member variable set during Word2vec::Interface object instantiation of new function.
9407            
9408             Input:
9409            
9410             None
9411            
9412             Output:
9413            
9414             $bst -> Compound word binary search tree.
9415            
9416             Example:
9417            
9418             use Word2vec::Interface;
9419            
9420             my $interface = Word2vec::Interface->new();
9421             my $bst = $interface->XTWGetCompoundWordBST();
9422            
9423             undef( $interface );
9424            
9425             =head3 XTWGetMaxCompoundWordLength
9426            
9427             Description:
9428            
9429             Returns the _maxCompoundWordLength member variable set during Word2vec::Interface object instantiation of new function.
9430            
9431             Note: If not defined, it is automatically set to and returns 20.
9432            
9433             Input:
9434            
9435             None
9436            
9437             Output:
9438            
9439             $value -> Maximum number of compound words in a given phrase.
9440            
9441             Example:
9442            
9443             use Word2vec::Interface;
9444            
9445             my $interface = Word2vec::Interface->new();
9446             my $compoundWordLength = $interface->XTWGetMaxCompoundWordLength();
9447            
9448             print( "Maximum Compound Word Length: $compoundWordLength\n" );
9449            
9450             undef( $interface );
9451            
9452             =head3 XTWGetOverwriteExistingFile
9453            
9454             Description:
9455            
9456             Returns the _overwriteExisitingFile member variable set during Word2vec::Interface object instantiation of new function.
9457             Enables overwriting of existing text corpus if set to '1' or appends to the existing text corpus if set to '0'.
9458            
9459             Input:
9460            
9461             None
9462            
9463             Output:
9464            
9465             $value -> '1' = Overwrite existing file / '0' = Append to exiting file.
9466            
9467             Example:
9468            
9469             use Word2vec::Interface;
9470            
9471             my $interface = Word2vec::Interface->new();
9472             my $overwriteExitingFile = $interface->XTWGetOverwriteExistingFile();
9473            
9474             print( "Overwrite Existing File? YES\n" ) if ( $overwriteExistingFile == 1 );
9475             print( "Overwrite Existing File? NO\n" ) if ( $overwriteExistingFile == 0 );
9476            
9477             undef( $interface );
9478            
9479             =head2 XMLToW2V Mutator Functions
9480            
9481             =head3 XTWSetStoreTitle
9482            
9483             Description:
9484            
9485             Sets member variable to passed integer parameter. Instructs module to store article title if true or omit if false.
9486            
9487             Input:
9488            
9489             $value -> '1' = Store Titles / '0' = Omit Titles
9490            
9491             Ouput:
9492            
9493             None
9494            
9495             Example:
9496            
9497             use Word2vec::Interface;
9498            
9499             my $interface = Word2vec::Interface->new();
9500             $interface->XTWSetStoreTitle( 1 );
9501            
9502             undef( $interface );
9503            
9504             =head3 XTWSetStoreAbstract
9505            
9506             Description:
9507            
9508             Sets member variable to passed integer parameter. Instructs module to store article abstracts if true or omit if false.
9509            
9510             Input:
9511            
9512             $value -> '1' = Store Abstracts / '0' = Omit Abstracts
9513            
9514             Ouput:
9515            
9516             None
9517            
9518             Example:
9519            
9520             use Word2vec::Interface;
9521            
9522             my $interface = Word2vec::Interface->new();
9523             $interface->XTWSetStoreAbstract( 1 );
9524            
9525             undef( $interface );
9526            
9527             =head3 XTWSetWorkingDir
9528            
9529             Description:
9530            
9531             Sets member variable to passed string parameter. Represents the working directory.
9532            
9533             Input:
9534            
9535             $string -> Working directory string
9536            
9537             Ouput:
9538            
9539             None
9540            
9541             Example:
9542            
9543             use Word2vec::Interface;
9544            
9545             my $interface = Word2vec::Interface->new();
9546             $interface->XTWSetWorkingDir( "/samples/" );
9547            
9548             undef( $interface );
9549            
9550             =head3 XTWSetSavePath
9551            
9552             Description:
9553            
9554             Sets member variable to passed integer parameter. Represents the text corpus save path.
9555            
9556             Input:
9557            
9558             $string -> Text corpus save path
9559            
9560             Output:
9561            
9562             None
9563            
9564             Example:
9565            
9566             use Word2vec::Interface;
9567            
9568             my $interface = Word2vec::Interface->new();
9569             $interface->XTWSetSavePath( "samples/textcorpus.txt" );
9570            
9571             undef( $interface );
9572            
9573             =head3 XTWSetQuickParse
9574            
9575             Description:
9576            
9577             Sets member variable to passed integer parameter. Instructs module to utilize quick parse
9578             routines to speed up text corpus compilation. This method is somewhat less accurate due to its non-exhaustive nature.
9579            
9580             Input:
9581            
9582             $value -> '1' = Enable Quick Parse / '0' = Disable Quick Parse
9583            
9584             Ouput:
9585            
9586             None
9587            
9588             Example:
9589            
9590             use Word2vec::Interface;
9591            
9592             my $interface = Word2vec::Interface->new();
9593             $interface->XTWSetQuickParse( 1 );
9594            
9595             undef( $interface );
9596            
9597             =head3 XTWSetCompoundifyText
9598            
9599             Description:
9600            
9601             Sets member variable to passed integer parameter. Instructs module to utilize 'compoundify' option if true.
9602            
9603             Warning: This requires compound word data to be loaded into memory with XTWReadCompoundWordDataFromFile() method prior
9604             to executing text corpus compilation.
9605            
9606             Input:
9607            
9608             $value -> '1' = Compoundify text / '0' = Do not compoundify text
9609            
9610             Ouput:
9611            
9612             None
9613            
9614             Example:
9615            
9616             use Word2vec::Interface;
9617            
9618             my $interface = Word2vec::Interface->new();
9619             $interface->XTWSetCompoundifyText( 1 );
9620            
9621             undef( $interface );
9622            
9623             =head3 XTWSetStoreAsSentencePerLine
9624            
9625             Description:
9626            
9627             Sets member variable to passed integer parameter. Instructs module to utilize 'storeAsSentencePerLine' option if true.
9628            
9629             Input:
9630            
9631             $value -> '1' = Store as sentence per line / '0' = Do not store as sentence per line
9632            
9633             Ouput:
9634            
9635             None
9636            
9637             Example:
9638            
9639             use Word2vec::Interface;
9640            
9641             my $interface = Word2vec::Interface->new();
9642             $interface->XTWSetStoreAsSentencePerLine( 1 );
9643            
9644             undef( $interface );
9645            
9646             =head3 XTWSetNumOfThreads
9647            
9648             Description:
9649            
9650             Sets member variable to passed integer parameter. Sets the requested number of threads to parse Medline XML files
9651             and compile the text corpus.
9652            
9653             Input:
9654            
9655             $value -> Integer (Positive value)
9656            
9657             Ouput:
9658            
9659             None
9660            
9661             Example:
9662            
9663             use Word2vec::Interface;
9664            
9665             my $interface = Word2vec::Interface->new();
9666             $interface->XTWSetNumOfThreads( 4 );
9667            
9668             undef( $interface );
9669            
9670             =head3 XTWSetBeginDate
9671            
9672             Description:
9673            
9674             Sets member variable to passed string parameter. Sets beginning date range for earliest articles to store, by
9675             'DateCreated' Medline tag, within the text corpus during compilation.
9676            
9677             Note: Expected format - "XX/XX/XXXX" (Mon/Day/Year)
9678            
9679             Input:
9680            
9681             $string -> Date string - Format: "XX/XX/XXXX"
9682            
9683             Ouput:
9684            
9685             None
9686            
9687             Example:
9688            
9689             use Word2vec::Interface;
9690            
9691             my $interface = Word2vec::Interface->new();
9692             $interface->XTWSetBeginDate( "01/01/2004" );
9693            
9694             undef( $interface );
9695            
9696             =head3 XTWSetEndDate
9697            
9698             Description:
9699            
9700             Sets member variable to passed string parameter. Sets ending date range for latest article to store, by
9701             'DateCreated' Medline tag, within the text corpus during compilation.
9702            
9703             Note: Expected format - "XX/XX/XXXX" (Mon/Day/Year)
9704            
9705             Input:
9706            
9707             $string -> Date string - Format: "XX/XX/XXXX"
9708            
9709             Ouput:
9710            
9711             None
9712            
9713             Example:
9714            
9715             use Word2vec::Interface;
9716            
9717             my $interface = Word2vec::Interface->new();
9718             $interface->XTWSetEndDate( "08/13/2016" );
9719            
9720             undef( $interface );
9721            
9722             =head3 XTWSetXMLStringToParse
9723            
9724             Description:
9725            
9726             Sets member variable to passed string parameter. This string normally consists of Medline XML data to be
9727             parsed for text corpus compilation.
9728            
9729             Warning: This is a private function and should not be called or manipulated.
9730            
9731             Input:
9732            
9733             $string -> String
9734            
9735             Ouput:
9736            
9737             None
9738            
9739             Example:
9740            
9741             use Word2vec::Interface;
9742            
9743             my $interface = Word2vec::Interface->new();
9744             $interface->XTWSetXMLStringToParse( "Hello World!" );
9745            
9746             undef( $interface );
9747            
9748             =head3 XTWSetTextCorpusStr
9749            
9750             Description:
9751            
9752             Sets member variable to passed string parameter. Overwrites any stored text corpus data in memory to the string parameter.
9753            
9754             Warning: This is a private function and should not be called or manipulated.
9755            
9756             Input:
9757            
9758             $string -> String
9759            
9760             Ouput:
9761            
9762             None
9763            
9764             Example:
9765            
9766             use Word2vec::Interface;
9767            
9768             my $interface = Word2vec::Interface->new();
9769             $interface->XTWSetTextCorpusStr( "Hello World!" );
9770            
9771             undef( $interface );
9772            
9773             =head3 XTWAppendStrToTextCorpus
9774            
9775             Description:
9776            
9777             Sets member variable to passed string parameter. Appends string parameter to text corpus string in memory.
9778            
9779             Warning: This is a private function and should not be called or manipulated.
9780            
9781             Input:
9782            
9783             $string -> String
9784            
9785             Ouput:
9786            
9787             None
9788            
9789             Example:
9790            
9791             use Word2vec::Interface;
9792            
9793             my $interface = Word2vec::Interface->new();
9794             $interface->XTWAppendStrToTextCorpus( "Hello World!" );
9795            
9796             undef( $interface );
9797            
9798             =head3 XTWClearTextCorpus
9799            
9800             Description:
9801            
9802             Clears text corpus data in memory.
9803            
9804             Warning: This is a private function and should not be called or manipulated.
9805            
9806             Input:
9807            
9808             None
9809            
9810             Ouput:
9811            
9812             None
9813            
9814             Example:
9815            
9816             use Word2vec::Interface;
9817            
9818             my $interface = Word2vec::Interface->new();
9819             $interface->XTWClearTextCorpus();
9820            
9821             undef( $interface );
9822            
9823             =head3 XTWSetTempStr
9824            
9825             Description:
9826            
9827             Sets member variable to passed string parameter. Sets temporary member string to passed string parameter.
9828             (Temporary placeholder for Medline Title and Abstract data).
9829            
9830             Note: This removes special characters and converts all characters to lowercase.
9831            
9832             Warning: This is a private function and should not be called or manipulated.
9833            
9834             Input:
9835            
9836             $string -> String
9837            
9838             Ouput:
9839            
9840             None
9841            
9842             Example:
9843            
9844             use Word2vec::Interface;
9845            
9846             my $interface = Word2vec::Interface->new();
9847             $interface->XTWSetTempStr( "Hello World!" );
9848            
9849             undef( $interface );
9850            
9851             =head3 XTWAppendToTempStr
9852            
9853             Description:
9854            
9855             Appends string parameter to temporary member string in memory.
9856            
9857             Note: This removes special characters and converts all characters to lowercase.
9858            
9859             Warning: This is a private function and should not be called or manipulated.
9860            
9861             Input:
9862            
9863             $string -> String
9864            
9865             Ouput:
9866            
9867             None
9868            
9869             Example:
9870            
9871             use Word2vec::Interface;
9872            
9873             my $interface = Word2vec::Interface->new();
9874             $interface->XTWAppendToTempStr( "Hello World!" );
9875            
9876             undef( $interface );
9877            
9878             =head3 XTWClearTempStr
9879            
9880             Clears the temporary string storage in memory.
9881            
9882             Warning: This is a private function and should not be called or manipulated.
9883            
9884             Input:
9885            
9886             None
9887            
9888             Ouput:
9889            
9890             None
9891            
9892             Example:
9893            
9894             use Word2vec::Interface;
9895            
9896             my $interface = Word2vec::Interface->new();
9897             $interface->XTWClearTempStr();
9898            
9899             undef( $interface );
9900            
9901             =head3 XTWSetTempDate
9902            
9903             Description:
9904            
9905             Sets member variable to passed string parameter. Sets temporary date string to passed string.
9906            
9907             Note: Date Format - "XX/XX/XXXX" (Mon/Day/Year)
9908            
9909             Warning: This is a private function and should not be called or manipulated.
9910            
9911             Input:
9912            
9913             $string -> Date string - Format: "XX/XX/XXXX"
9914            
9915             Ouput:
9916            
9917             None
9918            
9919             Example:
9920            
9921             use Word2vec::Interface;
9922            
9923             my $interface = Word2vec::Interface->new();
9924             $interface->XTWSetTempDate( "08/13/2016" );
9925            
9926             undef( $interface );
9927            
9928             =head3 XTWClearTempDate
9929            
9930             Description:
9931            
9932             Clears the temporary date storage location in memory.
9933            
9934             Warning: This is a private function and should not be called or manipulated.
9935            
9936             Input:
9937            
9938             None
9939            
9940             Ouput:
9941            
9942             None
9943            
9944             Example:
9945            
9946             use Word2vec::Interface;
9947            
9948             my $interface = Word2vec::Interface->new();
9949             $interface->XTWClearTempDate();
9950            
9951             undef( $interface );
9952            
9953             =head3 XTWSetCompoundWordAry
9954            
9955             Description:
9956            
9957             Sets member variable to de-referenced passed array reference parameter. Stores compound word array by
9958             de-referencing array reference parameter.
9959            
9960             Note: Clears previous data if existing.
9961            
9962             Warning: This is a private function and should not be called or manipulated.
9963            
9964             Input:
9965            
9966             $arrayReference -> Array reference of compound words
9967            
9968             Ouput:
9969            
9970             None
9971            
9972             Example:
9973            
9974             use Word2vec::Interface;
9975            
9976             my @compoundWordAry = ( "big dog", "respiratory failure", "seven large masses" );
9977            
9978             my $interface = Word2vec::Interface->new();
9979             $interface->XTWSetCompoundWordAry( \@compoundWordAry );
9980            
9981             undef( $interface );
9982            
9983             =head3 XTWClearCompoundWordAry
9984            
9985             Description:
9986            
9987             Clears compound word array in memory.
9988            
9989             Warning: This is a private function and should not be called or manipulated.
9990            
9991             Input:
9992            
9993             None
9994            
9995             Ouput:
9996            
9997             None
9998            
9999             Example:
10000            
10001             use Word2vec::Interface;
10002            
10003             my $interface = Word2vec::Interface->new();
10004             $interface->XTWClearCompoundWordAry();
10005            
10006             undef( $interface );
10007            
10008             =head3 XTWSetCompoundWordBST
10009            
10010             Description:
10011            
10012             Sets member variable to passed Word2vec::Bst parameter. Sets compound word binary search tree to passed binary tree parameter.
10013            
10014             Note: Un-defines previous binary tree if existing.
10015            
10016             Warning: This is a private function and should not be called or manipulated.
10017            
10018             Input:
10019            
10020             Word2vec::Bst -> Binary Search Tree
10021            
10022             Ouput:
10023            
10024             None
10025            
10026             Example:
10027            
10028             use Word2vec::Interface;
10029            
10030             my @compoundWordAry = ( "big dog", "respiratory failure", "seven large masses" );
10031             @compoundWordAry = sort( @compoundWordAry );
10032            
10033             my $arySize = @compoundWordAry;
10034            
10035             my $bst = Word2vec::Bst;
10036             $bst->CreateTree( \@compoundWordAry, 0, $arySize, undef );
10037            
10038             my $interface = Word2vec::Interface->new();
10039             $interface->XTWSetCompoundWordBST( $bst );
10040            
10041             undef( $interface );
10042            
10043             =head3 XTWClearCompoundWordBST
10044            
10045             Description:
10046            
10047             Clears/Un-defines existing compound word binary search tree from memory.
10048            
10049             Warning: This is a private function and should not be called or manipulated.
10050            
10051             Input:
10052            
10053             None
10054            
10055             Ouput:
10056            
10057             None
10058            
10059             Example:
10060            
10061             use Word2vec::Interface;
10062            
10063             my $interface = Word2vec::Interface->new();
10064             $interface->XTWClearCompoundWordBST();
10065            
10066             undef( $interface );
10067            
10068             =head3 XTWSetMaxCompoundWordLength
10069            
10070             Description:
10071            
10072             Sets member variable to passed integer parameter. Sets maximum number of compound words in a phrase for comparison.
10073            
10074             ie. "medical campus of Virginia Commonwealth University" can be interpreted as a compound word of 6 words.
10075             Setting this variable to 3 will only attempt compoundifying a maximum amount of three words.
10076             The result would be "medical_campus_of Virginia commonwealth university" even-though an exact representation
10077             of this compounded string can exist. Setting this variable to 6 will result in compounding all six words if
10078             they exists in the compound word array/bst.
10079            
10080             Warning: This is a private function and should not be called or manipulated.
10081            
10082             Input:
10083            
10084             $value -> Integer
10085            
10086             Ouput:
10087            
10088             None
10089            
10090             Example:
10091            
10092             use Word2vec::Interface;
10093            
10094             my $interface = Word2vec::Interface->new();
10095             $interface->XTWSetMaxCompoundWordLength( 8 );
10096            
10097             undef( $interface );
10098            
10099             =head3 XTWSetOverwriteExistingFile
10100            
10101             Description:
10102            
10103             Sets member variable to passed integer parameter. Sets option to overwrite existing text corpus during compilation
10104             if 1 or append to existing text corpus if 0.
10105            
10106             Input:
10107            
10108             $value -> '1' = Overwrite existing text corpus / '0' = Append to existing text corpus during compilation.
10109            
10110             Output:
10111            
10112             None
10113            
10114             Example:
10115            
10116             use Word2vec::Interface;
10117            
10118             my $interface = Word2vec::Interface->new();
10119             $interface->XTWSetOverWriteExistingFile( 1 );
10120            
10121             undef( $xmltow2v );
10122            
10123             =head1 Author
10124            
10125             Clint Cuffy, Virginia Commonwealth University
10126            
10127             =head1 COPYRIGHT
10128            
10129             Copyright (c) 2016
10130            
10131             Bridget T McInnes, Virginia Commonwealth University
10132             btmcinnes at vcu dot edu
10133            
10134             Clint Cuffy, Virginia Commonwealth University
10135             cuffyca at vcu dot edu
10136            
10137             This program is free software; you can redistribute it and/or modify it
10138             under the terms of the GNU General Public License as published by the Free
10139             Software Foundation; either version 2 of the License, or (at your option)
10140             any later version.
10141            
10142             This program is distributed in the hope that it will be useful, but WITHOUT
10143             ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10144             FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10145            
10146             You should have received a copy of the GNU General Public License along with
10147             this program; if not, write to:
10148            
10149             The Free Software Foundation, Inc.,
10150             59 Temple Place - Suite 330,
10151             Boston, MA 02111-1307, USA.
10152            
10153             =cut