var NAMES_TYPES = ['forename', 'addName', 'surname', 'bloc', 'country', 'date', 'district', 'geogName', 'orgName', 'persName', 'placeName', 'region', 'settlement', 'time']; var namesCollData; var webFontURLs; if (typeof String.prototype.startsWith != 'function') { // see below for better implementation! String.prototype.startsWith = function(str) { return this.indexOf(str) == 0; }; } function getNameColor(type) { if ($.inArray(type, ['geogName']) != -1) { return '#B85C00'; } else if ($.inArray(type, ['country', 'region', 'bloc', 'district', 'settlement']) != -1) { return '#FF6600'; } else if ($.inArray(type, ['placeName']) != -1) { return '#FF8533'; } else if ($.inArray(type, ['persName']) != -1) { return '#0066FF'; } else if ($.inArray(type, ['forename', 'addName']) != -1) { return '#66A3FF'; } else if ($.inArray(type, ['surname']) != -1) { return '#00CCFF'; } else if ($.inArray(type, ['orgName']) != -1) { return '#33D633'; } else if ($.inArray(type, ['date', 'time']) != -1) { return '#FFFF66'; } } function bratInitialize(bratLocation) { head.js( // brat helper modules bratLocation + 'client/src/configuration.js', bratLocation + 'client/src/util.js', bratLocation + 'client/src/annotation_log.js', bratLocation + 'client/lib/webfont.js', // brat modules bratLocation + 'client/src/dispatcher.js', bratLocation + 'client/src/url_monitor.js', bratLocation + 'client/src/visualizer.js'); webFontURLs = [bratLocation + 'static/fonts/Astloch-Bold.ttf', bratLocation + 'static/fonts/PT_Sans-Caption-Web-Regular.ttf', bratLocation + 'static/fonts/Liberation_Sans-Regular.ttf']; var named_entity_types = []; $.each(NAMES_TYPES, function(idx, t) { var entity_type = { 'type': t, 'labels': [t], // Blue is a nice colour for a person? 'bgColor': getNameColor(t), // Use a slightly darker version of the bgColor for the border 'borderColor': 'darken' }; named_entity_types.push(entity_type); }); namesCollData = { 'entity_types': named_entity_types }; } function bratVisualizeNames(elementId, text) { var entities = []; $.each(text.namedEntities, function(entityIdx, name) { if (typeof(name.relAdj) !=='undefined') { entities.push(['N' + entityIdx + ".1", 'relAdj', [[name.startIdx, name.endIdx]]]); } entities.push(['N' + entityIdx, name.subtype ? name.subtype : name.type, [[name.startIdx, name.endIdx]]]); }); var docData = { 'text': text.text, 'entities': entities }; // console.debug(JSON.stringify(docData)); Util.embed(elementId, namesCollData, docData, []); }