Skip to content

Commit 5d06ed8

Browse files
committed
edits to ann parse: handle .a1 .a2 input
1 parent 1e479e6 commit 5d06ed8

File tree

4 files changed

+97
-57
lines changed

4 files changed

+97
-57
lines changed

dist/tag/js/tag.min.js

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33532,6 +33532,12 @@ Main.init();
3353233532
},{"./components/link.js":74,"./components/word.js":77,"./components/wordcluster.js":78,"./managers/labelmanager.js":80,"./managers/rowmanager.js":81,"./managers/taxonomy.js":82,"./managers/tooltip.js":83,"./parse/parse.js":85,"./treelayout.js":87,"./ymljson.js":89,"svg.js":66}],80:[function(require,module,exports){
3353333533
'use strict';
3353433534

33535+
var _link = require('../components/link.js');
33536+
33537+
var _link2 = _interopRequireDefault(_link);
33538+
33539+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33540+
3353533541
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3353633542

3353733543
module.exports = function () {
@@ -33574,7 +33580,7 @@ module.exports = function () {
3357433580
function stopEditing() {
3357533581
if (activeObject && activeObject.isEditing) {
3357633582
var text = activeObject.text();
33577-
if (text && !(activeObject instanceof Link)) {
33583+
if (text && !(activeObject instanceof _link2.default)) {
3357833584
_svg.fire('label-updated', { object: text, label: text.text() });
3357933585
}
3358033586
activeObject.stopEditing();
@@ -33638,7 +33644,7 @@ module.exports = function () {
3363833644
return LabelManager;
3363933645
}();
3364033646

33641-
},{}],81:[function(require,module,exports){
33647+
},{"../components/link.js":74}],81:[function(require,module,exports){
3364233648
'use strict';
3364333649

3364433650
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
@@ -34420,12 +34426,13 @@ var BratParser = function () {
3442034426
/*
3442134427
@param textInput : Source text or input in standoff format
3442234428
@param annInput : BRAT annotation or {undefined}
34429+
@param evtInput : event annotations or {undefined}
3442334430
*/
3442434431

3442534432

3442634433
_createClass(BratParser, [{
3442734434
key: 'parse',
34428-
value: function parse(textInput, annInput) {
34435+
value: function parse(textInput, annInput, evtInput) {
3442934436
var output = {
3443034437
texts: [],
3443134438
events: [],
@@ -34448,6 +34455,9 @@ var BratParser = function () {
3444834455
} else {
3444934456
text = textInput;
3445034457
lines = annInput.split('\n');
34458+
if (evtInput) {
34459+
lines = lines.concat(evtInput.split('\n'));
34460+
}
3445134461
}
3445234462

3445334463
if (!text) {
@@ -34662,7 +34672,7 @@ var BratParser = function () {
3466234672
trigger = tokens[1],
3466334673
args = tokens.slice(2);
3466434674

34665-
if (id > 0 && trigger & args.length > 0) {
34675+
if (id > 0 && trigger && args.length > 0) {
3466634676
var split = trigger.split(this.re);
3466734677
if (split[0].length > 0 && mentions[split[1]]) {
3466834678

@@ -34816,40 +34826,57 @@ var Parser = function () {
3481634826
}
3481734827
return file.name;
3481834828
} else if (files.length > 1) {
34819-
// find two files that match in name
34829+
// find 2 or 3 files that match in name
3482034830
files.sort(function (a, b) {
3482134831
return a.name.localeCompare(b.name);
3482234832
});
3482334833

34824-
// file to check against
34834+
var matchingFiles = [];
34835+
3482534836
var i = 0;
3482634837
var iname = files[i].name.match(re);
34827-
34828-
var annRe = /a/;
34829-
var txtRe = /s/;
34830-
3483134838
for (var j = 1; j < files.length; ++j) {
3483234839
var jname = files[j].name.match(re);
34833-
if (jname[1] && jname[1] !== 'txt' && jname[1] !== 'ann') {
34834-
// not a valid extension
34835-
++i;
34836-
continue;
34837-
}
34838-
34839-
// check if name matches
34840-
if (jname[0] === iname[0]) {
34841-
if (iname[1] === 'ann' && jname[1] !== 'ann') {
34842-
this.parseText(files[j].content, files[i].content);
34843-
return;
34844-
} else if ((iname[1] === 'txt' || !iname[1]) && jname[1] === 'ann') {
34845-
this.parseText(files[i].content, files[j].content);
34846-
return;
34840+
if (jname[1] && jname[0] === iname[0]) {
34841+
matchingFiles.push(files[i], files[j]);
34842+
34843+
var k = j + 1;
34844+
while (k < files.length) {
34845+
var kname = files[k].name.match(re);
34846+
if (kname[1] && kname[0] === iname[0]) {
34847+
matchingFiles.push(files[k]);
34848+
} else {
34849+
break;
34850+
}
34851+
++k;
3484734852
}
34853+
break;
3484834854
}
34855+
}
3484934856

34850-
// iterate to next file
34851-
++i;
34852-
iname = jname;
34857+
// found matching files
34858+
if (matchingFiles.length === 2) {
34859+
// find text content
34860+
var text = matchingFiles.find(function (file) {
34861+
return file.name.endsWith('.txt');
34862+
});
34863+
var standoff = matchingFiles.find(function (file) {
34864+
return !file.name.endsWith('.txt');
34865+
});
34866+
this.parseText(text.content, standoff.content);
34867+
} else {
34868+
var _text = matchingFiles.find(function (file) {
34869+
return file.name.endsWith('.txt');
34870+
});
34871+
var entities = matchingFiles.find(function (file) {
34872+
return file.name.endsWith('.a1');
34873+
});
34874+
var evts = matchingFiles.find(function (file) {
34875+
return file.name.endsWith('.a2');
34876+
});
34877+
if (_text && evts && entities) {
34878+
this.parseText(_text.content, entities.content, evts.content);
34879+
}
3485334880
}
3485434881
}
3485534882
}
@@ -34861,8 +34888,8 @@ var Parser = function () {
3486134888
}
3486234889
}, {
3486334890
key: 'parseText',
34864-
value: function parseText(text, ann) {
34865-
this.ann.parse(text, ann);
34891+
value: function parseText() {
34892+
this.ann.parse.apply(this.ann, arguments);
3486634893
this.parsedData = this.ann.data;
3486734894
}
3486834895
}]);

src/js/managers/labelmanager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Link from '../components/link.js';
2+
13
module.exports = (function() {
24
let _svg;
35
let activeObject = null;

src/js/parse/ann.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
@@ -238,7 +243,7 @@ class BratParser {
238243
trigger = tokens[1],
239244
args = tokens.slice(2);
240245

241-
if (id > 0 && trigger & args.length > 0) {
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

src/js/parse/parse.js

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,45 @@ class Parser {
5757
return file.name;
5858
}
5959
else if (files.length > 1) {
60-
// find two files that match in name
60+
// find 2 or 3 files that match in name
6161
files.sort((a, b) => a.name.localeCompare(b.name));
6262

63-
// file to check against
63+
let matchingFiles = [];
64+
6465
let i = 0;
6566
let iname = files[i].name.match(re);
66-
67-
let annRe = /a/;
68-
let txtRe = /s/;
69-
7067
for (let j = 1; j < files.length; ++j) {
7168
let jname = files[j].name.match(re);
72-
if (jname[1] && jname[1] !== 'txt' && jname[1] !== 'ann') {
73-
// not a valid extension
74-
++i;
75-
continue;
76-
}
77-
78-
// check if name matches
79-
if (jname[0] === iname[0]) {
80-
if (iname[1] === 'ann' && jname[1] !== 'ann') {
81-
this.parseText(files[j].content, files[i].content);
82-
return;
83-
}
84-
else if ((iname[1] === 'txt' || !iname[1]) && jname[1] === 'ann') {
85-
this.parseText(files[i].content, files[j].content);
86-
return;
69+
if (jname[1] && jname[0] === iname[0]) {
70+
matchingFiles.push(files[i], files[j]);
71+
72+
let k = j + 1;
73+
while (k < files.length) {
74+
let kname = files[k].name.match(re);
75+
if (kname[1] && kname[0] === iname[0]) {
76+
matchingFiles.push(files[k]);
77+
} else {
78+
break;
79+
}
80+
++k;
8781
}
82+
break;
8883
}
84+
}
8985

90-
// iterate to next file
91-
++i;
92-
iname = jname;
86+
// found matching files
87+
if (matchingFiles.length === 2) {
88+
// find text content
89+
let text = matchingFiles.find(file => file.name.endsWith('.txt'));
90+
let standoff = matchingFiles.find(file => !file.name.endsWith('.txt'));
91+
this.parseText(text.content, standoff.content);
92+
} else {
93+
let text = matchingFiles.find(file => file.name.endsWith('.txt'));
94+
let entities = matchingFiles.find(file => file.name.endsWith('.a1'));
95+
let evts = matchingFiles.find(file => file.name.endsWith('.a2'));
96+
if (text && evts && entities) {
97+
this.parseText(text.content, entities.content, evts.content)
98+
}
9399
}
94100
}
95101
}
@@ -99,8 +105,8 @@ class Parser {
99105
this.parsedData = this.reach.data;
100106
}
101107

102-
parseText(text, ann) {
103-
this.ann.parse(text, ann);
108+
parseText() {
109+
this.ann.parse.apply(this.ann, arguments);
104110
this.parsedData = this.ann.data;
105111
}
106112
}

0 commit comments

Comments
 (0)