

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


long TotalItems = 0;
long TotalPatents = 0;
char sourcePath[300];
long **m_New32Projection;
double AvgUniqueTerms;
long MaxThreadSize;

long **fullPatent;
long **fullPatentInterval;
long *fullPatentIntervalLength;
long *fullPatentRowLength;
long *tempRow;
typedef struct str_thdata
{
    long Local_GlobalPostingAge;
	long ThreadNumber;
	long QueryPatentNumber;
    
} thdata;

long Size = 0;
long *IDFValue;
double *MedianWeight;
double *Patent_QRelevance_Score;
long *Patent_QRelevance_Name;
long Patent_QRelevance_Count;
long **PatentTermsArray;

double AveragePatentLength = 0;
long *FastProjection;

long *PatentHashIndex;
double Parameter_Value;

struct TermsBinaryTree
{
		struct TermsBinaryTree *RightBT;
		struct TermsBinaryTree *LeftBT;
		long Number;
		char WordName[300];
};
struct TermsBinaryTree *TermsBinaryTreeParentNode,*TermsBinaryTreeParentNodeQG,*ProcessQueryUniqueTerms;

long ProcessQueryUniqueTermsCount = 0;

struct TermsStruct
{
		char TermsName[100];
};
struct TermsStruct *TermsQG,*Terms;


char cleanTermName[100];

long FastQueryBank[100000][10];
long FastQueryBankLength[100000];




long *QueryItemCount;
long **QueryItemArray;
long **QueryItemArray_Freq;
double **QueryItemArray_Weight;








/*--------------------------- Inverted Index Variables ------------------------------------- */

struct InvertedItemsArray
{
		double Score;
		double TFScore;
		long DocumentNumber;
		struct InvertedItemsArray *nextPtr;


};
struct InvertedItemsArray **InvertedItemsNumbers,*tempInvertedVariable;
long *InvertedItemsNumbersCount;


long *fullPatentLength;
long *fullPatentUniqueItems;

long *fullPatentLength_feature;
long *fullPatentUniqueItems_feature;





double **PostingScore;
double **PostingTFScore;
long **PostingQueryTermsPresence;
long **PostingAge;


long GlobalPostingAge;


long **FoundPatents;
double **FoundPatentsScore;
double **FoundPatentsTFScore;
long *FoundPatentsCount;





double MinimumTopNScore = 0;
double predicted_score;
FILE *findability_log;
long fileNumber;

long **DocTermsArray_TermNumber;
long **DocTermsArray_TermFrequency;
long **DocTermsArray_TermRank;
double **DocTermsArray_TermWeight;
long *Thread_DocTermsArray_TotalTerms;
long *DocTermsArray_TotalTerms;







long RSType = 0;


long *TermCollectionSum;
long CollectionModel;
FILE *writeLog;










long *DocLength;
long *DocTotalQueries;
long *DocVocabularySize;
long *DocID;





											
/*------------------------------------------------------------------------------------------ */








int gotoxy(int x, int y,char printText[300]) {

					char essq[100]; // String variable to hold the escape sequence

					char xstr[100]; // Strings to hold the x and y coordinates

					char ystr[100]; // Escape sequences must be built with characters

					sprintf(xstr, "%d", x);

					sprintf(ystr, "%d", y);

					essq[0] = '\0';

					strcat(essq, "\033[");

					strcat(essq, ystr);

					strcat(essq, "d");


					strcat(essq, "\033[");

					strcat(essq, xstr);

					strcat(essq, "G");

					printf("%s%s",essq,printText);

 


					return 0;

}
void clrscr()
{
		int i , j;

		for ( i = 0; i < 100; i++ )
		{
			for ( j = 0; j < 100; j ++ )
					gotoxy(i,j," ");
		}
}




void InsertItem_InvertedIndex(int DocumentNumber, int ItemNumber, double Score)
{
   	   /* struct InvertedItemsArray *firstItem = NULL;

		if ( InvertedItemsNumbers[ItemNumber] == NULL )
		{				
				tempInvertedVariable = (struct InvertedItemsArray *)malloc(sizeof(struct InvertedItemsArray));
				tempInvertedVariable->DocumentNumber = DocumentNumber;
				tempInvertedVariable->Score = Score;
				tempInvertedVariable->nextPtr = NULL;
				InvertedItemsNumbers[ItemNumber] = tempInvertedVariable;				
		}
		else
		{
			 
				firstItem = InvertedItemsNumbers[ItemNumber];
				tempInvertedVariable = (struct InvertedItemsArray *)malloc(sizeof(struct InvertedItemsArray));
				tempInvertedVariable->DocumentNumber = DocumentNumber;
				tempInvertedVariable->Score = Score;
				tempInvertedVariable->nextPtr = firstItem;
				InvertedItemsNumbers[ItemNumber] = tempInvertedVariable;				

		}*/

		InvertedItemsNumbers[ItemNumber][InvertedItemsNumbersCount[ItemNumber]].DocumentNumber = DocumentNumber;
		InvertedItemsNumbers[ItemNumber][InvertedItemsNumbersCount[ItemNumber]].Score = Score;
		InvertedItemsNumbers[ItemNumber][InvertedItemsNumbersCount[ItemNumber]].TFScore = Score;
		InvertedItemsNumbersCount[ItemNumber]++;
	
}



void Make_TFIDF_Indexing()
{
		int firstItem = 0;
		double TF = 0;
		double IDF = 0;
		int i = 0,j=0,z,z1;
		double tempdouble;
		int tempInt;



		for ( i = 0; i < TotalItems+2; i++ )
		{
				IDF = IDFValue[i];
				IDF = (double)((double)(((TotalPatents))) /(double)IDF);
				IDF = (double)((double)log(IDF)/(double)log(2));

				
				if ( IDFValue[i] != InvertedItemsNumbersCount[i] )
				{
					printf("\n%d....%d...%d",i,IDFValue[i],InvertedItemsNumbersCount[i]);
					exit(1);
				}

				if ( InvertedItemsNumbersCount[i] > 0  )
				{
						firstItem = 0;
						while(1)
						{

							//	printf("\n%d.....%f",InvertedItemsNumbers[i][firstItem].DocumentNumber,InvertedItemsNumbers[i][firstItem].Score);


								TF = InvertedItemsNumbers[i][firstItem].Score;
								TF = (double) ( (double)TF/(double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber]);

								InvertedItemsNumbers[i][firstItem].Score = IDF*TF;

							//	FoundPatentsScore[FoundPatentsCount] = firstItem->Score;
							//	FoundPatents[FoundPatentsCount] = firstItem->DocumentNumber;

							//	FoundPatentsCount++;



								firstItem++;
								if ( firstItem == InvertedItemsNumbersCount[i] )
									break;
						}
				


	
				}
		}

}

void Make_SMART_Indexing()
{
		int firstItem = 0;
		double TF = 0;
		double IDF = 0;
		int i = 0,j=0,z,z1;
		double AvgTF = 0;
		double SecondPart = 0;
		double utf;
		double DocPart = 0;
		



		for ( i = 0; i < TotalItems+2; i++ )
		{
				IDF = IDFValue[i];
				IDF = (double)((double)(((TotalPatents))) /(double)IDF);
				IDF = (double)((double)log(IDF)/(double)log(2));

				
				if ( IDFValue[i] != InvertedItemsNumbersCount[i] )
				{
					printf("\n%d....%d...%d",i,IDFValue[i],InvertedItemsNumbersCount[i]);
					exit(1);
				}

				if ( InvertedItemsNumbersCount[i] > 0  )
				{
						firstItem = 0;
						while(1)
						{



								TF = InvertedItemsNumbers[i][firstItem].Score;
								TF = (double)((double)log(TF)/(double)log(2));
								TF = 1 + TF;

								AvgTF = ((double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber]/(double)fullPatentUniqueItems[InvertedItemsNumbers[i][firstItem].DocumentNumber]);
								AvgTF = (double)((double)log(AvgTF)/(double)log(2));
								AvgTF = 1 + AvgTF;


								utf = (double)((double)fullPatentUniqueItems[InvertedItemsNumbers[i][firstItem].DocumentNumber]/(double)AvgUniqueTerms);
								SecondPart = (double)( (double)0.8 + (double)((double)0.2*(double)utf  ));
								SecondPart = (double) ( (double)1/(double)SecondPart);


								DocPart = AvgTF*SecondPart;


								TF = 1;
								TF = (double)((double)log(TF)/(double)log(2));
								TF = 1 + TF;

								AvgTF = (double)((double)(TotalPatents+1)/(double)IDFValue[i]);

								AvgTF = AvgTF*TF;



								InvertedItemsNumbers[i][firstItem].Score = DocPart*AvgTF;



								firstItem++;
								if ( firstItem == InvertedItemsNumbersCount[i] )
									break;
						}
				


	
				}
		}

}


void Make_UnNormTFIDF_Indexing()
{
		int firstItem = 0;
		double TF = 0;
		double IDF = 0;
		int i = 0,j=0,z,z1;
		double tempdouble;
		int tempInt;



		for ( i = 0; i < TotalItems+2; i++ )
		{
				IDF = IDFValue[i];
				IDF = (double)((double)(((TotalPatents))) /(double)IDF);
				IDF = (double)((double)log(IDF)/(double)log(2));

				
				if ( IDFValue[i] != InvertedItemsNumbersCount[i] )
				{
					printf("\n%d....%d...%d",i,IDFValue[i],InvertedItemsNumbersCount[i]);
					exit(1);
				}

				if ( InvertedItemsNumbersCount[i] > 0  )
				{
						firstItem = 0;
						while(1)
						{



								TF = InvertedItemsNumbers[i][firstItem].Score;
							//	TF = (double) ( (double)TF/(double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber]);

								InvertedItemsNumbers[i][firstItem].Score = IDF*TF;


								firstItem++;
								if ( firstItem == InvertedItemsNumbersCount[i] )
									break;
						}
				


	
				}
		}

}


void Make_TwoStage_Indexing()
{
		int firstItem = 0;
		double TF = 0,SecondPart,SecondPart2;
		double IDF = 0;
		int i = 0,j=0,z,z1;
		double tempdouble;
		int tempInt;
 	    double Parameter  = 0.7;
	    double Parameter2  = 2000;

		Parameter = Parameter_Value;


		for ( i = 0; i < TotalItems+2; i++ )
		{
			//	IDF = (double)( (double)IDFValue[i]/(double)TotalPatents );

			
				if ( IDFValue[i] != InvertedItemsNumbersCount[i] )
				{
						printf("\n%d....%d...%d",i,IDFValue[i],InvertedItemsNumbersCount[i]);
						exit(1);
				}

				if ( InvertedItemsNumbersCount[i] > 0  )
				{
						firstItem = 0;
						while(1)
						{


								IDF = (double)TermCollectionSum[i];
								IDF = (double) ( IDF / (double) (CollectionModel ) );							  


								TF = InvertedItemsNumbers[i][firstItem].Score;
	


								SecondPart2 = (double)( TF + (double)( (double)Parameter2 *(double)IDF));
								SecondPart2 = (double) ( SecondPart2/ (double)( (double) fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber] + (double)(Parameter2)) );
								SecondPart = (double)((double)(1-Parameter)*(SecondPart2)) +(Parameter * (double)IDF);
							//	printf("\n%f...",SecondPart);



								InvertedItemsNumbers[i][firstItem].Score = SecondPart;




								firstItem++;
								if ( firstItem == InvertedItemsNumbersCount[i] )
									break;
						}
				


				}
		}

}



void Make_DirS_Indexing()
{
		int firstItem = 0;
		double TF = 0,SecondPart;
		double IDF = 0;
		int i = 0,j=0,z,z1;
		double tempdouble;
		int tempInt;
	    double Parameter  = 2000;



		for ( i = 0; i < TotalItems+2; i++ )
		{
				IDF = (double)( (double)IDFValue[i]/(double)TotalPatents );

			
				if ( IDFValue[i] != InvertedItemsNumbersCount[i] )
				{
						printf("\n%d....%d...%d",i,IDFValue[i],InvertedItemsNumbersCount[i]);
						exit(1);
				}

				if ( InvertedItemsNumbersCount[i] > 0  )
				{
						firstItem = 0;
						while(1)
						{



								TF = InvertedItemsNumbers[i][firstItem].Score;

								TF = (double) ( (double)TF/(double)(double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber] );
	
//								SecondPart = (double)( TF + (double) ((double)Parameter *(double)IDF));
//								SecondPart = SecondPart / (double) ( (double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber] + (double) Parameter    );




								InvertedItemsNumbers[i][firstItem].Score = TF;




								firstItem++;
								if ( firstItem == InvertedItemsNumbersCount[i] )
									break;
						}
				


				}
		}

}

void Make_JM_Indexing()
{
		int firstItem = 0;
		double TF = 0,SecondPart;
		double IDF = 0;
		int i = 0,j=0,z,z1;
		double tempdouble;
		int tempInt;
	    double Parameter  = .7;

		Parameter = Parameter_Value;


		for ( i = 0; i < TotalItems+2; i++ )
		{
			//	IDF = (double)( (double)IDFValue[i]/(double)TotalPatents );

			
				if ( IDFValue[i] != InvertedItemsNumbersCount[i] )
				{
						printf("\n%d....%d...%d",i,IDFValue[i],InvertedItemsNumbersCount[i]);
						exit(1);
				}

				if ( InvertedItemsNumbersCount[i] > 0  )
				{
						firstItem = 0;
						while(1)
						{


								IDF = (double)TermCollectionSum[i];
								IDF = (double) ( (double)IDF / (double) (CollectionModel ) );							  


								TF = InvertedItemsNumbers[i][firstItem].Score;
								TF = (double) ( (double)TF/(double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber]);


						//		if ( Parameter == 1.0 )
						//			TF = 0;
						//		else
								TF = (double)((double)(1-Parameter)*(double)TF);


								SecondPart = (double)((double)Parameter*(double)IDF);

								InvertedItemsNumbers[i][firstItem].Score = (double)((double)TF+(double)SecondPart);




								firstItem++;
								if ( firstItem == InvertedItemsNumbersCount[i] )
									break;
						}
				


				}
		}

}

void Make_AbsDis_Indexing()
{
		int firstItem = 0;
		double TF = 0,SecondPart;
		double IDF = 0;
		int i = 0,j=0,z,z1;
		double tempdouble;
		int tempInt;
	    double Parameter  = 0.7;

		Parameter = Parameter_Value;


		for ( i = 0; i < TotalItems+2; i++ )
		{
			

			
				if ( IDFValue[i] != InvertedItemsNumbersCount[i] )
				{						
						exit(1);
				}

				if ( InvertedItemsNumbersCount[i] > 0  )
				{
						firstItem = 0;
						while(1)
						{


								IDF = (double)TermCollectionSum[i];
								IDF = (double) ( IDF / (double) (CollectionModel ) );							  


								TF = InvertedItemsNumbers[i][firstItem].Score;
								TF = TF  - Parameter;
								TF = (double) ( (double)TF/(double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber]);


								SecondPart = (double)((double)fullPatentUniqueItems[InvertedItemsNumbers[i][firstItem].DocumentNumber]*(double)Parameter);
								SecondPart = (double) ( (double)SecondPart/(double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber]);								
								SecondPart = (double)((double)SecondPart*(double)IDF);


								TF = (double)((double)TF+(double)SecondPart);

							//	printf("\n%f...%f...%d...%d",TF,SecondPart,InvertedItemsNumbers[i][firstItem].DocumentNumber,fullPatentUniqueItems[InvertedItemsNumbers[i][firstItem].DocumentNumber]);



								InvertedItemsNumbers[i][firstItem].Score = TF;
								firstItem++;
								if ( firstItem == InvertedItemsNumbersCount[i] )
									break;
						}
				


				}
		}

}


void Make_BM25_Indexing()
{
		int firstItem = 0;
		double TF = 0;
		double IDF = 0;
		int i = 0,j=0,z,z1;
		double tempdouble;
		int tempInt;
        double k = 2.0;
        double b = .75;
		double TermFreq, IDFUpper, IDFLower;
  		double WeightedLength = 0;
        double MainUpper = 0;
        double MainLower = 0;
        double Main = 0;

		b = Parameter_Value;

	//	printf("\n\n%f...\n\n",b);
	//	exit(1);

		for ( i = 0; i < TotalItems+2; i++ )
		{
			//	IDF = IDFValue[i];
			//	IDF = (double)((double)(((TotalPatents))) /(double)IDF);
			//	IDF = (double)((double)log(IDF)/(double)log(2));

			
				if ( IDFValue[i] != InvertedItemsNumbersCount[i] )
				{
					printf("\n%d....%d...%d",i,IDFValue[i],InvertedItemsNumbersCount[i]);
					exit(1);
				}

				if ( InvertedItemsNumbersCount[i] > 0  )
				{
						firstItem = 0;
						while(1)
						{


								TF = InvertedItemsNumbers[i][firstItem].Score;
							//	TF = (double) ( (double)TF/(double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber]);

							//	InvertedItemsNumbers[i][firstItem].Score = IDF*TF;

		

								

								WeightedLength = 0;
								WeightedLength = (double)((double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber]);

								IDF = (double)IDFValue[i];
							  
				
								IDFUpper = (double)(((double)(TotalPatents))- (double)IDF + (double)0.5);
								IDFLower = (double)IDF + (double)0.5;
								IDF = (double) (IDFUpper/IDFLower);
								IDF = (double)((double)log(IDF)/(double)log(2));

                    
								MainUpper = (double)(TF*(k+1));
								MainLower = (double)(TF + k*(1-b+(b*(WeightedLength/AveragePatentLength))));
								Main = MainUpper/MainLower;
								InvertedItemsNumbers[i][firstItem].Score  = (IDF*Main);






								firstItem++;
								if ( firstItem == InvertedItemsNumbersCount[i] )
									break;
						}
				




				}
		}

}


void Make_LM2000_Indexing()
{
		int firstItem = 0;
		double TF = 0;
		double IDF = 0;
		int i = 0,j=0,z,z1;
		double tempdouble;
		int tempInt;
        double k = 2.0;
        double b = .75;
		double TermFreq, IDFUpper, IDFLower;
  		double WeightedLength = 0;
        double MainUpper = 0;
        double MainLower = 0;
        double Main = 0;


		for ( i = 0; i < TotalItems+2; i++ )
		{

			
				if ( IDFValue[i] != InvertedItemsNumbersCount[i] )
				{
					printf("\n%d....%d...%d",i,IDFValue[i],InvertedItemsNumbersCount[i]);
					exit(1);
				}

				if ( InvertedItemsNumbersCount[i] > 0  )
				{
						firstItem = 0;
						while(1)
						{


								
						

		

								TF = InvertedItemsNumbers[i][firstItem].Score;								
								WeightedLength = 0;
								WeightedLength = (double)((double)fullPatentLength[InvertedItemsNumbers[i][firstItem].DocumentNumber]);



								IDF = (double)TermCollectionSum[i];
								IDF = (double) ( IDF / (double) (CollectionModel ) );							  

								

				
								IDFUpper = TF +  ( (double) ( (double) Parameter_Value * IDF ) );
								MainLower = (double) ( WeightedLength + (double) Parameter_Value );



								Main = IDFUpper/MainLower;
								InvertedItemsNumbers[i][firstItem].Score= Main;




								firstItem++;
								if ( firstItem == InvertedItemsNumbersCount[i] )
									break;
						}
				




				}
		}

}




void ReadItemFile(int clusterNumber,int patentsCopyingFrom, int patentsCopyingTo)
{
	FILE *itemfptr,*rowfptr,*fullTextfptr,*TFIDF_Write,*Find_Read;
	char itemFileName[300];
	char rowFileName[300];
	char fullTextFileName[300];
//	char wordNumberFileName[300];
//	char IDFFileName[300];

	int i, j,k;
	int ItemNumber = 0;
	int eof = 0;
	int RowCount = 0;
	int BlockCount = 0;
	int tt = 0;
	int IntLength = 0;
	char word[300];
	int IntervalCount = 0;
	int LastItem = 0;
	int Difference = 0;
	long ANDValue = 65535;
	int idfcount = 0;
	char printText[300];
	double Min,Max;
	 
	double TF = 0;
	double IDF = 0;
	



	sprintf(itemFileName,"%sItemsetProcessing%d.txt",sourcePath,clusterNumber);
	sprintf(rowFileName,"%sfullTextRow%d.txt",sourcePath,clusterNumber);
	sprintf(fullTextFileName,"%sfullText%d.txt",sourcePath,clusterNumber);
//	sprintf(wordNumberFileName,"%swordnumberclusterCompress%d.txt",sourcePath,clusterNumber);
//	sprintf(IDFFileName,"%sIDF.txt",sourcePath);




	itemfptr = fopen(itemFileName,"r");
	fullTextfptr = fopen(fullTextFileName,"r");
//	wordNumberfptr = fopen(wordNumberFileName,"r");
//	idf_fptr = fopen(IDFFileName,"r");


	fscanf(itemfptr,"%d",&TotalPatents);
	fscanf(itemfptr,"%d",&TotalItems);
	TotalItems++;


	printf("\n%d...%d\n",TotalPatents,TotalItems);


	if ( patentsCopyingTo > TotalPatents )
		patentsCopyingTo = TotalPatents;


	TotalPatents = (patentsCopyingTo-patentsCopyingFrom);

	TermsBinaryTreeParentNode = NULL;
	TermsBinaryTreeParentNodeQG = NULL;




	tt = 0;
	RowCount = 0;

	

	DocTermsArray_TotalTerms = (long *)malloc((TotalPatents)*sizeof(long));
	for ( j = 0; j < TotalPatents; j++ )
	{			
			DocTermsArray_TotalTerms[j] = 0;
	}




	IDFValue = (long *)malloc((TotalItems+2)*sizeof(long));
	MedianWeight = (double *)malloc((TotalItems+2)*sizeof(double));
	TermCollectionSum = (long *)malloc((TotalItems+2)*sizeof(long));

	for ( j = 0; j < TotalItems+2; j++ )
	{
			IDFValue[j] = 0;
			TermCollectionSum[j] = 0;
	}


	RowCount = 0;



	RowCount = 0;
	IntervalCount = 0;
	Patent_QRelevance_Count = 0;
//	FoundPatentsCount[0] = 0;
	while(1)
	{
			if ( fscanf(fullTextfptr,"%d %d",&ItemNumber,&IntLength) == EOF )
					break;

			if ( ItemNumber != -17 && ( Patent_QRelevance_Count >= patentsCopyingFrom && Patent_QRelevance_Count < patentsCopyingTo) )
			{

				     if ( IntLength > 0 )
					 {
							IDFValue[ItemNumber]++;
							DocTermsArray_TotalTerms[RowCount]++;
					 }
			}

			if ( ItemNumber == -17 )
			{
					if ( Patent_QRelevance_Count >= patentsCopyingFrom && Patent_QRelevance_Count < patentsCopyingTo )
					{
							RowCount++;
					}
					Patent_QRelevance_Count++;

			}
			if ( Patent_QRelevance_Count == patentsCopyingTo )
					break;
				

	}
	Patent_QRelevance_Count = 0;
	fclose(fullTextfptr);





	

	InvertedItemsNumbers = (struct InvertedItemsArray *)malloc((TotalItems+2)*sizeof(struct InvertedItemsArray));
	InvertedItemsNumbersCount = (long *)malloc((TotalItems+2)*sizeof(long));
	for ( j = 0; j < TotalItems+2; j++ )
	{
			InvertedItemsNumbers[j] = (struct InvertedItemsArray *)malloc((IDFValue[j])*sizeof(struct InvertedItemsArray));
			InvertedItemsNumbersCount[j] = 0;
	}

	

	fullPatentLength = (long *)malloc((TotalPatents)*sizeof(long));
	fullPatentUniqueItems = (long *)malloc((TotalPatents)*sizeof(long));

	fullPatentLength_feature = (long *)malloc((TotalPatents)*sizeof(long));
	fullPatentUniqueItems_feature = (long *)malloc((TotalPatents)*sizeof(long));





	PostingScore = (double *)malloc((MaxThreadSize)*sizeof(double));
	PostingTFScore = (double *)malloc((MaxThreadSize)*sizeof(double));
	PostingQueryTermsPresence = (long *)malloc((MaxThreadSize)*sizeof(long));
	PostingAge = (long *)malloc((MaxThreadSize)*sizeof(long));


	FoundPatents = (long *)malloc((MaxThreadSize)*sizeof(long));
	FoundPatentsScore = (double *)malloc((MaxThreadSize)*sizeof(double));
	FoundPatentsTFScore = (double *)malloc((MaxThreadSize)*sizeof(double));
	FoundPatentsCount = (long *)malloc((MaxThreadSize)*sizeof(long));



	QueryItemCount = (long *)malloc((MaxThreadSize)*sizeof(long));


	DocTermsArray_TermNumber = (long *)malloc((TotalPatents)*sizeof(long));
	DocTermsArray_TermFrequency = (long *)malloc((TotalPatents)*sizeof(long));
	DocTermsArray_TermRank = (long *)malloc((TotalPatents)*sizeof(long));
	DocTermsArray_TermWeight = (double *)malloc((TotalPatents)*sizeof(double));
	Thread_DocTermsArray_TotalTerms = (long *)malloc((TotalPatents)*sizeof(long));



	QueryItemArray = (long *)malloc((MaxThreadSize)*sizeof(long));
	QueryItemArray_Freq = (long *)malloc((MaxThreadSize)*sizeof(long));
	QueryItemArray_Weight = (double *)malloc((MaxThreadSize)*sizeof(double));




	GlobalPostingAge = 0;

	for ( j = 0; j < MaxThreadSize; j++ )
	{
			QueryItemArray[j] = (long *)malloc((50000)*sizeof(long));
			QueryItemArray_Freq[j] = (long *)malloc((50000)*sizeof(long));
			QueryItemArray_Weight[j] = (double *)malloc((50000)*sizeof(double));

			FoundPatents[j] = (long *)malloc((TotalPatents)*sizeof(long));
			FoundPatentsScore[j] = (double *)malloc((TotalPatents)*sizeof(double));
			FoundPatentsTFScore[j] = (double *)malloc((TotalPatents)*sizeof(double));


			PostingScore[j] = (double *)malloc((TotalPatents)*sizeof(double));
			PostingTFScore[j] = (double *)malloc((TotalPatents)*sizeof(double));
			PostingQueryTermsPresence[j] = (long *)malloc((TotalPatents)*sizeof(long));
			PostingAge[j] = (long *)malloc((TotalPatents)*sizeof(long));





	}


	for ( k = 0; k < TotalPatents; k++ )
	{
			DocTermsArray_TermNumber[k] = (long *)malloc((DocTermsArray_TotalTerms[k])*sizeof(long));
			DocTermsArray_TermFrequency[k] = (long *)malloc((DocTermsArray_TotalTerms[k])*sizeof(long));
			DocTermsArray_TermRank[k] = (long *)malloc((DocTermsArray_TotalTerms[k])*sizeof(long));
			DocTermsArray_TermWeight[k] = (double *)malloc((DocTermsArray_TotalTerms[k])*sizeof(double));

			Thread_DocTermsArray_TotalTerms[k] = 0;					
	}



	GlobalPostingAge = 0;


	for ( j = 0; j < TotalPatents; j++ )
	{
			fullPatentLength[j] = 0;
			fullPatentUniqueItems[j] = 0;

			fullPatentLength_feature[j] = 0;
			fullPatentUniqueItems_feature[j] = 0;


			for ( i = 0; i < MaxThreadSize; i++ )
				PostingAge[i][j] = -1;
	
	}






	AvgUniqueTerms = 0;
	CollectionModel = 0;
	RowCount = 0;
	IntervalCount = 0;
	Patent_QRelevance_Count = 0;
	AveragePatentLength = 0;
	
	sprintf(fullTextFileName,"%sfullText%d.txt",sourcePath,clusterNumber);
	fullTextfptr = fopen(fullTextFileName,"r");



	while(1)
	{
			if ( fscanf(fullTextfptr,"%d %d",&ItemNumber,&IntLength) == EOF )
					break;

			if ( ItemNumber != -17 && ( Patent_QRelevance_Count >= patentsCopyingFrom && Patent_QRelevance_Count < patentsCopyingTo) )
			{
				    if ( IntLength > 0 )
					{
						//	IntLength--;
							fullPatentLength[RowCount] += IntLength;
							fullPatentUniqueItems[RowCount]++;
					

							InsertItem_InvertedIndex(RowCount,ItemNumber,IntLength);	



							TermCollectionSum[ItemNumber] += IntLength;
							CollectionModel+=IntLength;


							

					}

					fullPatentLength_feature[RowCount] += IntLength;
					fullPatentUniqueItems_feature[RowCount]++;

					
			}

			if ( ItemNumber == -17 )
			{
					if ( Patent_QRelevance_Count >= patentsCopyingFrom && Patent_QRelevance_Count < patentsCopyingTo )
					{							
							AvgUniqueTerms += fullPatentUniqueItems[RowCount];
							AveragePatentLength += fullPatentLength[RowCount];

							RowCount++;
//							FoundPatentsCount = 0;

							if ( (RowCount%20000) == 0 )
								printf("\nIndexing Documents...%d",RowCount);

					}
					Patent_QRelevance_Count++;

			}
			if ( Patent_QRelevance_Count == patentsCopyingTo )
					break;
				

	}
	Patent_QRelevance_Count = 0;
	fclose(fullTextfptr);



 

	


	





	if ( RSType == 1 )
	{
		Make_TFIDF_Indexing();
		printf("\n TFIDF algorithm selected");
	}
	



	AveragePatentLength = (double)(AveragePatentLength/(double)TotalPatents);
	AvgUniqueTerms = (double)(AvgUniqueTerms/(double)TotalPatents);

	if ( RSType == 2 )
	{
			Make_BM25_Indexing();
			printf("\n BM25 algorithm selected");

	}

	if  ( RSType == 3 )
	{
			Make_LM2000_Indexing();
			printf("\n LM algorithm selected");

	}


	if  ( RSType == 4 )
	{
			Make_JM_Indexing();
			printf("\n JM algorithm selected");

	}

	if  ( RSType == 5 )
	{
			printf("\n Absolute Discounting Smooting algorithm selected");
			Make_AbsDis_Indexing();

	}

	if  ( RSType == 6 )
	{
			printf("\n Two Stage Smooting algorithm selected");
			Make_TwoStage_Indexing();
	}


	if  ( RSType == 7 )
	{
			printf("\n Un Normalized TFIDF algorithm selected");
			Make_UnNormTFIDF_Indexing();
	}

	if  ( RSType == 8 )
	{
			printf("\n SMART algorithm selected");
			Make_SMART_Indexing();
	}



	sprintf(printText,"cluster Number = %d",clusterNumber);
	gotoxy(5,5,printText);

	sprintf(printText,"patents Copying From = %d",patentsCopyingFrom);
	gotoxy(5,6,printText);

	sprintf(printText,"patents Copying To = %d",patentsCopyingTo);
	gotoxy(5,7,printText);


	
/*	sprintf(itemFileName,"%spartition_input.txt",sourcePath);
	itemfptr = fopen(itemFileName,"r");
	while(1)
	{
			if ( fscanf(itemfptr,"%d	%f	%f",&i,&Min,&Max) == EOF )
				break;

			PartitionMinScore[i] = Min;
			PartitionMaxScore[i] = Max;


	}
	fclose(itemfptr);
*/


}


void quicksort__DocumentsTerms ( long PN, long lo , long hi )
{
		long i = lo, j = hi;
		long h;
		long x = DocTermsArray_TermFrequency[PN][(lo+hi)/2];
		long iTempNumber;
		double dTempNumber;
		do
		{
				while ( DocTermsArray_TermFrequency[PN][i] > x ) i++;
				while ( DocTermsArray_TermFrequency[PN][j] < x ) j--;
				if ( i <= j )
				{

						dTempNumber = DocTermsArray_TermWeight[PN][i];
						DocTermsArray_TermWeight[PN][i] = DocTermsArray_TermWeight[PN][j];
						DocTermsArray_TermWeight[PN][j] = dTempNumber;


						iTempNumber = DocTermsArray_TermFrequency[PN][i];
						DocTermsArray_TermFrequency[PN][i] = DocTermsArray_TermFrequency[PN][j];
						DocTermsArray_TermFrequency[PN][j] = iTempNumber;

							
						iTempNumber = DocTermsArray_TermRank[PN][i];
						DocTermsArray_TermRank[PN][i] = DocTermsArray_TermRank[PN][j];
						DocTermsArray_TermRank[PN][j] = iTempNumber;
			
					

						iTempNumber = DocTermsArray_TermNumber[PN][i];
						DocTermsArray_TermNumber[PN][i] = DocTermsArray_TermNumber[PN][j];
						DocTermsArray_TermNumber[PN][j] = iTempNumber;




						i++;
						j--;
				}

		}
		while (i<=j);

		if ( lo<j) quicksort__DocumentsTerms(PN,lo,j);
		if ( i<hi) quicksort__DocumentsTerms (PN,i,hi);
	
}


void quicksort__performance ( int lo , int hi , int ThreadNumber)
{
		int i = lo, j = hi;
		long h;
		double x = FoundPatentsScore[ThreadNumber][ (lo+hi)/2 ];
		long iTempNumber;
		double dTempNumber;
		do
		{
				while ( FoundPatentsScore[ThreadNumber][i] > x ) i++;
				while ( FoundPatentsScore[ThreadNumber][j] < x ) j--;
				if ( i <= j )
				{

						iTempNumber = FoundPatents[ThreadNumber][i];
						FoundPatents[ThreadNumber][i] = FoundPatents[ThreadNumber][j];
						FoundPatents[ThreadNumber][j] = iTempNumber;

			
						dTempNumber = FoundPatentsScore[ThreadNumber][i];
						FoundPatentsScore[ThreadNumber][i] = FoundPatentsScore[ThreadNumber][j];
						FoundPatentsScore[ThreadNumber][j] = dTempNumber;


						i++;
						j--;
				}

		}
		while (i<=j);

		if ( lo<j) quicksort__performance (lo,j,ThreadNumber);
		if ( i<hi) quicksort__performance (i,hi,ThreadNumber);
	
}


void *ProcessQueryInInvertedIndex(void *ptr)
{
		int z = 0,z1 = 0;
		int firstItem[100];
		double MinimumScore = 999999;
		double TopKCheck = 0;
		int NULLCount = 0;
		int DocumentNumber = 0;
		long DN;
		long DN2;
		double Score = 0;
		double TFScore = 0;
		int Length = 0;
		int zero = 0;


		double TF = 0,SecondPart,SecondPart2;
		double IDF = 0;
	    double Parameter  = 0.7;
	    double Parameter2  = 2000;

		long ThreadNumber;
		long Local_GlobalPostingAge;
		long QueryPatentNumber;


		thdata *data;            
		data = (thdata *) ptr;  

		ThreadNumber=  data->ThreadNumber;
		Local_GlobalPostingAge = data->Local_GlobalPostingAge;
		QueryPatentNumber = data->QueryPatentNumber;



		Parameter = Parameter_Value;
		Parameter2 = Parameter_Value;


		for ( z = 0; z < QueryItemCount[ThreadNumber]-1; z++ )
		{
					firstItem[z] = 0;

					if ( InvertedItemsNumbersCount[QueryItemArray[ThreadNumber][z]] == 0 )
					{
						//	exit(1);
							firstItem[z] = -1;
							return;
					}
		}


		
		

		

		while(1)
		{

					for ( z = 0; z < QueryItemCount[ThreadNumber]-1; z++ )
					{
								

								if ( firstItem[z] != -1 )
								{
									        

											DocumentNumber = InvertedItemsNumbers[QueryItemArray[ThreadNumber][z]][firstItem[z]].DocumentNumber;
											Score = InvertedItemsNumbers[QueryItemArray[ThreadNumber][z]][firstItem[z]].Score;
											TFScore = InvertedItemsNumbers[QueryItemArray[ThreadNumber][z]][firstItem[z]].TFScore;


											Length = fullPatentLength[DocumentNumber];

											 


											if ( PostingAge[ThreadNumber][ DocumentNumber ] != Local_GlobalPostingAge )
											{
														PostingAge[ThreadNumber][DocumentNumber] = Local_GlobalPostingAge;
														PostingQueryTermsPresence[ThreadNumber][DocumentNumber] = 1;




														
														PostingScore[ThreadNumber][DocumentNumber] = Score;


														PostingTFScore[ThreadNumber][DocumentNumber] = (double)( (double)TFScore/*/(double)Length*/ );





														
											}
											else
											{
												
													

														PostingQueryTermsPresence[ThreadNumber][DocumentNumber]++;
														if ( RSType == 1 || RSType == 2 || RSType == 7 || RSType == 8 )
														{
																PostingScore[ThreadNumber][DocumentNumber] += Score;
																PostingTFScore[ThreadNumber][DocumentNumber] += (double)( (double)TFScore/(double)Length );
														}
														if ( RSType == 3 || RSType == 4 || RSType == 5 || RSType == 6 )
														{
																PostingScore[ThreadNumber][DocumentNumber] *= Score;
																PostingTFScore[ThreadNumber][DocumentNumber] += (double)( (double)TFScore/(double)Length );


														}

											}

								}

					}


					

					//NULLCount = 0;
					for ( z = 0; z < QueryItemCount[ThreadNumber]-1; z++ )
					{
							if ( firstItem[z] != -1 )
									firstItem[z]++;

							if ( firstItem[z] == InvertedItemsNumbersCount[QueryItemArray[ThreadNumber][z]] )
							{
									NULLCount++;
									firstItem[z] = -1;

							}
					}
					if ( NULLCount == QueryItemCount[ThreadNumber]-1 )
						break;

			
		}
		

		
		for ( z = 0; z < TotalPatents; z ++ )
		{
					DocumentNumber = z;
					SecondPart = 0;
					TF = 0;
					IDF = 0;
					SecondPart2 = 0;



					if ( PostingQueryTermsPresence[ThreadNumber][DocumentNumber] > 0 )
					{
								
								FoundPatents[ThreadNumber][FoundPatentsCount[ThreadNumber]] = DocumentNumber;
								FoundPatentsScore[ThreadNumber][FoundPatentsCount[ThreadNumber]] = PostingScore[ThreadNumber][DocumentNumber]+20;
								FoundPatentsTFScore[ThreadNumber][FoundPatentsCount[ThreadNumber]] = PostingTFScore[ThreadNumber][DocumentNumber];
								FoundPatentsCount[ThreadNumber]++;



					}
					PostingQueryTermsPresence[ThreadNumber][DocumentNumber]  = 0;
					PostingScore[ThreadNumber][DocumentNumber] = 0;


		}
	








					if ( FoundPatentsCount[ThreadNumber] > 0 )
							quicksort__performance (0,FoundPatentsCount[ThreadNumber]-1,ThreadNumber);


}




void quicksort__GINI ( int lo , int hi )
{
		int i = lo, j = hi;
		long h;
		double x = FoundPatentsScore[0][ (lo+hi)/2 ];
		long iTempNumber;
		double dTempNumber;
		do
		{
				while ( FoundPatentsScore[0][i] < x ) i++;
				while ( FoundPatentsScore[0][j] > x ) j--;
				if ( i <= j )
				{

		
						dTempNumber = FoundPatentsScore[0][i];
						FoundPatentsScore[0][i] = FoundPatentsScore[0][j];
						FoundPatentsScore[0][j] = dTempNumber;


						i++;
						j--;
				}

		}
		while (i<=j);

		if ( lo<j) quicksort__GINI (lo,j);
		if ( i<hi) quicksort__GINI (i,hi);
	
}


double CalculateGINI(int PN, int Feature)
{


		int j = 0;
		double RankSum = 0;
		double UpperSum = 0;
		double LowerSum = 0;
		double GINI = 0;


		FoundPatentsCount[0] = 0;
		for ( j = 0; j < Thread_DocTermsArray_TotalTerms[PN]; j++ )
		{
				if ( Feature == 1 )
					RankSum = (double) ( (double) DocTermsArray_TermRank[PN][j]/ (double)IDFValue[DocTermsArray_TermNumber[PN][j]] );	
				if ( Feature == 2 )
					RankSum = DocTermsArray_TermWeight[PN][j];

				FoundPatentsScore[0][FoundPatentsCount[0]] = RankSum;
				FoundPatentsCount[0]++;
//				if ( j > 80 )
//					break;
		}
		
		if ( FoundPatentsCount[0] > 0 )
			quicksort__GINI ( 0, FoundPatentsCount[0]-1);

		
		UpperSum = 0;
		LowerSum = 0;
		for ( j = 0; j < FoundPatentsCount[0]; j++ )
		{
								
				UpperSum += ((2*(j+1)-(FoundPatentsCount[0])-1) * FoundPatentsScore[0][j] );
				LowerSum += FoundPatentsScore[0][j];					
										
		}
		LowerSum = LowerSum * ((FoundPatentsCount[0])-1);
		GINI = UpperSum / LowerSum;


		if ( UpperSum > 0 && LowerSum > 0 )
			return GINI;
		else
			return 1;

				
	
				


}


void ExtracFeatures(int clusterNumber)
{
		int i = 0, j = 0,k= 0;
		double RankSum  = 0;
		double WeightSum = 0;
		double LowerRankRatio;
		double DiffMedianWeight = 0;
		double GINI_Rank = 0;
		double GINI_MedianWeight = 0;
//		double FScore,TotalQueries;
		double AvgTF;
		double AvgIDF;
		double ATW;
		double ATRP;
		double VTRP;

		int TT =0;
		FILE *features_writing;//*findability_reading;
		char fileName2[200];
		double Points;
//		double Median_FScore = 0;
		//int HighLow = 0;
		int TopCount;
		long MainSize = 0;
 
		
		

		sprintf(fileName2,"%sWeightingFeatures%d.txt",sourcePath,clusterNumber);
		features_writing = fopen(fileName2,"w");

	
	

		

	

		FoundPatentsCount[0] = 0;
		for ( i = 0; i < TotalPatents; i++ )
		{


				LowerRankRatio = 0;
				DiffMedianWeight = 0;
				TT = 0;
				TopCount = 0;
				ATW = 0;
				ATRP = 0;
				VTRP = 0;

					
				quicksort__DocumentsTerms ( i, 0 , Thread_DocTermsArray_TotalTerms[i]-1 );

				for ( j = 0; j < Thread_DocTermsArray_TotalTerms[i]; j++ )
				{
						ATRP += (double) ( (double) DocTermsArray_TermRank[i][j]/ (double)IDFValue[DocTermsArray_TermNumber[i][j]] );									
						ATW += DocTermsArray_TermWeight[i][j];
						TT++;						
						DiffMedianWeight += DocTermsArray_TermWeight[i][j] - MedianWeight[DocTermsArray_TermNumber[i][j]];

						Points = (double) ( (double) DocTermsArray_TermRank[i][j]/ (double)IDFValue[DocTermsArray_TermNumber[i][j]] );
						if ( Points < 0.98  )
							LowerRankRatio++;

				}


				if ( TT > 0 )
				{
						ATW = (double)((double)ATW/(double)TT);
						ATRP = (double)((double)ATRP/(double)TT);

						
						
						LowerRankRatio = (double)((double)LowerRankRatio/(double)TT);
						DiffMedianWeight = (double)((double)DiffMedianWeight/(double)TT);

						
						
						

				}
				else
				{
						RankSum = 0;
						WeightSum = 0;
						LowerRankRatio = 0;
						DiffMedianWeight = 0;
						AvgTF = 0;
						AvgIDF = 0;
				}

				VTRP = CalculateGINI(i,1);

			
			
				fprintf(features_writing,"%lf	%lf	%lf	%lf	%lf\n",ATW,ATRP,VTRP,DiffMedianWeight,LowerRankRatio);

		}
		fclose(features_writing);

}

/*

void ExtracSimpleFeatures(int clusterNumber)
{
		int i = 0, j = 0;
		double RankSum  = 0;
		double WeightSum = 0;
		double LowerRankRatio;
		double DiffMedianWeight = 0;
		double GINI_Rank = 0;
		double GINI_MedianWeight = 0;
//		double FScore,TotalQueries;
		double AvgTF;
		double AvgIDF;

		int TT =0;
		FILE *features_writing;//*findability_reading;
		char fileName2[200];
		double Points;
//		double Median_FScore = 0;
		//int HighLow = 0;
		int TopCount;
 
		
		

		sprintf(fileName2,"%sWeightingFeatures%d_full.txt",sourcePath,clusterNumber);
		features_writing = fopen(fileName2,"w");

	

		

		
		FoundPatentsCount[0] = 0;
		for ( i = 0; i < TotalPatents; i++ )
		{



				AvgTF = 0;
				AvgIDF = 0;
				TopCount = 0;
	
				for ( j = 0; j < DocTermsArray_TotalTerms[i]; j++ )
				{
								
						AvgTF += DocTermsArray_TermFrequency[i][j];
						TopCount++;
						AvgIDF += (double)((double)(IDFValue[DocTermsArray_TermNumber[i][j]])/(double)TotalPatents);

				}

				AvgTF = (double)((double)AvgTF/(double)TopCount);
				AvgIDF = (double)((double)AvgIDF/(double)TopCount);
						

	
				if ( i%2000 == 0 )
					printf("\nFeature Writing Completed = %d",i);

				fprintf(features_writing,"%lf	%lf	%d	%d\n",AvgTF,AvgIDF,fullPatentUniqueItems_feature[i],fullPatentLength_feature[i]);

		}
		fclose(features_writing);

}*/

void ProcessQueries(int clusterNumber)
{

	int z = 0,i,j,z1;
	long TotalQueriesProcess = 0;
	long ThreadCount = 0;
	long DN;
	long DN2;


 
		
	pthread_t thread1[20000];  
	thdata data1[20000];



//	exit(1);




	GlobalPostingAge = 0;


     for ( i = 0; i < TotalItems; i++ )
	 {

					


					QueryItemArray[GlobalPostingAge%MaxThreadSize][0] = i;
					QueryItemCount[GlobalPostingAge%MaxThreadSize] = 2;		
	

					TotalQueriesProcess++;
					GlobalPostingAge++;

				
					if ( GlobalPostingAge%MaxThreadSize == 0 )
					{
											

									for ( z = 0; z < TotalQueriesProcess; z ++ )
									{
											FoundPatentsCount[z] = 0;
											data1[z].ThreadNumber = z;
											data1[z].Local_GlobalPostingAge = z+GlobalPostingAge;
											data1[z].QueryPatentNumber = (ThreadCount*MaxThreadSize)+z;
											pthread_create (&thread1[z], NULL, (void *) &ProcessQueryInInvertedIndex, (void *) &data1[z]);									

									}
										
									for ( z = 0; z  < TotalQueriesProcess; z++ )
											pthread_join(thread1[z], NULL);
											

									for ( z = 0; z  < TotalQueriesProcess; z++ )
									{

											for ( z1 = 0; z1 < FoundPatentsCount[z]; z1++ )
											{
													DN = FoundPatents[z][z1];
													DN2 = Thread_DocTermsArray_TotalTerms[DN];
														
													DocTermsArray_TermNumber[DN][DN2] = QueryItemArray[z][0]; 
													DocTermsArray_TermFrequency[DN][DN2] = FoundPatentsTFScore[z][z1]; 
													DocTermsArray_TermRank[DN][DN2] = (FoundPatentsCount[z]-z1); 
													DocTermsArray_TermWeight[DN][DN2] = FoundPatentsScore[z][z1]; 
														
													Thread_DocTermsArray_TotalTerms[DN]++;								

											}
											MedianWeight[QueryItemArray[z][0]] = FoundPatentsScore[z][FoundPatentsCount[z]/2];



											QueryItemCount[z] = 0;
									}

									TotalQueriesProcess = 0;
									ThreadCount++;

					}
				

					if ( i%10000 == 0 )
						printf("\nFeatures Ranking Completed = %d",i);

	}


		/*			for ( z1 = 0; z1 < FoundPatentsCount[ThreadNumber]; z1++ )
					{
								DN = FoundPatents[ThreadNumber][z1];
								DN2 = Thread_DocTermsArray_TotalTerms[ThreadNumber][DN];
								
								DocTermsArray_TermNumber[ThreadNumber][DN][DN2] = QueryItemArray[ThreadNumber][0]; 
								DocTermsArray_TermFrequency[ThreadNumber][DN][DN2] = FoundPatentsTFScore[ThreadNumber][z1]; 
								DocTermsArray_TermRank[ThreadNumber][DN][DN2] = (FoundPatentsCount[ThreadNumber]-z1); 
								DocTermsArray_TermWeight[ThreadNumber][DN][DN2] = FoundPatentsScore[ThreadNumber][z1]; 
								
								Thread_DocTermsArray_TotalTerms[ThreadNumber][DN]++;								

					}*/
		


	ExtracFeatures(RSType);
	

}




int main (int argc, char *argv[])
{                              
	int clusterNumber = 0;
	int patentsCopyingFrom;
	int patentsCopyingTo;
	//int fileNumber;

	
	system("clear");


	

	// first parameter = files folder path (like //home//bashir//)
	// second parameter = cluster number
	// third parameter = patentsCopyingFrom
	// forth parameter = patentsCopyingTo
	// fifth parameter = fileNumber - log
	// Retrieval System type = 1. TFIDF, 2. BM25, 3. LM
	// parameter_value;


	strcpy(sourcePath,argv[1]);
	clusterNumber = atoi(argv[2]);

	patentsCopyingFrom = atoi(argv[3]);
	patentsCopyingTo = atoi(argv[4]);
	fileNumber = atoi(argv[5]);
	RSType = atoi(argv[6]);
	Parameter_Value = atof(argv[7]);



	MaxThreadSize = 1000;


	ReadItemFile(clusterNumber,patentsCopyingFrom,patentsCopyingTo);
	ProcessQueries(clusterNumber);
///	GenerateQueries();

	return 0;
}  
