@@ -222,3 +222,53 @@ describe( 'Detect from learned examples', function () {
222222 expect ( d1 . tokens ( ) . itemAt ( 22 ) . parentCustomEntity ( ) . out ( its . detail ) ) . to . deep . equal ( expectedEntities [ 5 ] ) ;
223223 } ) ;
224224} ) ;
225+
226+ describe ( 'Mark forward, backward & out of bound' , function ( ) {
227+ const text = 'My best friend has a fluffy cat and fat dog.' ;
228+
229+ var forwardExample = [
230+ { name : 'forward' , patterns : [ 'DET ADJ NOUN' ] , mark : [ 2 , 2 ] }
231+ ] ;
232+
233+ var backwardExample = [
234+ { name : 'forward' , patterns : [ '[|DET] [ADJ] [NOUN]' ] , mark : [ - 2 , - 1 ] }
235+ ] ;
236+
237+ var noMarkExample = [
238+ { name : 'forward' , patterns : [ '[|DET] [ADJ] [NOUN]' ] }
239+ ] ;
240+
241+ var outOfBoundExample = [
242+ { name : 'forward' , patterns : [ '[|DET] [ADJ] [NOUN]' ] , mark : [ - 20 , 10 ] }
243+ ] ;
244+
245+ it ( 'forward example must work correctly' , function ( ) {
246+ const nlp1 = winkNLP ( model ) ;
247+ nlp1 . learnCustomEntities ( forwardExample ) ;
248+ var d1 = nlp1 . readDoc ( text ) ;
249+ expect ( d1 . customEntities ( ) . out ( ) ) . to . deep . equal ( [ 'cat' ] ) ;
250+ } ) ;
251+
252+ it ( 'backward example must work correctly' , function ( ) {
253+ const nlp2 = winkNLP ( model ) ;
254+ nlp2 . learnCustomEntities ( backwardExample ) ;
255+ var d2 = nlp2 . readDoc ( text ) ;
256+ expect ( d2 . customEntities ( ) . out ( ) ) . to . deep . equal ( [ 'best friend' , 'fluffy cat' , 'fat dog' ] ) ;
257+ } ) ;
258+
259+ it ( '"No mark example" must work correctly' , function ( ) {
260+ // contrast with the backward example — no mark & out of bound produce same results!
261+ const nlp3 = winkNLP ( model ) ;
262+ nlp3 . learnCustomEntities ( noMarkExample ) ;
263+ var d3 = nlp3 . readDoc ( text ) ;
264+ expect ( d3 . customEntities ( ) . out ( ) ) . to . deep . equal ( [ 'best friend' , 'a fluffy cat' , 'fat dog' ] ) ;
265+ } ) ;
266+
267+ it ( 'out of bound example must work correctly' , function ( ) {
268+ // contrast with the backward example — no mark & out of bound produce same results!
269+ const nlp4 = winkNLP ( model ) ;
270+ nlp4 . learnCustomEntities ( outOfBoundExample ) ;
271+ var d4 = nlp4 . readDoc ( text ) ;
272+ expect ( d4 . customEntities ( ) . out ( ) ) . to . deep . equal ( [ 'best friend' , 'a fluffy cat' , 'fat dog' ] ) ;
273+ } ) ;
274+ } ) ;
0 commit comments