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