Ext.namespace('Voyeur.data');

Ext.namespace('Voyeur.data.Corpus');

Voyeur.data.Corpus.fields = [
	{name: 'id', mapping: '@id'}
	,{name: 'lastModified', mapping: '@lastModified'}
	,{name: 'totalWordTokens', type: 'int', mapping: '@totalWordTokens'}
	,{name: 'totalWordTypes', type: 'int', mapping: '@totalWordTypes'}
	,{name: 'docsCount', type: 'int', mapping: 'documents', convert: function(val, record) {return val.length}}
]

Ext.namespace('Voyeur.data.Document');

Voyeur.data.Document.fields = [
	{name: 'id', mapping: '@id'}
	,{name: 'index', type: 'int', mapping: '@index'}
	,{name: 'title', mapping: '@title'}
	,{name: 'shortTitle', mapping: '@title', convert: function(val) {
		title = val.replace(/\.(html?|txt|xml|docx?|pdf|rtf|\/)$/,'');
		if (title.length > 25) {
			
				 // maybe a file or URL?
				var slash = title.lastIndexOf("/");
				if (slash>-1) {title = title.substr(slash+1)}
				
				if (title.length>25) {
					var space = title.indexOf(" ", 20);
					if (space < 0 || space > 30) {
						space = 25;
					}
					title = title.substring(0, space) + "&hellip;";					
				}
		}
		return title;
		
	}}
	,{name: 'author', mapping: '@author'}
	,{name: 'timeInMillis', type: 'int', mapping: '@time'}
	,{name: 'totalWordTokens', type: 'int', mapping: '@totalWordTokens'}
	,{name: 'totalWordTypes', type: 'int', mapping: '@totalWordTypes'}
	,{name: 'wordDensity', type: 'float', mapping: '@totalWordTokens', convert: function(val, record) {return val < 1 ? 0 : (record['@totalWordTypes']/val)*1000;}}
]

Ext.namespace('Voyeur.data.CorpusTypes');

Voyeur.data.CorpusTypes.fields = [
	{name : 'type', 	mapping : '@type'}
	,{name : 'rawFreq', 	mapping : '@rawFreq', 	type : 'int'}
	,{name : 'relativeMin', 	mapping : '@relativeMin', 	type : 'float'}
	,{name : 'relativeMax', 	mapping : '@relativeMax', 	type : 'float'}
	,{name : 'relativeMean', 	mapping : '@relativeMean', 	type : 'float'}
	,{name : 'relativeStdDev', 	mapping : '@relativeStdDev', 	type : 'float'}
	,{name : 'relativeKurtosis', 	mapping : '@relativeKurtosis', 	type : 'float'}
	,{name : 'relativeSkewness', 	mapping : '@relativeSkewness', 	type : 'float'}
	,{name : 'rawZscore', 	mapping : '@rawZscore', 	type : 'float'}
	,{name : 'rawZscoreDifferenceCorpusComparison', 	mapping : '@rawZscoreDifferenceCorpusComparison', 	type : 'float'}
	,{name : 'relativeFreqs', 	mapping : 'float-array'
}]

Ext.namespace('Voyeur.data.DocumentTypes');

Voyeur.data.DocumentTypes.fields = [
	{name:'type',mapping:'@type'}
	,{name:'docId',mapping:'@docId'}
	,{name:'docIndex',mapping:'@docIndex',type:'int'}
	,{name:'rawFreq',mapping:'@rawFreq',type:'int'}
	,{name:'rawZscore',mapping:'@rawZscore',type:'float'}
	,{name:'rawZscoreCorpusDelta',mapping:'@rawZscoreCorpusDelta',type:'float'}
	,{name:'relativeFreq',mapping:'@relativeFreq',type:'float'}
	,{name:'distributionMin',mapping:'@distributionMin',type:'int'}
	,{name:'distributionMax',mapping:'@distributionMax',type:'int'}
	,{name:'distributionMean',mapping:'@distributionMean',type:'float'}
	,{name:'distributionStdDev',mapping:'@distributionStdDev',type:'float'}
	,{name:'distributionKurtosis',mapping:'@distributionKurtosis',type:'float'}
	,{name:'distributionSkewness',mapping:'@distributionSkewness',type:'float'}
	,{name:'distributionFreqs',mapping:'int-array'}
]

Ext.namespace('Voyeur.data.DocumentTypeCollocates');

Voyeur.data.DocumentTypeCollocates.fields = [
 	{name: 'type', mapping: '@type'}
	,{name: 'keyword', mapping: '@keyword'}
	,{name: 'docId', mapping: '@docId'}
	,{name: 'docIndex', mapping: '@docIndex',type:'int'}
	,{name: 'keyword_docId', mapping: '@docId', convert: function(val, record) {return record['keyword']+': '+val}}
	,{name: 'rawFreq', mapping: '@rawFreq', type: 'int'}
	,{name: 'relativeFreq', mapping: '@relativeFreq', type: 'float'}
	,{name: 'rawCollocateFreq', mapping: '@rawCollocateFreq', type: 'int'}
	,{name: 'relativeCollocateFreq', mapping: '@relativeCollocateFreq', type: 'float'}
	,{name: 'relativeRatio', mapping: '@relativeRatio', type: 'float'}
]

