Package featuregenerator :: Package meteor :: Module testmeteor
[hide private]
[frames] | no frames]

Source Code for Module featuregenerator.meteor.testmeteor

 1  ''' 
 2  Created on 22 Jun 2012 
 3   
 4  @author: Eleftherios Avramidis 
 5  ''' 
 6  from py4j.java_gateway import JavaGateway, GatewayClient, java_import 
 7   
 8  import multiprocessing, time, random 
 9  from util.jvm import JVM 
10   
11 -def singlethread(java_classpath):
12 print "Thread starting" 13 14 jvm = JVM(java_classpath, dir_path) 15 socket_no = self.jvm.socket_no 16 gatewayclient = GatewayClient('localhost', socket_no) 17 gateway = JavaGateway(gatewayclient, auto_convert=True, auto_field=True) 18 sys.stderr.write("Initialized global Java gateway with pid {} in socket {}\n".format(self.jvm.pid, socket_no)) 19 20 21 gatewayclient = GatewayClient('localhost', socket_no) 22 print "Gclient started" 23 gateway = JavaGateway(gatewayclient, auto_convert=True, auto_field=True) 24 print "Java Gateway started" 25 #create a new view for the jvm 26 meteor_view = gateway.new_jvm_view() 27 #import required packages 28 java_import(meteor_view, 'edu.cmu.meteor.scorer.*') 29 #initialize the java object 30 java_import(meteor_view, 'edu.cmu.meteor.util.*') 31 print "Modules imported" 32 #pass the language setting into the meteor configuration object 33 config = meteor_view.MeteorConfiguration(); 34 config.setLanguage("en"); 35 scorer = meteor_view.MeteorScorer(config) 36 print "object initialized" 37 #run object function 38 stats = scorer.getMeteorStats("Test sentence", "Test sentence !"); 39 print stats.score 40 return 1
41 42 43 if __name__ == '__main__': 44 45 # gatewayclient = GatewayClient('localhost', socket_no) 46 47 java_classpath = "" 48 49 p = multiprocessing.Pool(3) 50 print "Multipool initialized" 51 p.map(singlethread, [java_classpath, java_classpath, java_classpath]) 52 53 54 55 56 57 if __name__ == '__main__': 58 pass 59