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