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) + "…;";					
				}
		}
		return title;
		
	}}
	,{name: 'author', mapping: '@author'}
	,{name: 'timeInMillis', type: 'int', mapping: '@time'}
	,{name: 'totalTokens', type: 'int', mapping: '@totalTokens'}
	,{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 : '@relativeDistributionMin', 	type : 'float'}
	,{name : 'relativeMax', 	mapping : '@relativeDistributionMax', 	type : 'float'}
	,{name : 'relativeDistributionMean', 	mapping : '@relativeDistributionMean', 	type : 'float'}
	,{name : 'relativeDistributionStdDev', 	mapping : '@relativeDistributionStdDev', 	type : 'float'}
	,{name : 'relativeDistributionKurtosis', 	mapping : '@relativeDistributionKurtosis', 	type : 'float'}
	,{name : 'relativeDistributionSkewness', 	mapping : '@relativeDistributionSkewness', 	type : 'float'}
	,{name : 'rawZscore', 	mapping : '@rawZscore', 	type : 'float'}
	,{name : 'rawZscoreDifferenceCorpusComparison', 	mapping : '@rawZscoreDifferenceCorpusComparison', 	type : 'float'}
	,{name : 'relativeFreqs', 	mapping : 'relativeFreqs', convert: function(val){return val['float-array']}}
	,{name : 'rawFreqs', 	mapping : 'rawFreqs', convert: function(val){return val['int-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:'relativeFreqCorpusDelta',mapping:'@relativeFreqCorpusDelta',type:'float'}
	,{name:'relativeFreq',mapping:'@relativeFreq',type:'float'}
	,{name:'rawDistributionMin',mapping:'@rawDistributionMin',type:'int'}
	,{name:'rawDistributionMax',mapping:'@rawDistributionMax',type:'int'}
	,{name:'rawDistributionMean',mapping:'@rawDistributionMean',type:'float'}
	,{name:'rawDistributionStdDev',mapping:'@rawDistributionStdDev',type:'float'}
	,{name:'rawDistributionKurtosis',mapping:'@rawDistributionKurtosis',type:'float'}
	,{name:'rawDistributionSkewness',mapping:'@rawDistributionSkewness',type:'float'}
	,{name:'distributionFreqs',mapping:'int-array'}
	,{name : 'relativeFreqs', 	mapping : 'relativeFreqs', convert: function(val){return val['float-array']}}
	,{name : 'rawFreqs', 	mapping : 'rawFreqs', convert: function(val){return val['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: 'rawCollocateFreqRatio', mapping: '@rawCollocateFreqRatio', type: 'float'}
]

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

Voyeur.data.TypeKwics.fields = [
	{name : 'type',mapping:'@type'},
	{name : 'left',mapping:'@left'},
	{name : 'middle',mapping:'@middle'},
	{name : 'right',mapping:'@right'},
	{name : 'docId', mapping:'@docId'},
	{name : 'docIndex',mapping:'@docIndex',type : 'int'},
	{name : 'tokenId', mapping:'@tokenId',type : 'int'},
	{name : 'category' /* for KwicTagger */}
]

Voyeur.data.TypeKwics.reader = new Ext.data.JsonReader({
	root : 'typeKwics.kwics'
	,totalProperty : 'typeKwics["@totalKwics"]'
	,fields: Voyeur.data.TypeKwics.fields
});

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

Voyeur.data.CorpusEntities.fields = [
	{name : 'text',mapping:'@text'},
	{name : 'category',mapping:'@category'},
	{name : 'rawFreq',mapping:'@rawFreq', type: 'int'},
	{name : 'relevances',mapping:'relevances/float-array'},
	{name : 'counts',mapping:'counts/float-array'},
	{name : 'disambiguate', mapping:'@disambiguate'}                
]

Voyeur.data.CorpusEntities.reader = new Ext.data.JsonReader({
	root : 'corpusEntities.entities'
	,totalProperty : 'corpusEntities["@totalEntities"]'
	,fields: Voyeur.data.CorpusEntities.fields
});

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

Voyeur.data.DocumentEntities.fields = [
   	{name : 'text',mapping:'@text'},
	{name : 'docId',mapping:'@docId'},
	{name : 'category',mapping:'@category'},
	{name : 'rawFreq',mapping:'@rawFreq', type: 'int'},
	{name : 'relevance',mapping:'@relevance', type: 'float'},
	{name : 'disambiguate', mapping:'@disambiguate'}                
]

Voyeur.data.DocumentEntities.reader = new Ext.data.JsonReader({
	root : 'documentEntities.entities'
	,totalProperty : 'documentEntities["@totalEntities"]'
	,fields: Voyeur.data.DocumentEntities.fields
});
