1515
1616logger = logging .getLogger (__name__ )
1717
18+
1819class LocalPipeline (PipelineBase ):
1920 def __init__ (self ):
2021 """
2122 Constructor to set up local pipeline
2223
2324 @param: file_name, the file name of the custom config file
2425 """
25- super (LocalPipeline ,self ).__init__ ()
26+ super (LocalPipeline , self ).__init__ ()
2627
2728 self .PipelineFactory = None
2829 self .pipeline = None
2930 self .ProtobufSerializer = None
3031
31- pipeline_config .log_current_config (self .config , False )
32+ pipeline_config .log_current_config (self .config , False )
3233
3334 # set up JVM and load classes needed
3435 try :
3536 import jnius_config
3637 jnius_config .add_options ('-Xmx16G' )
37- jnius_config .add_classpath (get_model_path ()+ '/*' )
38- except :
39- logger .warn ("Couldn't set JVM config; this might be because you're setting up the multiple instances of the local pipeline." )
38+ jnius_config .add_classpath (get_model_path () + '/*' )
39+ except Exception as e :
40+ logger .warning (
41+ "Couldn't set JVM config; this might be because you're setting up the multiple instances of the local pipeline." )
42+ logger .warning (str (e ))
4043 try :
4144 from jnius import autoclass
4245 self .PipelineFactory = autoclass ('edu.illinois.cs.cogcomp.pipeline.main.PipelineFactory' )
4346 self .SerializationHelper = autoclass ('edu.illinois.cs.cogcomp.core.utilities.SerializationHelper' )
4447 self .ProtobufSerializer = autoclass ('edu.illinois.cs.cogcomp.core.utilities.protobuf.ProtobufSerializer' )
4548 self .Boolean = autoclass ('java.lang.Boolean' )
49+ self .JString = autoclass ('java.lang.String' )
4650 except Exception as e :
4751 logger .error ('Fail to load models, please check if your Java version is up to date.' )
52+ logger .error (str (e ))
4853 return None
4954 self .pipeline = self .PipelineFactory .buildPipelineWithAllViews (self .Boolean (True ))
5055
5156 logger .info ("pipeline has been set up" )
5257
53-
5458 def call_server (self , text , views ):
5559 """
5660 Funtion to get preprocess text annotation from local pipeline
@@ -60,14 +64,21 @@ def call_server(self, text, views):
6064 @return: raw text of the response from local pipeline
6165 """
6266 view_list = views .split (',' )
63- text_annotation = self .pipeline .createBasicTextAnnotation ("" , "" , text )
67+ text_annotation = self .pipeline .createBasicTextAnnotation (self .JString ("" ), self .JString ("" ),
68+ self .JString (text ))
6469 for view in view_list :
65- self .pipeline .addView (text_annotation , view .strip ())
66- #json = SerializationHelper.serializeToJson(text_annotation)
70+ if (len (view .strip ()) > 0 ):
71+ try :
72+ self .pipeline .addView (text_annotation , self .JString (view .strip ()))
73+ except Exception as e :
74+ logger .error ('Failed to add view ' + view .strip ())
75+ logger .error (str (e ))
76+
77+ # json = SerializationHelper.serializeToJson(text_annotation)
6778
6879 path = os .path .expanduser ('~' ) + "{0}.ccg_nlpy{0}" .format (os .path .sep ) + 'temp.temp'
6980
70- self .ProtobufSerializer .writeToFile (text_annotation ,path )
81+ self .ProtobufSerializer .writeToFile (text_annotation , self . JString ( path ) )
7182 proto_data = None
7283 with open (path , 'rb' ) as f :
7384 proto_data = f .read ()
@@ -77,4 +88,3 @@ def call_server(self, text, views):
7788 proto_to_json = json_format .MessageToJson (message )
7889
7990 return proto_to_json
80-
0 commit comments