-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJythonTest.java
More file actions
67 lines (47 loc) · 1.5 KB
/
Copy pathJythonTest.java
File metadata and controls
67 lines (47 loc) · 1.5 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.wsd.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.python.util.PythonInterpreter;
import org.python.core.*;
//from gensim.models import word2vec
public class JythonTest
{
/**
* @param args
*/
public JythonTest()
{
}
public void checkSimilarityOfTwoWords()
{
PythonInterpreter interp = new PythonInterpreter();
interp.execfile("./src/com/wsd/util/GensimInterface.py");
PyFunction func =
(PyFunction)interp.get("printHelloWorld",PyFunction.class);
func.__call__();
/*
PyFunction func =
(PyFunction)interp.get("loadGensimModel",PyFunction.class);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh.mm.ss");
System.out.println("======[" + sdf.format(new Date()) +
"]===========");
func.__call__(new PyString("cbow"));
System.out.println("======[" + sdf.format(new Date()) +
"]===========");
String tweeter_1 = "this is a test tweet" ;
String tweeter_2 = "also a test tweet" ;
String[] tweeter_1_words = tweeter_1.split("\\s++") ;
String[] tweeter_2_words = tweeter_2.split("\\s++") ;
func =
(PyFunction)interp.get("computeSimViaWord2Vec",PyFunction.class);
PyFloat similarity = (PyFloat) func.__call__(new PyString(tweeter_1),new PyString(tweeter_2));
System.out.println("similarity is " + similarity.asDouble()) ;
*/
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
JythonTest testObject = new JythonTest() ;
testObject.checkSimilarityOfTwoWords();
}
}