- 1 :
/**
- 2 :
* Corpus Collocates is a table view of which terms appear more frequently in proximity to keywords across the entire corpus.
- 3 :
*
- 4 :
* @example
- 5 :
*
- 6 :
* let config = {
- 7 :
* columns: null,
- 8 :
* context: null,
- 9 :
* dir: null,
- 10 :
* docId: null,
- 11 :
* docIndex: null,
- 12 :
* query: null,
- 13 :
* sort: null,
- 14 :
* stopList: null,
- 15 :
* termColors: null
- 16 :
* };
- 17 :
*
- 18 :
* loadCorpus("austen").tool("CorpusCollocates", config);
- 19 :
*
- 20 :
*
- 21 :
* @class CorpusCollocates
- 22 :
* @tutorial corpuscollocates
- 23 :
* @memberof Tools
- 24 :
*/
- 25 :
Ext.define('Voyant.panel.CorpusCollocates', {
- 26 :
extend: 'Ext.grid.Panel',
- 27 :
mixins: ['Voyant.panel.Panel'],
- 28 :
alias: 'widget.corpuscollocates',
- 29 :
statics: {
- 30 :
i18n: {
- 31 :
},
- 32 :
api: {
- 33 :
/**
- 34 :
* @memberof Tools.CorpusCollocates
- 35 :
* @instance
- 36 :
* @property {stopList}
- 37 :
* @default
- 38 :
*/
- 39 :
stopList: 'auto',
- 40 :
- 41 :
/**
- 42 :
* @memberof Tools.CorpusCollocates
- 43 :
* @instance
- 44 :
* @property {context}
- 45 :
* @default
- 46 :
*/
- 47 :
context: 5,
- 48 :
- 49 :
/**
- 50 :
* @memberof Tools.CorpusCollocates
- 51 :
* @instance
- 52 :
* @property {query}
- 53 :
*/
- 54 :
query: undefined,
- 55 :
- 56 :
/**
- 57 :
* @memberof Tools.CorpusCollocates
- 58 :
* @instance
- 59 :
* @property {docId}
- 60 :
*/
- 61 :
docId: undefined,
- 62 :
- 63 :
/**
- 64 :
* @memberof Tools.CorpusCollocates
- 65 :
* @instance
- 66 :
* @property {docIndex}
- 67 :
*/
- 68 :
docIndex: undefined,
- 69 :
- 70 :
/**
- 71 :
* @memberof Tools.CorpusCollocates
- 72 :
* @instance
- 73 :
* @property {columns} columns 'term', 'rawFreq', 'contextTerm', 'contextTermRawFreq'
- 74 :
*/
- 75 :
columns: undefined,
- 76 :
- 77 :
/**
- 78 :
* @memberof Tools.CorpusCollocates
- 79 :
* @instance
- 80 :
* @property {sort}
- 81 :
*/
- 82 :
sort: undefined,
- 83 :
- 84 :
/**
- 85 :
* @memberof Tools.CorpusCollocates
- 86 :
* @instance
- 87 :
* @property {dir}
- 88 :
*/
- 89 :
dir: undefined,
- 90 :
- 91 :
/**
- 92 :
* @memberof Tools.CorpusCollocates
- 93 :
* @instance
- 94 :
* @property {termColors}
- 95 :
* @default
- 96 :
*/
- 97 :
termColors: 'categories'
- 98 :
},
- 99 :
glyph: 'xf0ce@FontAwesome'
- 100 :
},
- 101 :
config: {
- 102 :
options: [{xtype: 'stoplistoption'},{xtype: 'categoriesoption'},{xtype: 'termcolorsoption'}]
- 103 :
},
- 104 :
constructor: function(config) {
- 105 :
- 106 :
this.callParent(arguments);
- 107 :
this.mixins['Voyant.panel.Panel'].constructor.apply(this, arguments);
- 108 :
- 109 :
// create a listener for corpus loading (defined here, in case we need to load it next)
- 110 :
this.on('loadedCorpus', function(src, corpus) {
- 111 :
if (this.isVisible()) {
- 112 :
this.loadFromApis();
- 113 :
}
- 114 :
});
- 115 :
- 116 :
if (config.embedded) {
- 117 :
// var cls = Ext.getClass(config.embedded).getName();
- 118 :
// if (cls=="Voyant.data.store.DocumentTerms" || cls=="Voyant.data.model.Document") {
- 119 :
// this.fireEvent('loadedCorpus', this, config.embedded.getCorpus())
- 120 :
// }
- 121 :
}
- 122 :
else if (config.corpus) {
- 123 :
this.fireEvent('loadedCorpus', this, config.corpus)
- 124 :
}
- 125 :
- 126 :
this.on("corpusTermsClicked", function(src, terms) {
- 127 :
if (this.getStore().getCorpus()) { // make sure we have a corpus
- 128 :
var query = [];
- 129 :
terms.forEach(function(term) {
- 130 :
query.push(term.get("term"));
- 131 :
})
- 132 :
this.setApiParams({
- 133 :
query: query,
- 134 :
docId: undefined,
- 135 :
docIndex: undefined
- 136 :
});
- 137 :
if (this.isVisible()) {
- 138 :
this.loadFromApis();
- 139 :
}
- 140 :
}
- 141 :
});
- 142 :
- 143 :
this.on("documentsClicked", function(src, documents) {
- 144 :
var docIds = [];
- 145 :
documents.forEach(function(doc) {docIds.push(doc.get('id'))});
- 146 :
this.setApiParams({
- 147 :
docId: docIds,
- 148 :
docid: undefined,
- 149 :
query: undefined
- 150 :
})
- 151 :
if (this.isVisible()) {
- 152 :
this.loadFromApis();
- 153 :
}
- 154 :
});
- 155 :
- 156 :
this.on("activate", function() { // load after tab activate (if we're in a tab panel)
- 157 :
if (this.getStore().getCorpus()) {this.loadFromApis()}
- 158 :
}, this)
- 159 :
- 160 :
this.on("query", function(src, query) {
- 161 :
if (query.length === 0) query = undefined;
- 162 :
this.setApiParam("query", query);
- 163 :
this.getStore().getProxy().setExtraParam("query", query);
- 164 :
this.loadFromApis();
- 165 :
}, this)
- 166 :
},
- 167 :
- 168 :
loadFromApis: function() {
- 169 :
if (this.getStore().getCorpus()) {
- 170 :
if (this.getApiParam('query')) {
- 171 :
this.getStore().clearAndLoad({params: this.getApiParams()});
- 172 :
}
- 173 :
else {
- 174 :
var corpusTerms = this.getStore().getCorpus().getCorpusTerms({
- 175 :
leadingBufferZone: 0,
- 176 :
autoLoad: false
- 177 :
});
- 178 :
corpusTerms.load({
- 179 :
callback: function(records, operation, success) {
- 180 :
if (success) {
- 181 :
var terms = [];
- 182 :
records.forEach(function(term) {
- 183 :
terms.push(term.getTerm());
- 184 :
})
- 185 :
this.getStore().getProxy().setExtraParam("query", terms);
- 186 :
this.setApiParam('query', terms);
- 187 :
this.loadFromApis();
- 188 :
}
- 189 :
},
- 190 :
scope: this,
- 191 :
params: {
- 192 :
limit: 10,
- 193 :
stopList: this.getApiParam("stopList")
- 194 :
}
- 195 :
});
- 196 :
- 197 :
}
- 198 :
}
- 199 :
},
- 200 :
- 201 :
initComponent: function() {
- 202 :
var me = this;
- 203 :
- 204 :
var store = Ext.create("Voyant.data.store.CorpusCollocatesBuffered", {parentPanel: this});
- 205 :
- 206 :
Ext.apply(me, {
- 207 :
title: this.localize('title'),
- 208 :
emptyText: this.localize("emptyText"),
- 209 :
store : store,
- 210 :
selModel: Ext.create('Ext.selection.CheckboxModel', {
- 211 :
listeners: {
- 212 :
selectionchange: {
- 213 :
fn: function(sm, selections) {
- 214 :
if (selections.length > 0) {
- 215 :
var terms = [];
- 216 :
var context = this.getApiParam("context")
- 217 :
selections.forEach(function(selection) {
- 218 :
terms.push('"'+selection.getKeyword()+" "+selection.getContextTerm()+'"~'+context)
- 219 :
})
- 220 :
this.getApplication().dispatchEvent('termsClicked', this, terms);
- 221 :
}
- 222 :
},
- 223 :
scope: this
- 224 :
}
- 225 :
}
- 226 :
}),
- 227 :
dockedItems: [{
- 228 :
dock: 'bottom',
- 229 :
xtype: 'toolbar',
- 230 :
overflowHandler: 'scroller',
- 231 :
items: [{
- 232 :
xtype: 'querysearchfield'
- 233 :
}, {
- 234 :
xtype: 'totalpropertystatus'
- 235 :
}, this.localize('context'), {
- 236 :
xtype: 'slider',
- 237 :
minValue: 1,
- 238 :
value: 5,
- 239 :
maxValue: 30,
- 240 :
increment: 2,
- 241 :
width: 50,
- 242 :
listeners: {
- 243 :
render: function(slider) {
- 244 :
slider.setValue(me.getApiParam('context'))
- 245 :
},
- 246 :
changecomplete: function(slider, newValue) {
- 247 :
me.setApiParam("context", slider.getValue());
- 248 :
me.loadFromApis();
- 249 :
}
- 250 :
}
- 251 :
},{
- 252 :
xtype: 'corpusdocumentselector'
- 253 :
}]
- 254 :
}],
- 255 :
columns: [{
- 256 :
text: this.localize("term"),
- 257 :
dataIndex: 'term',
- 258 :
tooltip: this.localize("termTip"),
- 259 :
sortable: true,
- 260 :
flex: 1,
- 261 :
xtype: 'coloredtermfield',
- 262 :
useCategoriesMenu: true
- 263 :
},{
- 264 :
text: this.localize("rawFreq"),
- 265 :
dataIndex: 'rawFreq',
- 266 :
tooltip: this.localize("termRawFreqTip"),
- 267 :
sortable: true,
- 268 :
width: 'autoSize',
- 269 :
hidden: true
- 270 :
},{
- 271 :
text: this.localize("contextTerm"),
- 272 :
dataIndex: 'contextTerm',
- 273 :
tooltip: this.localize("contextTermTip"),
- 274 :
flex: 1,
- 275 :
sortable: true,
- 276 :
xtype: 'coloredtermfield'
- 277 :
},{
- 278 :
text: this.localize("contextTermRawFreq"),
- 279 :
tooltip: this.localize("contextTermRawFreqTip"),
- 280 :
dataIndex: 'contextTermRawFreq',
- 281 :
width: 'autoSize',
- 282 :
sortable: true
- 283 :
}/*,{
- 284 :
xtype: 'widgetcolumn',
- 285 :
text: this.localize("trend"),
- 286 :
tooltip: this.localize('trendTip'),
- 287 :
width: 120,
- 288 :
dataIndex: 'distributions',
- 289 :
widget: {
- 290 :
xtype: 'sparklineline'
- 291 :
}
- 292 :
}*/],
- 293 :
- 294 :
listeners: {
- 295 :
scope: this,
- 296 :
termsClicked: function(src, terms) {
- 297 :
if (this.getStore().getCorpus()) { // make sure we have a corpus
- 298 :
var queryTerms = [];
- 299 :
terms.forEach(function(term) {
- 300 :
if (Ext.isString(term)) {queryTerms.push(term);}
- 301 :
else if (term.term) {queryTerms.push(term.term);}
- 302 :
else if (term.getTerm) {queryTerms.push(term.getTerm());}
- 303 :
});
- 304 :
if (queryTerms.length > 0) {
- 305 :
this.setApiParams({
- 306 :
docIndex: undefined,
- 307 :
docId: undefined,
- 308 :
query: queryTerms
- 309 :
});
- 310 :
if (this.isVisible()) {
- 311 :
this.loadFromApis();
- 312 :
}
- 313 :
}
- 314 :
}
- 315 :
},
- 316 :
- 317 :
corpusSelected: function() {
- 318 :
if (this.getStore().getCorpus()) {
- 319 :
this.setApiParams({docId: undefined, docIndex: undefined})
- 320 :
this.loadFromApis();
- 321 :
}
- 322 :
},
- 323 :
- 324 :
documentsSelected: function(src, docs) {
- 325 :
var docIds = [];
- 326 :
var corpus = this.getStore().getCorpus();
- 327 :
docs.forEach(function(doc) {
- 328 :
docIds.push(corpus.getDocument(doc).getId())
- 329 :
}, this);
- 330 :
this.setApiParams({docId: docIds, docIndex: undefined});
- 331 :
this.loadFromApis();
- 332 :
}
- 333 :
}
- 334 :
});
- 335 :
- 336 :
me.callParent(arguments);
- 337 :
- 338 :
me.getStore().getProxy().setExtraParam("withDistributions", true);
- 339 :
- 340 :
}
- 341 :
- 342 :
})