1  /** @author Amit Kumar
  2  * @date 03/20/2008
  3  * @since 1.2M1
  4  * @extends Workbench.component.Component
  5  * @description This component displays workset comparison
  6  */
  7 String.prototype.ellipse = function(maxLength){
  8     if(this.length > maxLength){
  9         return this.substr(0, maxLength-3) + '...';
 10     }
 11     return this;
 12 };
 13 Monk.component.WorksetSimilarityComparisonComponent = function(args) {
 14   this.searchParams = {'corpusCriterion':'*','limit':1200,'start':0};
 15    var worksetReader=new Ext.data.XmlReader({record : 'workset', id : '@id'}
 16                 , new Ext.data.Record.create([
 17                 {name : 'value', mapping : '@id'},
 18                 {name: 'label', mapping:'label', convert: function(value){return value.ellipse(10)}},
 19                 {name: 'type',mapping: 'label', convert: function(value){return 'workset'}},
 20                 {name:'count', mapping:'workList', type: 'int', convert: function(value){
 21                     if(value==null){
 22                         return 0;
 23                     }
 24                     return value.split(',').length;
 25                 }}
 26                 ]));
 27                 
 28      this.filterLemmaStore=new Ext.data.SimpleStore({
 29      fields: ['id','label','label']
 30      , data : [['2','2',"2"],
 31      ["3","3","3"],["4","4","4"],
 32      ["5","5","5"],["6","6","6"],
 33      ["7","7","7"],["8","8","8"]
 34      ]
 35     });
 36   
 37      this.featureLenStore=new Ext.data.SimpleStore({
 38      fields: ['id','label','label']
 39      , data : [['2','2',"2"],
 40      ["3","3","3"],["4","4","4"],
 41      ["5","5","5"],["6","6","6"],
 42      ["7","7","7"],["8","8","8"]
 43      ]
 44     });
 45     
 46     this.featureFreqStore=new Ext.data.SimpleStore({
 47      fields: ['id','label','label']
 48      , data : [['2','2',"2"],
 49      ["3","3","3"],["4","4","4"],
 50      ["5","5","5"],["6","6","6"],
 51      ["7","7","7"],["8","8","8"]
 52      ]
 53     });
 54     
 55      this.featureFreqDocumentStore=new Ext.data.SimpleStore({
 56      fields: ['id','label','label']
 57      , data : [['2','2',"2"],
 58      ["5","5","5"],["10","10","10"],
 59      ["15","15","15"],["20","20","20"],
 60      ["25","25","25"],["50","50","50"]
 61      ]
 62     });
 63      
 64                 
 65 
 66   
 67   
 68     this.featureCountStore=new Ext.data.SimpleStore({
 69          fields: ['value','label']
 70          , data : [['10','10'],
 71          ['20','20'],
 72          ["30","30"],
 73          ["50","50"]
 74          ]
 75     });
 76     
 77     
 78     this.methodStore=new Ext.data.SimpleStore({
 79          fields: ['value','label']
 80          , data : [
 81          ['SimilarFeatures','IDF: First workset as training set'],
 82          ['SimilarFeatures:swap','IDF: Second workset as training set']
 83          ]
 84     });
 85   
 86 
 87   this.featureTypeStore=new Ext.data.SimpleStore({
 88           fields: ['value','label'],
 89           data : [
 90                   ['spelling','Spelling'],
 91                   ['lemma','Lemma']
 92                  ]
 93         });
 94 
 95    var WordClassRecord= new Ext.data.Record.create([
 96                 {name : 'label', mapping : '@id'},
 97                 {name: 'value', mapping: '@id'}
 98                 ])
 99    this.wordclassStore = new Ext.data.Store({
100             url: Monk.data.PROXY_URL + "get/AnalyticsManager.getMajorWordClasses",
101             reader : new Ext.data.XmlReader({record : 'class'}
102                 ,WordClassRecord),
103             sortInfo: {field:'label', direction:"ASC"},
104            autoLoad: true
105      });
106 
107     // add the all Word Class
108     this.wordclassStore.on('load',function(){
109      var newRecord = new WordClassRecord({"label": 'All','value':'*'});
110      this.wordclassStore.addSorted(newRecord);
111     },this);
112 
113     this.groupRecord = new Ext.data.Record.create([
114         {name : 'type', mapping : 'type'},
115         {name : 'value', mapping : 'value'},
116         {name : 'count', mapping : 'count'},
117         {name : 'label', mapping : 'type'}
118     ]);
119 
120     this.groupStore = new Ext.data.Store({
121             url: Monk.data.PROXY_URL + 'get/SearchManager.getResultGroupsWithFeatures',
122             baseParams: this.searchParams,
123             reader: new Ext.data.XmlReader({record : 'key'}, this.groupRecord),
124             remoteSort: false,
125             //sortInfo: {field: 'type', direction: 'DESC'},
126             autoLoad: false
127      });
128     
129     this.groupStore.on('load', function(store, records, options){
130         store.each(function(record, options){
131             var type = record.get('type');
132             var value = record.get('value');
133             var count = record.get('count');
134             if (type == 'circulation') {
135                 var start = value;
136                 var end = parseInt(value)+9;
137                 value = start + '-'+ end;
138             }
139             var label =  type +': '+value +' ('+count+' works)';
140             record.set('value', type+':'+value);
141             record.set('label', label);
142         },this);
143         Ext.getCmp('compareOption1Id').reset();
144         Ext.getCmp('compareOption2Id').reset();
145         this.worksetStore.load();
146     }, this);
147     
148     this.worksetStore = new Ext.data.Store({
149         reader: worksetReader,
150         url: Monk.data.PROXY_URL + 'get/ProjectManager.getWorksets',
151         baseParams: {projectId: Monk.component.dataManager.getProjectId()},
152         autoLoad: false,
153         listeners: {
154             load: {
155                 fn: function(store, records, options) {
156                     store.each(function(record, options){
157                         var type = record.get('type');
158                         var value = record.get('value');
159                         var count = record.get('count');
160                         var name = record.get('label'); 
161                         var label =  type +': '+name +' ('+count+' works)';
162                         record.set('value', 'worksetIdCriterion:'+value);
163                         record.set('label', label);
164                     },this);
165                     
166                     this.groupStore.on('add', function(store, records, index){
167                         store.on('datachanged', function(store){
168                             var worksetId = Monk.component.dataManager.getWorksetId();
169                             if (worksetId != null) {
170                                 var combo = Ext.getCmp('compareOption1Id');
171                                 combo.setValue('worksetIdCriterion:'+worksetId);
172                                 Workbench.console.info("set value:   >>" + "worksetIdCriterion:"+worksetId);
173                             }
174                         }, this, {single: true});
175                         
176                         store.sort('value', 'ASC');
177                         store.sort('type', 'DESC');
178                     }, this, {single: true});
179                     this.groupStore.add(records);
180                 },
181                 scope: this
182             },
183             loadexception: {
184                 fn: function() {
185                     this.groupStore.load();
186                 },
187                 scope: this
188             }
189         }
190     });
191 
192   Monk.component.WorksetSimilarityComparisonComponent.superclass.constructor.call(this, args);
193 }
194 
195 
196 
197 Workbench.extend(Monk.component.WorksetSimilarityComparisonComponent, Workbench.component.Component, {
198 label : "Workset Similarity Comparison",
199 description : "This similarity  component is for workset comparison",
200 "window" : this.window,
201 beforeExit : function() {
202      
203 },
204 
205 sendCompareNotification: function(form){
206 	Ext.apply(this.searchParams, form.getValues());
207     this.searchParams.topNCount = this.searchParams.cutoff
208     /*this.searchParams.minTermFreq=
209     this.searchParams.minWordLen=
210     this.searchParams.minDocFreq=
211     */
212     if(this.searchParams.method == "SimilarFeatures" || this.searchParams.method == "SimilarFeatures:swap"){
213     	this.searchParams.format="json";
214     	if (this.searchParams.method == "SimilarFeatures"){
215             this.searchParams.firstComparisonCriterionAsReference = true;
216         } else if(this.searchParams.method == "SimilarFeatures:swap"){
217             this.searchParams.firstComparisonCriterionAsReference = false;
218         }
219     }
220 
221     Workbench.component.manager.notify(new Monk.event.workbench.WorksetDocumentComparison({
222        label: 'workset document comparison: '
223     }), this.searchParams);
224 },
225 
226 
227 handle : function(monkEvent, data) {
228     if(monkEvent.instanceOf(Monk.event.workbench.AdvancedSearchQuery)){
229         this.searchParams = data[0];
230         this.searchParams.limit = 1200;
231         this.searchParams.start = 0;
232         this.groupStore.baseParams = this.searchParams;
233         this.groupStore.load();
234     }
235 },
236 init: function(){
237  this.groupStore.reload();
238 	
239  var minWordLen = {
240      id: 'minWordLenId',
241      name: 'minWordLen',
242      hiddenName: 'minWordLen',
243      labelAlign : 'right',
244      fieldLabel : 'Min. Character length',
245      blankText : 'Minimum Feature Length',
246      emptyText: 'Minimum Feature Length',
247      xtype: 'combo',
248      valueField: 'id',
249      displayField : 'label',
250      disabled: false,
251      editable: true,
252      value: 5,
253      triggerAction: 'all',
254      store : this.featureLenStore,
255      mode : 'local',
256      allowBlank: false,
257      regex: /^\d+$/,
258      regexText: 'Please specify a numeric value.'
259  };
260 
261    var minTermFreq = {
262      id: 'minTermFreqId',
263      name: 'minTermFreq',
264      hiddenName: 'minTermFreq',
265      labelAlign : 'right',
266      fieldLabel : 'At least how many times should the feature occur in each training document',
267      blankText : 'Feature Frequency',
268      emptyText: 'Feature Frequency',
269      xtype: 'combo',
270      valueField: 'id',
271      displayField : 'label',
272      disabled: false,
273      editable: true,
274      value: 3,
275      triggerAction: 'all',
276      store : this.featureFreqStore,
277      mode : 'local',
278      allowBlank: false,
279      regex: /^\d+$/,
280      regexText: 'Please specify a numeric value.'
281    };
282 
283 
284    var minDocFreq = {
285      xtype: 'combo',
286      id: 'minDocFreqId',
287      name: 'minDocFreq',
288      hiddenName: 'minDocFreq',
289      labelAlign : 'right',
290      fieldLabel : 'Feature should occur in at least this many training documents',
291      blankText : 'Feature Document Frequency',
292      emptyText: 'Feature Document Frequency',
293      valueField: 'id',
294      displayField : 'label',
295      disabled: false,
296      editable: true,
297      value: 2,
298      triggerAction: 'all',
299      store : this.featureFreqDocumentStore,
300      mode : 'local',
301      allowBlank: false,
302      regex: /^\d+$/,
303      regexText: 'Please specify a numeric value.'
304    };
305 	
306 	
307 	
308 	var group1 = {
309         id: 'compareOption1Id',
310         name: 'compareOption1',
311         hiddenName: 'compareOption1',
312         fieldLabel: '<span style="background-color:#9C9CDB">First Workset</span>',
313         tooltip: {title:'First Workset',text:'Select First Workset'},
314         triggerAction: 'all',
315         xtype: 'combo',
316         emptyText: 'Workset 1',
317         valueField : 'value',
318         displayField : 'label',
319         allowBlank : false,
320         width: 220,
321         mode: 'local',
322         style:'background-color:#9C9CDB',
323         store: this.groupStore
324     };
325         
326         
327    var group2= {
328         id: 'compareOption2Id',
329         name: 'compareOption2',
330         hiddenName: 'compareOption2',
331         fieldLabel: '<span style="background-color:#8BA353">Second Workset</span>',
332         tooltip: {title:'Second Workset',text:'Select Second Workset'},
333         triggerAction: 'all',
334         xtype: 'combo',
335         emptyText: 'Workset 2',
336         valueField : 'value',
337         displayField : 'label',
338         allowBlank : false,
339         width: 220,
340         mode: 'local',
341         style:'background-color:#8BA353',
342         store: this.groupStore
343     };
344     
345       var featureCount= {
346         xtype: 'combo',
347         fieldLabel: 'Number of Features',
348         id: 'cutoffId',
349         name: 'cutoff',
350         hiddenName: 'cutoff',
351         tooltip: {title:'Select Count',text:'Select the number of feature Spelling/Lemma'},
352         triggerAction: 'all',
353         emptyText: 'Feature Count',
354         valueField: 'value',
355         displayField: 'label',
356         mode: 'local',
357         allowBlank: false,
358         width: 120,
359         value:10,
360         store: this.featureCountStore
361     };   
362     
363     var analysisMethod={
364         xtype: 'combo',
365         fieldLabel: 'Analysis Methods',
366         id: 'methodId',
367         name: 'method',
368         hiddenName: 'method',
369         tooltip: {title:'Select Method',text:'Select the Method'},
370         triggerAction: 'all',
371         emptyText: 'Method',
372         valueField: 'value',
373         displayField: 'label',
374         mode: 'local',
375         allowBlank: false,
376         width: 200,
377         store: this.methodStore
378         
379     };
380 
381 
382 
383   var featureType= {
384         xtype: 'combo',
385         fieldLabel: 'Feature',
386         id: 'featureId',
387         name: 'feature',
388         hiddenName: 'feature',
389         tooltip: {title:'Select feature',text:'Select the feature Spelling/Lemma'},
390         triggerAction: 'all',
391         emptyText: 'Feature',
392         valueField: 'value',
393         displayField: 'label',
394         mode: 'local',
395         allowBlank: false,
396         width: 120,
397         value: 'Spelling',
398         store: this.featureTypeStore
399     };
400     
401   var majorWordClasses= {
402         xtype: 'combo',
403         fieldLabel: 'Feature  Class',
404         tooltip: {title:'Major Word Classes',text:'Select Major Word Class.'},
405         id: 'wordClassId',
406         name: 'wordClass',
407         hiddenName: 'wordClass',
408         triggerAction: 'all',
409         emptyText: 'Word Class',
410         valueField: 'value',
411         displayField: 'label',
412         mode: 'local',
413         allowBlank : false,
414         width: 120,
415         store: this.wordclassStore
416     };
417         
418 	
419 	
420 	this.viewport = new Ext.Viewport({
421         id: 'viewport',
422         layout: 'fit',
423         renderTo: 'container',
424         items: {
425             border: false,
426             items: {
427                 xtype: 'form',
428                 id: 'featureFormPanel',
429                 bodyStyle:'padding: 10px',
430                 labelAlign: 'right',
431                 labelWidth: 125,
432                 autoScroll: true,
433                 border: false,
434                 items: [
435                     group1,
436                     group2,
437                     featureType,
438                     featureCount,
439                     majorWordClasses,
440                     analysisMethod,
441                     minTermFreq,
442                     minDocFreq,
443                     minWordLen
444                 ],
445                  buttons: [{
446                     id: 'gobutton'
447                     ,xtype: 'button'
448                     ,fieldLabel: 'Click to Compare.'
449                     ,text: 'Compare'
450                     ,tooltip: 'Compare'
451                     ,listeners :{
452                         click :{fn : function(){
453                             var form = Ext.getCmp('featureFormPanel').getForm();
454                             if (form.isValid()) {
455                                 this.sendCompareNotification(form);
456                             } else {
457                                 Monk.component.messenger.show({
458                                     title: 'Search Tool',
459                                     msg: 'The form is not valid.  Please correct the highlighted field(s) and try again.',
460                                     width: 240,
461                                     modal: true
462                                });
463                             }
464                         }, scope: this}
465                     }
466                 }]
467             }
468         }
469 	});
470 	
471   
472 	
473 	
474 }
475 
476 
477 
478 });
479 
480