- 1 :
Ext.define('Voyant.panel.Entities', {
- 2 :
extend: 'Ext.panel.Panel',
- 3 :
mixins: ['Voyant.panel.Panel'],
- 4 :
alias: 'widget.entities',
- 5 :
- 6 :
statics: {
- 7 :
i18n: {
- 8 :
title: 'Named Entity Recognition',
- 9 :
entity: 'Entity',
- 10 :
lemma: 'Lemma',
- 11 :
classification: 'Classification',
- 12 :
document: 'Document',
- 13 :
start: 'Start',
- 14 :
end: 'End',
- 15 :
entityType: 'entity type',
- 16 :
nerVoyant: 'Entity Identification with Voyant',
- 17 :
nerNssi: 'Entity Identification with NSSI',
- 18 :
nerSpacy: 'Entity Identification with SpaCy',
- 19 :
},
- 20 :
api: {
- 21 :
/**
- 22 :
* @memberof Tools.Contexts
- 23 :
* @instance
- 24 :
* @property {docId}
- 25 :
*/
- 26 :
docId: undefined,
- 27 :
}
- 28 :
},
- 29 :
- 30 :
constructor: function(config) {
- 31 :
this.mixins['Voyant.util.Api'].constructor.apply(this, arguments);
- 32 :
this.callParent(arguments);
- 33 :
this.mixins['Voyant.panel.Panel'].constructor.apply(this, arguments);
- 34 :
},
- 35 :
- 36 :
initComponent: function() {
- 37 :
var me = this;
- 38 :
- 39 :
Ext.apply(me, {
- 40 :
title: this.localize('title'),
- 41 :
layout: 'fit',
- 42 :
items: [{
- 43 :
xtype: 'entitieslist',
- 44 :
listeners: {
- 45 :
boxready: function(cmp) {
- 46 :
cmp.getColumns().forEach(function(col) {
- 47 :
col.show();
- 48 :
})
- 49 :
},
- 50 :
scope: this
- 51 :
}
- 52 :
}],
- 53 :
dockedItems: [{
- 54 :
dock: 'bottom',
- 55 :
xtype: 'toolbar',
- 56 :
items: [{
- 57 :
xtype: 'corpusdocumentselector'
- 58 :
},{
- 59 :
itemId: 'annotatorType',
- 60 :
xtype: 'combo',
- 61 :
queryMode: 'local',
- 62 :
triggerAction: 'all',
- 63 :
fieldLabel: 'NER Annotator',
- 64 :
labelAlign: 'right',
- 65 :
value: 'spacy',
- 66 :
forceSelection: true,
- 67 :
allowBlank: false,
- 68 :
editable: false,
- 69 :
valueField: 'value',
- 70 :
displayField: 'name',
- 71 :
store: new Ext.data.ArrayStore({
- 72 :
fields: ['name', 'value'],
- 73 :
data: [['Spacy', 'spacy'], ['NSSI', 'nssi'], ['Voyant', 'stanford']]
- 74 :
})
- 75 :
},{
- 76 :
xtype: 'button',
- 77 :
text: 'Find Entities',
- 78 :
handler: function(btn) {
- 79 :
var annotator = btn.up().queryById('annotatorType').getValue();
- 80 :
if (annotator !== null) {
- 81 :
this.nerServiceHandler(annotator);
- 82 :
}
- 83 :
},
- 84 :
scope: this
- 85 :
},'->',{
- 86 :
xtype: 'textfield',
- 87 :
itemId: 'entitySearch',
- 88 :
fieldLabel: 'Filter Entities',
- 89 :
labelAlign: 'right',
- 90 :
enableKeyEvents: true,
- 91 :
triggers: {
- 92 :
search: {
- 93 :
cls: 'fa-trigger form-fa-search-trigger',
- 94 :
handler: function(cmp) {
- 95 :
this.searchEntities(cmp.getValue());
- 96 :
},
- 97 :
scope: this
- 98 :
}
- 99 :
},
- 100 :
listeners: {
- 101 :
keyup: function(cmp, e) {
- 102 :
if (e.getCharCode() === 13) {
- 103 :
this.searchEntities(cmp.getValue());
- 104 :
}
- 105 :
},
- 106 :
scope: this
- 107 :
}
- 108 :
}]
- 109 :
}],
- 110 :
listeners: {
- 111 :
corpusSelected: function(src, corpus) {
- 112 :
this.setApiParam('docId', undefined);
- 113 :
},
- 114 :
- 115 :
documentsSelected: function(src, docIds) {
- 116 :
this.setApiParam('docId', docIds);
- 117 :
},
- 118 :
- 119 :
entitiesClicked: function(src, ents) {
- 120 :
},
- 121 :
- 122 :
entityLocationClicked: function(src, ent) {
- 123 :
},
- 124 :
- 125 :
scope: this
- 126 :
}
- 127 :
});
- 128 :
- 129 :
me.callParent(arguments);
- 130 :
},
- 131 :
- 132 :
nerServiceHandler: function(annotator) {
- 133 :
var entitiesList = this.down('entitieslist');
- 134 :
entitiesList.clearEntities();
- 135 :
entitiesList.getEntities(annotator, this.getApiParam('docId'));
- 136 :
},
- 137 :
- 138 :
searchEntities: function(query) {
- 139 :
query = query.trim().toLowerCase();
- 140 :
var entitiesList = this.down('entitieslist');
- 141 :
if (query.length > 0) {
- 142 :
entitiesList.getStore().filterBy(function(record) {
- 143 :
return record.getTerm().toLowerCase().indexOf(query) !== -1;
- 144 :
});
- 145 :
entitiesList.getView().findFeature('grouping').expandAll();
- 146 :
} else {
- 147 :
entitiesList.getStore().clearFilter();
- 148 :
entitiesList.getView().findFeature('grouping').collapseAll();
- 149 :
}
- 150 :
}
- 151 :
});
- 152 :