Skip to content

Commit 121260c

Browse files
committed
Merge branch 'ann'
2 parents b7d3502 + 5d06ed8 commit 121260c

File tree

6 files changed

+94
-44
lines changed

6 files changed

+94
-44
lines changed

dist/tag/js/tag.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
<p><input type="checkbox" data-option="tree"> Open tree view in modal</p>
149149
</div>
150150
</div>
151-
152151
</div>
153152

154153
<script src="dist/tag/js/tag.min.js"></script>

src/css/app.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ label[for="file-input"] {
210210
pointer-events:none;
211211
opacity:0.5;
212212
}
213+
213214
#taxonomy input.colorpicker:focus {
214215
border-color: white;
215216
}

src/js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ const Main = (function() {
295295
Promise.all(promises).then(files => {
296296
try {
297297
let message = parser.parseFiles(files);
298+
redrawVisualization();
298299
if (message) {
299-
redrawVisualization();
300300
printMessage(message);
301301
}
302302
}

src/js/parse/ann.js

Lines changed: 41 additions & 36 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) {
@@ -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
}

src/js/parse/parse.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import ReachParser from './reach.js';
22
import BratParser from './ann.js';
33
import load from '../xhr.js';
44

5+
const re = /.*(?=\.(\S+))|.*/;
6+
57
class Parser {
68
constructor() {
79
/* output */
@@ -19,11 +21,12 @@ class Parser {
1921
loadFile(path, format) {
2022
// get format from extension
2123
if (!format) {
22-
const extension = path.slice(path.lastIndexOf('.'));
23-
if (extension === '.json') {
24+
const extension = path.toLowerCase().match(re)[1];
25+
26+
if (extension === 'json') {
2427
format = 'json';
2528
}
26-
else if (extension === '.ann') {
29+
else {
2730
format = 'brat';
2831
}
2932
}
@@ -53,15 +56,57 @@ class Parser {
5356
}
5457
return file.name;
5558
}
59+
else if (files.length > 1) {
60+
// find 2 or 3 files that match in name
61+
files.sort((a, b) => a.name.localeCompare(b.name));
62+
63+
let matchingFiles = [];
64+
65+
let i = 0;
66+
let iname = files[i].name.match(re);
67+
for (let j = 1; j < files.length; ++j) {
68+
let jname = files[j].name.match(re);
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;
81+
}
82+
break;
83+
}
84+
}
85+
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+
}
99+
}
100+
}
56101
}
57102

58103
parseJson(data) {
59104
this.reach.parse(data);
60105
this.parsedData = this.reach.data;
61106
}
62107

63-
parseText(text) {
64-
this.ann.parse(text);
108+
parseText() {
109+
this.ann.parse.apply(this.ann, arguments);
65110
this.parsedData = this.ann.data;
66111
}
67112
}

0 commit comments

Comments
 (0)