@@ -109,14 +109,9 @@ var nlp = function ( theModel, pipe ) {
109109 // Used to innstantiate the compiler.
110110 var cerMetaModel ;
111111
112- // Annotation stuff .
112+ // Contains a list of valid annotations built from `theModel` .
113113 var validAnnotations = Object . create ( null ) ;
114- validAnnotations . sbd = true ;
115- validAnnotations . negation = true ;
116- validAnnotations . sentiment = true ;
117- validAnnotations . pos = true ;
118- validAnnotations . ner = true ;
119- validAnnotations . cer = true ;
114+
120115 // Current pipe.
121116 var currPipe = Object . create ( null ) ;
122117 var onlyTokenization = true ;
@@ -231,6 +226,9 @@ var nlp = function ( theModel, pipe ) {
231226 // Markings are 4-tuples of `start`, `end` **token indexes**, and `begin & end markers`.
232227 // The begin & end markers are used to markup the tokens specified.
233228 rdd . markings = [ ] ;
229+ // Publish the current annotation pipeline so that code can inquire about
230+ // active annotations!
231+ rdd . currPipe = currPipe ;
234232
235233 var wrappedDocData = DocDataWrapper ( rdd ) ; // eslint-disable-line new-cap
236234
@@ -395,6 +393,15 @@ var nlp = function ( theModel, pipe ) {
395393 throw Error ( 'wink-nlp: invalid model used.' ) ;
396394 }
397395
396+ // Build a list of valid annotations from `theModel`. This will ensure that
397+ // only **available** annotations from the model can be used in the pipe.
398+ validAnnotations . sbd = typeof theModel . sbd === 'function' ;
399+ validAnnotations . negation = typeof theModel . negation === 'function' ;
400+ validAnnotations . sentiment = typeof theModel . sa === 'function' ;
401+ validAnnotations . pos = typeof theModel . pos === 'function' ;
402+ validAnnotations . ner = typeof theModel . ner === 'function' ;
403+ validAnnotations . cer = typeof theModel . metaCER === 'function' ;
404+
398405 const tempPipe = ( pipe === undefined ) ? Object . keys ( validAnnotations ) : pipe ;
399406 if ( helper . isArray ( tempPipe ) ) {
400407 tempPipe . forEach ( ( at ) => {
0 commit comments