@@ -10,8 +10,9 @@ class BratParser {
1010/*
1111 @param textInput : Source text or input in standoff format
1212 @param annInput : BRAT annotation or {undefined}
13+ @param evtInput : event annotations or {undefined}
1314 */
14- parse ( textInput , annInput ) {
15+ parse ( textInput , annInput , evtInput ) {
1516 var output = {
1617 texts : [ ] ,
1718 events : [ ] ,
@@ -33,6 +34,10 @@ class BratParser {
3334 } else {
3435 text = textInput ;
3536 lines = annInput . split ( '\n' ) ;
37+ if ( evtInput ) {
38+ lines = lines . concat (
39+ evtInput . split ( '\n' ) ) ;
40+ }
3641 }
3742
3843 if ( ! text ) {
@@ -133,7 +138,7 @@ class BratParser {
133138 ++ tbm_i ;
134139 }
135140 }
136- else if ( text [ ch ] === ' ' ) {
141+ else if ( / \s / . test ( text [ ch ] ) ) {
137142 if ( token_start < ch ) {
138143 tokens . push ( {
139144 word : text . slice ( token_start , ch ) ,
@@ -238,7 +243,7 @@ class BratParser {
238243 trigger = tokens [ 1 ] ,
239244 args = tokens . slice ( 2 ) ;
240245
241- if ( id > 0 && trigger ) {
246+ if ( id > 0 && trigger && args . length > 0 ) {
242247 let split = trigger . split ( this . re ) ;
243248 if ( split [ 0 ] . length > 0 && mentions [ split [ 1 ] ] ) {
244249
@@ -265,42 +270,42 @@ class BratParser {
265270 }
266271
267272 parseRelationMention ( tokens , mentions ) {
268- const id = + tokens [ 0 ] . slice ( 1 ) ,
269- label = tokens [ 1 ] ,
270- arg1 = tokens [ 2 ] ,
271- arg2 = tokens [ 3 ] ;
272-
273- if ( id > 0 && arg2 ) {
274- const split1 = arg1 . split ( this . re ) ,
275- split2 = arg2 . split ( this . re ) ;
276-
277- if ( mentions [ split1 [ 1 ] ] && mentions [ split2 [ 1 ] ] ) {
278- return {
279- id : 'R' + id ,
280- label,
281- arguments : [ {
282- type : split1 [ 0 ] ,
283- id : split1 [ 1 ]
284- } , {
285- type : split2 [ 0 ] ,
286- id : split2 [ 1 ]
287- } ]
288- } ;
273+ const id = + tokens [ 0 ] . slice ( 1 ) ,
274+ label = tokens [ 1 ] ,
275+ arg1 = tokens [ 2 ] ,
276+ arg2 = tokens [ 3 ] ;
277+
278+ if ( id > 0 && arg2 ) {
279+ const split1 = arg1 . split ( this . re ) ,
280+ split2 = arg2 . split ( this . re ) ;
281+
282+ if ( mentions [ split1 [ 1 ] ] && mentions [ split2 [ 1 ] ] ) {
283+ return {
284+ id : 'R' + id ,
285+ label,
286+ arguments : [ {
287+ type : split1 [ 0 ] ,
288+ id : split1 [ 1 ]
289+ } , {
290+ type : split2 [ 0 ] ,
291+ id : split2 [ 1 ]
292+ } ]
293+ } ;
294+ }
289295 }
290296 }
291- }
292297
293- parseAttributes ( tokens , mentions ) {
294- const id = + tokens [ 0 ] . slice ( 1 ) ,
295- attribute = tokens [ 1 ] ,
296- target = tokens [ 2 ] ;
297-
298- if ( id > 0 && mentions [ target ] ) {
299- return {
300- id,
301- target,
302- attribute,
303- value : tokens . slice ( 3 ) . join ( ' ' )
298+ parseAttribute ( tokens , mentions ) {
299+ const id = + tokens [ 0 ] . slice ( 1 ) ,
300+ attribute = tokens [ 1 ] ,
301+ target = tokens [ 2 ] ;
302+
303+ if ( id > 0 && mentions [ target ] ) {
304+ return {
305+ id,
306+ target,
307+ attribute,
308+ value : tokens . slice ( 3 ) . join ( ' ' )
304309 } ;
305310 }
306311 }
0 commit comments