1919package  org .apache .streampipes .processors .textmining .jvm .processor .chunker ;
2020
2121import  org .apache .streampipes .commons .exceptions .SpRuntimeException ;
22+ import  org .apache .streampipes .extensions .api .pe .IStreamPipesDataProcessor ;
23+ import  org .apache .streampipes .extensions .api .pe .config .IDataProcessorConfiguration ;
2224import  org .apache .streampipes .extensions .api .pe .context .EventProcessorRuntimeContext ;
25+ import  org .apache .streampipes .extensions .api .pe .param .IDataProcessorParameters ;
2326import  org .apache .streampipes .extensions .api .pe .routing .SpOutputCollector ;
2427import  org .apache .streampipes .model .DataProcessorType ;
2528import  org .apache .streampipes .model .extensions .ExtensionAssetType ;
26- import  org .apache .streampipes .model .graph .DataProcessorDescription ;
2729import  org .apache .streampipes .model .runtime .Event ;
2830import  org .apache .streampipes .model .runtime .field .ListField ;
2931import  org .apache .streampipes .model .schema .PropertyScope ;
3032import  org .apache .streampipes .processors .textmining .jvm .processor .TextMiningUtil ;
3133import  org .apache .streampipes .sdk .builder .ProcessingElementBuilder ;
3234import  org .apache .streampipes .sdk .builder .StreamRequirementsBuilder ;
35+ import  org .apache .streampipes .sdk .builder .processor .DataProcessorConfiguration ;
3336import  org .apache .streampipes .sdk .helpers .EpProperties ;
3437import  org .apache .streampipes .sdk .helpers .EpRequirements ;
3538import  org .apache .streampipes .sdk .helpers .Labels ;
3639import  org .apache .streampipes .sdk .helpers .Locales ;
3740import  org .apache .streampipes .sdk .helpers .OutputStrategies ;
3841import  org .apache .streampipes .sdk .utils .Datatypes ;
39- import  org .apache .streampipes .wrapper .params .compat .ProcessorParams ;
40- import  org .apache .streampipes .wrapper .standalone .StreamPipesDataProcessor ;
4142
4243import  opennlp .tools .chunker .ChunkerME ;
4344import  opennlp .tools .chunker .ChunkerModel ;
4950import  java .util .Arrays ;
5051import  java .util .List ;
5152
52- public  class  ChunkerProcessor  extends   StreamPipesDataProcessor  {
53+ public  class  ChunkerProcessor  implements   IStreamPipesDataProcessor  {
5354
5455  private  static  final  String  TAGS_FIELD_KEY  = "tagsField" ;
5556  private  static  final  String  TOKENS_FIELD_KEY  = "tokensField" ;
@@ -62,44 +63,59 @@ public class ChunkerProcessor extends StreamPipesDataProcessor {
6263  private  ChunkerME  chunker ;
6364
6465  @ Override 
65-   public  DataProcessorDescription  declareModel () {
66-     return  ProcessingElementBuilder 
67-         .create ("org.apache.streampipes.processors.textmining.jvm.chunker" , 0 )
68-         .category (DataProcessorType .ENRICH_TEXT )
69-         .withAssets (ExtensionAssetType .DOCUMENTATION , ExtensionAssetType .ICON )
70-         .withLocales (Locales .EN )
71-         .requiredFile (Labels .withId (BINARY_FILE_KEY ))
72-         .requiredStream (StreamRequirementsBuilder 
73-             .create ()
74-             .requiredPropertyWithUnaryMapping (
75-                 EpRequirements .listRequirement (Datatypes .String ),
76-                 Labels .withId (TAGS_FIELD_KEY ),
77-                 PropertyScope .NONE )
78-             .requiredPropertyWithUnaryMapping (
79-                 EpRequirements .listRequirement (Datatypes .String ),
80-                 Labels .withId (TOKENS_FIELD_KEY ),
81-                 PropertyScope .NONE )
82-             .build ())
83-         .outputStrategy (OutputStrategies .append (
84-             EpProperties .listStringEp (
85-                 Labels .withId (CHUNK_TYPE_FIELD_KEY ),
86-                 CHUNK_TYPE_FIELD_KEY ,
87-                 "http://schema.org/ItemList" ),
88-             EpProperties .listStringEp (
89-                 Labels .withId (CHUNK_FIELD_KEY ),
90-                 CHUNK_FIELD_KEY ,
91-                 "http://schema.org/ItemList" )))
92-         .build ();
66+   public  IDataProcessorConfiguration  declareConfig () {
67+     return  DataProcessorConfiguration .create (
68+         ChunkerProcessor ::new ,
69+         ProcessingElementBuilder 
70+             .create ("org.apache.streampipes.processors.textmining.jvm.chunker" , 0 )
71+             .category (DataProcessorType .ENRICH_TEXT )
72+             .withAssets (ExtensionAssetType .DOCUMENTATION , ExtensionAssetType .ICON )
73+             .withLocales (Locales .EN )
74+             .requiredFile (Labels .withId (BINARY_FILE_KEY ))
75+             .requiredStream (StreamRequirementsBuilder 
76+                                 .create ()
77+                                 .requiredPropertyWithUnaryMapping (
78+                                     EpRequirements .listRequirement (Datatypes .String ),
79+                                     Labels .withId (TAGS_FIELD_KEY ),
80+                                     PropertyScope .NONE 
81+                                 )
82+                                 .requiredPropertyWithUnaryMapping (
83+                                     EpRequirements .listRequirement (Datatypes .String ),
84+                                     Labels .withId (TOKENS_FIELD_KEY ),
85+                                     PropertyScope .NONE 
86+                                 )
87+                                 .build ())
88+             .outputStrategy (OutputStrategies .append (
89+                 EpProperties .listStringEp (
90+                     Labels .withId (CHUNK_TYPE_FIELD_KEY ),
91+                     CHUNK_TYPE_FIELD_KEY ,
92+                     "http://schema.org/ItemList" 
93+                 ),
94+                 EpProperties .listStringEp (
95+                     Labels .withId (CHUNK_FIELD_KEY ),
96+                     CHUNK_FIELD_KEY ,
97+                     "http://schema.org/ItemList" 
98+                 )
99+             ))
100+             .build ()
101+     );
93102  }
94103
95104  @ Override 
96-   public  void  onInvocation (ProcessorParams  parameters ,
97-                            SpOutputCollector  spOutputCollector ,
98-                            EventProcessorRuntimeContext  context ) throws  SpRuntimeException  {
99-     this .tags  = parameters .extractor ().mappingPropertyValue (TAGS_FIELD_KEY );
100-     this .tokens  = parameters .extractor ().mappingPropertyValue (TOKENS_FIELD_KEY );
101-     String  filename  = parameters .extractor ().selectedFilename (BINARY_FILE_KEY );
102-     byte [] fileContent  = context .getStreamPipesClient ().fileApi ().getFileContent (filename );
105+   public  void  onPipelineStarted (
106+       IDataProcessorParameters  params ,
107+       SpOutputCollector  collector ,
108+       EventProcessorRuntimeContext  context 
109+   ) {
110+     this .tags  = params .extractor ()
111+                       .mappingPropertyValue (TAGS_FIELD_KEY );
112+     this .tokens  = params .extractor ()
113+                         .mappingPropertyValue (TOKENS_FIELD_KEY );
114+     String  filename  = params .extractor ()
115+                             .selectedFilename (BINARY_FILE_KEY );
116+     byte [] fileContent  = context .getStreamPipesClient ()
117+                                 .fileApi ()
118+                                 .getFileContent (filename );
103119
104120    InputStream  modelIn  = new  ByteArrayInputStream (fileContent );
105121    ChunkerModel  model ;
@@ -113,19 +129,23 @@ public void onInvocation(ProcessorParams parameters,
113129  }
114130
115131  @ Override 
116-   public  void  onEvent (Event  event ,
117-                       SpOutputCollector  collector ) throws  SpRuntimeException  {
118-     ListField  tags  = event .getFieldBySelector (this .tags ).getAsList ();
119-     ListField  tokens  = event .getFieldBySelector (this .tokens ).getAsList ();
132+   public  void  onEvent (Event  event , SpOutputCollector  collector ) throws  SpRuntimeException  {
133+     ListField  tags  = event .getFieldBySelector (this .tags )
134+                           .getAsList ();
135+     ListField  tokens  = event .getFieldBySelector (this .tokens )
136+                             .getAsList ();
120137
121- 
122-     String [] tagsArray  = tags .castItems (String .class ).toArray (String []::new );
123-     String [] tokensArray  = tokens .castItems (String .class ).toArray (String []::new );
138+     String [] tagsArray  = tags .castItems (String .class )
139+                              .toArray (String []::new );
140+     String [] tokensArray  = tokens .castItems (String .class )
141+                                  .toArray (String []::new );
124142
125143    Span [] spans  = chunker .chunkAsSpans (tokensArray , tagsArray );
126144
127145    List <String > chunks  = TextMiningUtil .extractSpans (spans , tokensArray );
128-     String [] types  = Arrays .stream (spans ).map (Span ::getType ).toArray (String []::new );
146+     String [] types  = Arrays .stream (spans )
147+                            .map (Span ::getType )
148+                            .toArray (String []::new );
129149
130150    event .addField (ChunkerProcessor .CHUNK_TYPE_FIELD_KEY , types );
131151    event .addField (ChunkerProcessor .CHUNK_FIELD_KEY , chunks );
@@ -134,7 +154,6 @@ public void onEvent(Event event,
134154  }
135155
136156  @ Override 
137-   public  void  onDetach () throws  SpRuntimeException  {
138- 
157+   public  void  onPipelineStopped () {
139158  }
140159}
0 commit comments