forked from NLPatVCU/NER-OUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw2v.pl
53 lines (44 loc) · 944 Bytes
/
w2v.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
###
#w2v.pl
#Scope: Defines the perl module to pull embeddings from a trained embedding model.
#Authors: Jeffrey Smith, Bill Cramer, Evan French
###
#Author: Jeffrey Smith
use strict;
use warnings;
use Word2vec::Interface;
use IO::Handle;
select(STDOUT);
$| = 1;
my $source = $ARGV[0];
my $interface = Word2vec::Interface->new();
my $result = $interface->W2VReadTrainedVectorDataFromFile( "./" . $source );
if ($result != 0) {
print "FAILED\n";
exit;
}
else {
print "READY\n";
}
while (1) {
my $word = readline(STDIN);
if(!defined($word)) {
next;
}
chomp($word);
if ($word eq "EXIT") {
print("TRYING TO EXIT.");
last;
}
my $result = $interface->W2VGetWordVector($word);
if (defined($result)) {
print($result);
print("\n");
}
else {
print("UNDEF\n");
}
}
print "EXITED\n";
$interface->W2VClearVocabularyHash();
undef( $interface );