All pastes #278206 Raw Edit

Mine

public text v1 · immutable
·published 2006-12-13 22:18 UTC
rendered paste body
#ifndef structES_H
#define structES_H

#include<string>
#include <stdio.h>
#include<conio.h> //gia th getch()
#include <iostream>
#include<fstream> //gia thn infile,ifstream,
#include <algorithm>
#include<cctype>
#include<math.h>
#include<process.h>


#using <mscorlib.dll>

void returnCurrentDirectory(char buffer[])
{

	/* Get the current working directory: */
	if( _getcwd( buffer, _MAX_PATH ) == NULL )
		perror( "_getcwd error" );

}
using namespace System;
using namespace System::IO;

/* Pairnei ena char[] to metatrepei se String* kai to epistrefei */
String* convertToString(char buffer[])
{
	String* stringVal;
	stringVal = System::Convert::ToString(buffer);
	return stringVal;
}


using namespace std;

/* klash me mia synarthsh pou elegxei an ena string einai arithmos */
struct nondigit
{
	public:

		bool operator() (char c) {return !isdigit(c);}
};

/* klash pou antistoixei se mia leksh */
struct word_freq
{
	public:

		/* h leksh */
		string word;

		/* o arithmos emfanisewn ths lekshs */
		int count;

		word_freq* next;
		word_freq* prev;

		int doc_appearence;

		/* Methodos egkatastashs me ena orisma */
		word_freq(string w)
		{
			word=w;
			count=0;
			doc_appearence=0;
			next=NULL;
			prev=NULL;
		}
};

struct word_appear
{
	public:

		/* h leksh */
		string word;

		/* o arithmos emfanisewn ths lekshs */
		int count; /* arithmos emfanisewn ths lekshs se olo to arxeio */

		bool flag;

		int document_appearence; /*arithmos twn arthrwn pou emfanizetai h leksh */

		word_appear* next;

		/* Methodos egkatastashs me ena orisma */
		word_appear(string w)
		{
			word=w;
			count=0;
			next=NULL;
			flag=true;
			document_appearence=0;
		}
};

struct remaining_words
{
	private:
		word_freq* head;
		word_freq* tail;

		/* o synolikos arithos twn stoixeiwn ths listas, dhl oi lekseis */
		int count;

	public:
		remaining_words()
		{
			head=NULL;
			tail=NULL;
			count=0;
		}

		/* prosthetei mia leskh sth lista */
		void add(string word,int count);

        /* afairei ena stoixeio apo th lista */
		void pop();

		/* epistrefei true an einai adeia h lista */
		bool IsEmpty();

		/* adeiazei th lista me diadoxika pop */
		void EmptyList();

		bool IsReamainingWord(string word,int *app_count);

		int RemainingWordsReturnCount();

		void CopyList(string * WordsArray);

};

void remaining_words::add(string word,int count)
{
	word_freq* ptr=head;
	(this->count)++;/*afkshsh tou metrhth twn leksewn ths listas kata 1 */

	word_freq* new_wf=new word_freq(word);
	if(head==NULL)     //den iparxei kanena stoixeio sth lista
	{
		head=new_wf;          //tithetai ws prwto stoixeio ths listas
		new_wf->next=NULL;
		tail=new_wf;          //afou einai to monadiko stoixeio ths listas tithetai kai ws teleftaio
	    new_wf->prev=NULL;
	}

	else
	{
		word_freq* ptr=head;

		while (ptr!=NULL)//gia olh th lista me tis lekseis
		{
			if(ptr->word>new_wf->word) //an exei vrethei hdh h oxi
			{
				if(ptr==head)
				{
					head=new_wf;
					ptr->prev=head;
					head->next=ptr;
				}
				else
				{
					ptr->prev->next=new_wf;
					new_wf->prev=ptr->prev;
					new_wf->next=ptr;
					ptr->prev=new_wf;
				}
				goto end;
			}
			ptr=ptr->next;
		}
		word_freq* temp;
		temp=tail;
		temp->next=new_wf;    //prostithetai sto telos tis listas
		new_wf->prev=tail;
		tail=new_wf;     //tithetai ws teleftaio stoixeio tis listas
	}
	end:
	new_wf->count=count; //o arithmos emfanisewn ths lekshs sto arxeio tithetai iso me count */
}

//eksagei to prwto stoixeio ths listas
void remaining_words::pop()
{
	//h lista den einai adeia
	if(head!=NULL)
	{
		//iparxoun toulaxiston 3 stoixeia sth lista
		if((head->next!=NULL)&&(head->next->next!= NULL))
		{
			word_freq *temp1;
			word_freq *temp2;
			temp1=head;
			temp2=head->next;
			head=temp2;
			delete temp1;
		}
		//iparxoun 2 to poly stoixeia sth lista
		else //!(head->next!=NULL)&&(head->next->next!= NULL)
		{
			//iparxoun 2 akrivws stoixeia
			if(head->next!=NULL)
			{
				word_freq *temp1;
				temp1=head;
				head->next=NULL;
				head=tail;
				delete temp1;
			}
			//iparxei mono 1 stoixeio
			else //!(head->next!=NULL)
			{
				word_freq* temp1;
				temp1=head;
				head=NULL;
				tail=NULL;
			}
		}
	}
}

//Epistrefei True an einai adeia h lista alliws epistrefei False
bool remaining_words::IsEmpty()
{
	if( head == NULL)
		return true;
	return false;
}

void remaining_words::EmptyList()
{
	while(!IsEmpty())
	   pop();
	count=0;
}

bool remaining_words::IsReamainingWord(string word2,int *app_count)
{
	word_freq* ptr=head;

	while (ptr!=NULL)//gia olh th lista me tis lekseis
	{
		if(ptr->word==word2) //an exei vrethei hdh h oxi
		{
			(*app_count)=ptr->count; //de vrethike pros to paron thn elegxoume me thn epomenh lesk ths listas
		  return true;
		}
		if(ptr->word>word2)
			goto end;
		ptr=ptr->next;
	}
    end:
	return false;
}

int remaining_words::RemainingWordsReturnCount()
{
	return count;
}

void remaining_words::CopyList(string * WordsArray)
{
	word_freq* ptr=head;
	int i=0;
	while (ptr!=NULL)//gia olh th lista me tis lekseis
	{
		WordsArray[i]=ptr->word;
		i++;
		ptr=ptr->next;
	}
}

/* h syndedemenh lista me stoixeia tis lekseis */
struct freq_count
{
	private:
		word_freq* head;
		word_freq* tail;
		double** RemainingWords;

		string* WordsArray;
		int number_of_words;

		/* o synolikos arithos twn stoixeiwn ths listas, dhl oi lekseis */
		int count;

	public:
		freq_count()
		{
			head=NULL;
			tail=NULL;
			count=0;
			RemainingWords= NULL;
		    WordsArray=NULL;
		}

		/* prosthetei mia leskh sth lista */
		void add(string word,int app_count);

		/* grafei tis lekseis ths listas sto arxeio x */
		void print_out(char x[],int y,string title,int documents);

        /* afairei ena stoixeio apo th lista */
		void pop();

		/* epistrefei true an einai adeia h lista */
		bool IsEmpty();

		/* adeiazei th lista me diadoxika pop */
		void EmptyList();

		void MakeArray(int documents,int words);

		void DestroyArray(int words,int documents);

		void InitializeArray(int documents,int words);

		void MakeWordsArray(remaining_words rw);

		int BinarySearch(string key);

		void WriteTable(char x[],int words,int documents);

		string doubleToString(double num);

};

void freq_count::add(string word,int app_count)
{

	word_freq* ptr=head;

	/* krataei an h leksh yparxei hdh sth lista */
	int found=1;

	count++;  //+1 oi synolikes lekseis toy keimenou

	while (ptr!=NULL && found!=0)//gia olh th lista me tis lekseis
	{
		found=(word.compare(ptr->word)); //an exei vrethei hdh h oxi
		if (found!=0) ptr=ptr->next; //de vrethike pros to paron thn elegxoume me thn epomenh lesk ths listas
	}

	if (found==0)       //thn exoume hdh vrei th leksh
		(ptr->count)++; //ara afksanoume ton arithmo emfanisewn ths kata 1
	else           //th vriskoume gia prwth fora
	{
		word_freq* new_wf=new word_freq(word);
		if(head==NULL)     //den iparxei kanena stoixeio sth lista
		{
			head=new_wf;          //tithetai ws prwto stoixeio ths listas
			new_wf->next=NULL;
			tail=new_wf;          //afou einai to monadiko stoixeio ths listas tithetai kai ws teleftaio
		}
		else
		{
			word_freq* temp;
			temp=tail;
			temp->next=new_wf;    //prostithetai sto telos tis listas
			tail=new_wf;     //tithetai ws teleftaio stoixeio tis listas
		}

		(new_wf->count)++; //o arithmos emfanisewn ths lekshs sto arthro +1 */
		new_wf->doc_appearence=app_count;
	}
}

//Epistrefei True an einai adeia h lista alliws epistrefei False
bool freq_count::IsEmpty()
{
	if( head == NULL)
		return true;
	return false;
}

//eksagei to prwto stoixeio ths listas
void freq_count::pop()
{
	//h lista den einai adeia
	if(head!=NULL)
	{
		//iparxoun toulaxiston 3 stoixeia sth lista
		if((head->next!=NULL)&&(head->next->next!= NULL))
		{
			word_freq *temp1;
			word_freq *temp2;
			temp1=head;
			temp2=head->next;
			head=temp2;
			delete temp1;
		}
			//iparxoun 2 to poly stoixeia sth lista
		else //!(head->next!=NULL)&&(head->next->next!= NULL)
		{
			//iparxoun 2 akrivws stoixeia
			if(head->next!=NULL)
			{
				word_freq *temp1;
				temp1=head;
				head->next=NULL;
				head=tail;
				delete temp1;
			}
			//iparxei mono 1 stoixeio
			else //!(head->next!=NULL)
			{
				word_freq* temp1;
				temp1=head;
				head=NULL;
				tail=NULL;
			}
		}
	}
}

void freq_count::EmptyList()
{
	count=0;
	while(!IsEmpty())
	   pop();
}

void freq_count::MakeArray(int documents,int words)
{
	number_of_words=words;
	RemainingWords= new double *[words];


    for(int i=0;i<words;i++)
	{
		*(RemainingWords +i)= new double[documents];
		
	}
	for(int i=0;i<documents;i++)
	WordsArray=new string[words];
}

void freq_count::MakeWordsArray(remaining_words rw)
{
	rw.CopyList(&WordsArray[0]);
}



void freq_count::DestroyArray(int words,int documents)
{

	for(int i=0;i<words;i++)
	{
		delete[] *(RemainingWords +i);
	}
	for(int i=0;i<documents;i++)
       delete[] RemainingWords;

	delete[] WordsArray;
}

void freq_count::InitializeArray(int documents,int words)
{
	for(int i=0;i<words;i++)
		for(int j=0;j<documents;j++)
			RemainingWords[i][j]=0.0;
}

void freq_count::print_out(char x[],int y,string title,int documents)
{
	
	word_freq* ptr = head;
	float float_count=(float)count;
	float percentage;

	char SubDirectoryChar2[_MAX_PATH];
	char Columns[_MAX_PATH];
	using namespace std;
	using namespace System;
	using namespace System::IO;

	returnCurrentDirectory(SubDirectoryChar2);

	strcat_s(SubDirectoryChar2,"\\articles\\");

	strcpy_s(Columns,SubDirectoryChar2);
	char filename[100];

	strcpy_s(filename,"Columns");
	strcat_s(filename,x);
	strcat_s(Columns,filename);
	strcat_s(SubDirectoryChar2,x);

	String* path=convertToString(SubDirectoryChar2);
    String* path2=convertToString(Columns);

    StreamWriter* streamW;
	StreamWriter* streamW2;

    if (!File::Exists(path))
    {   // Create a file to write to.
         streamW = File::CreateText(path);
    }
    else
    {
		// This text is always added, making the file longer over time
		// if it is not deleted.
		streamW = File::AppendText(path);
    }
	
	    if (!File::Exists(path2))
    {   // Create a file to write to.
         streamW2 = File::CreateText(path2);
    }
    else
    {
		// This text is always added, making the file longer over time
		// if it is not deleted.
		streamW2 = File::AppendText(path2);
    }
double temp;
double temp2;
double temp3;
double temp4;
    streamW->Write(y);
streamW->Write("\n\n");

	streamW2->Write(y-1);
	streamW2->Write(title.c_str());
	streamW2->Write("\n\n");
int index;
	while ((ptr!=NULL)&&(ptr!=tail))
	{
		index=BinarySearch(ptr->word);
		temp=(double)ptr->doc_appearence;
		temp2=documents/temp;
		temp3=(double)ptr->count;
		temp4=temp3*log10(temp2);

		RemainingWords[index][y-1]=temp4;
		
		streamW->Write(ptr->word.c_str());
		streamW->Write(" ");
		streamW->Write(ptr->count);
		streamW->Write(" ");
		streamW->Write(ptr->doc_appearence);
		streamW->Write("\n");
	
		ptr=ptr->next;       //proxwrame sthn epomenh leksh ths listas
	
	}

	streamW->Write("\n\n");
streamW->Close();
	
	streamW2->Close();
}

void freq_count::WriteTable(char x[],int words,int documents)
{

	char SubDirectoryChar2[_MAX_PATH];
	using namespace std;
	using namespace System;
	using namespace System::IO;

	returnCurrentDirectory(SubDirectoryChar2);

	strcat_s(SubDirectoryChar2,"\\articles\\");
	char Rows[_MAX_PATH];
	using namespace std;
	using namespace System;
	using namespace System::IO;

	returnCurrentDirectory(SubDirectoryChar2);

	strcat_s(SubDirectoryChar2,"\\articles\\");

	strcpy_s(Rows,SubDirectoryChar2);
	char filename[100];


	strcpy_s(filename,"Rows");
	strcat_s(filename,x);
	strcat_s(Rows,filename);


	strcat_s(SubDirectoryChar2,"TableFile");
	strcat_s(SubDirectoryChar2,x);

	String* path=convertToString(SubDirectoryChar2);
    String* path2=convertToString(Rows);

    StreamWriter* streamW;
	StreamWriter* streamW2;


  // Create a file to write to.
         streamW = File::CreateText(path);
      // Create a file to write to.
         streamW2 = File::CreateText(path2);
    

	string temp;
	string temp2;
	string temp3;

	for(int i=0;i<words;i++)
	{
		for(int j=0;j<documents;j++)
		{

			temp=doubleToString(RemainingWords[i][j]);
			streamW->Write(temp.c_str());

		    if(j!=(documents-1))
				streamW->Write(" ");
		}
        if(i!=(words-1))
		    streamW->Write("\n");

	    streamW2->Write(WordsArray[i].c_str());
	    streamW2->Write("\n");

	}


	streamW->Close();
	streamW2->Close();

}



string freq_count::doubleToString(double num) {
	using namespace std;
using std::string;char buf[80];
	sprintf_s(buf,"%lf", num);
	string ret = buf;
	ret = ret.substr(0,ret.find_last_not_of('0')+1);
	if(ret[ret.length()-1] == '.')
		ret = ret.substr(0,ret.length()-1);
	return ret;
}

int freq_count::BinarySearch(string key) {
   // function:
   //   Searches sortedArray[first]..sortedArray[last] for key.  
   // returns: index of the matching element if it finds key, 
   //         otherwise  -(index where it could be inserted)-1.
   // parameters:
   //   sortedArray in  array of sorted (ascending) values.
   //   first, last in  lower and upper subscript bounds
   //   key         in  value to search for.
   // returns:
   //   index of key, or -insertion_position -1 if key is not 
   //                 in the array. This value can easily be
   //                 transformed into the position to insert it.
  int first=0;
int   last=number_of_words;
   while (first <= last) {
       int mid = (first + last) / 2;  // compute mid point.
       if (key > WordsArray[mid]) 
           first = mid + 1;  // repeat search in top half.
       else if (key < WordsArray[mid]) 
           last = mid - 1; // repeat search in bottom half.
       else
           return mid;     // found it. return position /////
   }
   return -(first + 1);    // failed to find key
}






/* h syndedemenh lista me stoixeia tis lekseis */
struct appearrence_count
{
	private:
		word_appear* head;
		word_appear* tail;

		/* o synolikos arithos twn stoixeiwn ths listas, dhl oi lekseis */
		int count;

	public:
		appearrence_count()
		{
			head=NULL;
			tail=NULL;
			count=0;
		}

		/* prosthetei mia leskh sth lista */
		void add(string word);

        /* afairei ena stoixeio apo th lista */
		void pop();

		/* epistrefei true an einai adeia h lista */
		bool IsEmpty();

		/* adeiazei th lista me diadoxika pop */
		void EmptyList();

		void turn_flags_on();

		void print_out(remaining_words *rw,int document_counter);

};

void appearrence_count::add(string word)
{
	word_appear* ptr=head;

	/* krataei an h leksh yparxei hdh sth lista */
	int found=1;

	while (ptr!=NULL && found!=0)//gia olh th lista me tis lekseis
	{
		found=word.compare(ptr->word); //an exei vrethei hdh h oxi
		if (found!=0) ptr=ptr->next; //de vrethike pros to paron thn elegxoume me thn epomenh lesk ths listas
	}

	if (found==0)       //thn exoume hdh vrei th leksh
	{
		(ptr->count)++; //ara afksanoume ton arithmo emfanisewn ths kata 1
		if(ptr->flag==true)
		{
			(ptr->document_appearence)++;
			ptr->flag=false;
		}
	}

	else           //th vriskoume gia prwth fora
	{
		count++;  //+1 oi synolikes lekseis toy keimenou
		word_appear* new_wf=new word_appear(word);
		if(head==NULL)     //den iparxei kanena stoixeio sth lista
		{
			head=new_wf;          //tithetai ws prwto stoixeio ths listas
			new_wf->next=NULL;
			tail=new_wf;          //afou einai to monadiko stoixeio ths listas tithetai kai ws teleftaio
		}
		else
		{
			word_appear* temp;
			temp=tail;
			temp->next=new_wf;    //prostithetai sto telos tis listas
			tail=new_wf;     //tithetai ws teleftaio stoixeio tis listas
		}

		(new_wf->count)++; //o arithmos emfanisewn ths lekshs sto arthro +1 */
		(new_wf->document_appearence)++;
		new_wf->flag=false;
	}
}

//Epistrefei True an einai adeia h lista alliws epistrefei False
bool appearrence_count::IsEmpty()
{
	if( head == NULL)
		return true;
	return false;
}

//eksagei to prwto stoixeio ths listas
void appearrence_count::pop()
{
	//h lista den einai adeia
	if(head!=NULL)
	{
		//iparxoun toulaxiston 3 stoixeia sth lista
		if((head->next!=NULL)&&(head->next->next!= NULL))
		{
			word_appear *temp1;
			word_appear *temp2;
			temp1=head;
			temp2=head->next;
			head=temp2;
			delete temp1;
		}
			//iparxoun 2 to poly stoixeia sth lista
		else //!(head->next!=NULL)&&(head->next->next!= NULL)
		{
			//iparxoun 2 akrivws stoixeia
			if(head->next!=NULL)
			{
				word_appear *temp1;
				temp1=head;
				head->next=NULL;
				head=tail;
				delete temp1;
			}
			//iparxei mono 1 stoixeio
			else //!(head->next!=NULL)
			{
				word_appear* temp1;
				temp1=head;
				head=NULL;
				tail=NULL;
			}
		}
	}
}

void appearrence_count::EmptyList()
{
	count=0;
	while(!IsEmpty())
	   pop();
}



void appearrence_count::turn_flags_on()
{
	word_appear* ptr = head;

	while ((ptr!=NULL)&&(ptr!=tail))
	{
        ptr->flag=true;
		ptr=ptr->next;                             //proxwrame sthn epomenh leksh ths listas
	}

}

void appearrence_count::print_out(remaining_words *rw,int document_counter)
{
	word_appear* ptr = head;

	float float_count=(float)document_counter;/*synolikos arithmos arthrwn sto arxeio */

	float percentage; /*pososto emfanishs se arthra */
	while ((ptr!=NULL)&&(ptr!=tail))
	{
		percentage=(ptr->document_appearence/float_count)*100; //ipologizoume to pososto emfanishs
		if((percentage>=0.2)&&(percentage<=15))        //an einai mesa sto orio pou theloume
		{
			(*rw).add(ptr->word,ptr->document_appearence);
		}
		ptr=ptr->next;                             //proxwrame sthn epomenh leksh ths listas
	}
}

struct stop_word
{
	public:
		string word;
		stop_word* next;
		stop_word(string w)
		{
			word=w;
			next=NULL;
		}
};

struct stop_words_list
{
	private:
		stop_word* head;
		stop_word* tail;
	public:
		stop_words_list()
		{
			head=NULL;
			tail=NULL;
		}
		void add(string word);
		bool IsStopWord(string word);
};

void stop_words_list::add(string word)
{
	stop_word* ptr=head;

	stop_word* new_wf=new stop_word(word);
	if(head==NULL)     //den iparxei kanena stoixeio sth lista
	{
		head=new_wf;          //tithetai ws prwto stoixeio ths listas
		tail=new_wf;
		new_wf->next=NULL;
	}
	else
	{
		stop_word* temp;
		temp=tail;
		temp->next=new_wf;    //prostithetai sto telos tis listas
		tail=new_wf;     //tithetai ws teleftaio stoixeio tis listas
	}
}


//Epistrefei True an einai adeia h lista alliws epistrefei False
bool stop_words_list::IsStopWord(string word)
{
	stop_word* ptr=head;
	bool found=false;

	while (ptr!=NULL && !found)//gia olh th lista me tis lekseis
	{
		found=(word==ptr->word); //an exei vrethei hdh h oxi
		if (!found) ptr=ptr->next; //de vrethike pros to paron thn elegxoume me thn epomenh lesk ths listas
	}

	if (found)       //thn exoume hdh vrei th leksh
      return true;
	return false;
}




//eksagei to prwto stoixeio ths listas

#endif




/* Web_clustering.cpp */

#pragma warning(push)
#pragma warning(disable : 4561)

#include <cstdlib>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
#include <stdlib.h>
#include <direct.h>
#include"web_clustering.h"
#include <algorithm> //gia th transform

#using <mscorlib.dll>

using namespace boost;

/* Regular expressions */

/* taftopoiei string ths morfhs .I k opou k arithmos
   Sta arxeia pou exoume me arthra afto dhlwnei thn arxh
   enos arthrou
*/
regex expression1("^([.]I\\s[1-9][0-9]*)$");

/* taftopoiei string ths morfhs .X
   Sta arxeia pou exoume me arthra afto dhlwnei to telos
   toy keimenou poy mas endiaferei enos arthrou
*/
regex expression2("^([.]X)$");

/* taftopoiei string ths morfhs .W
   Sta arxeia pou exoume me arthra afto dhlwnei thn arxh
   toy keimenou poy mas endiaferei enos arthrou
*/
regex expression3("^([.]W)$");

regex expression4("^([.]T)$");

regex expression5("^([.]A)$");


using namespace System;
using namespace System::IO;


/*dhmioyrgei to fakelo articles kai trexei to filelist.exe */
void run();

using namespace std;

#define MAX_NUMBER_OF_FILES 100
#define MAX_FILENAME 50
#define MAX_WORD_LENGTH

/* dhmiourgei ta filenames twn newn arxeiwn apo ta palia p.x. MED.ALL => MED2.ALL */
string produce_name(string x);

void main()
{
    /* dhmioyrgoume to fakelo articles kai trexoume to filelist.exe */
	run();

	using namespace std;

	/*periexei ta filenames twn arxikwn arxeiwn */
	string files[MAX_FILENAME];

	/*periexei ta filenames twn newn arxeiwn */
	string files2[MAX_FILENAME];

	/* afta ta smheia stikshs orizoun thn srxh mias lekshs */
	const string delims(" \t,.; ( ) ' / \" -:!{}[]<>?+=:@#$%^&*~`");

	/* periexei mia th seira pou molis diavasthke apo ena arxeio se string */
	string line;

	/* periexei mia th seira pou molis diavasthke apo ena arxeio se char[] */
	char line2[MAX_FILENAME];

	/* periexei kathe fora mia leksh */
	string temp;

	/* metrhths pou deixnei posa arxeia me arthra yparxoun sto fakelo */
	int i=0;

    /* syndedemenh lista pou vazoume tis lekseis kathe arthrou*/
	freq_count c;

    /* syndedemenh lista pou vazoume tis lekseis pou kratame apo kathe arthro*/
	remaining_words rw;

    /* syndedemenh lista pou vazoume tis lekseis kathe arxeiou*/
	appearrence_count ac;

    /*metavlhth pou xrhsimopoioume gia na pername tis synolikes emfaniseis mias lekshs */
	int app_count;

    /* metavlhth pou metra ton arithmo arthrwn se ena arxeio */
	int document_counter;

	/* syndedemenh lista pou vazoume ta stop words */
	stop_words_list swl;

	/* metavlhth gia to anoigma tou arxeiou me ta stop words */
	ifstream file;

    /* metavlhth gia to anoigma tou arxeiou me th lista me ta .ALL arxeia */
    ifstream file2;

	/* anoigma toy arxeiou me ta stop words */
	file.open("stop words.txt");

	/* periexei kathe fora mia stop word */
	string temp_word;

	/*To anoigma tou arxeiou stop words.txt apetyxe */
	if (file.fail())
	{
		cout << "Opening of file \"stop words.txt\" failed.\n";
		_getch();
		exit(1);
	}

	/* mexri to telos toy arxeiou */
	while ( !file.eof() )
	{
		/*diavazoume mia seira apo to arxeio dhl mia leksh */
		file.getline(line2,MAX_FILENAME);

		/* anathetoume th leksh se mia metavlhth string */
		temp_word.assign(line2);

		/* thn prosthetoyme sth lista me tis stop words */
		swl.add(temp_word);
	}

    /* anoigoume to arxeio me th lista me ta arxeia me ta arthra */
	file2.open("directory_listing.txt");

	/*To anoigma tou arxeiou a apetyxe */
	if (file2.fail())
	{
		cout << "Opening of file \"a\" failed .\n";
		_getch();
		exit(1);
	}

	/* mexri to telos toy arxeiou */
	while ( !file2.eof() )
	{
		/* diavazoume mia seira dhl to filename enos arxeiou me arthra */
		file2.getline(line2,MAX_FILENAME);

		/* prosthetoume to filename ston pinaka me ta filenames */
		files[i].assign(line2);

		/* paragoume to onoma toy neou arxeiou poy tha prokypsei kai to prosthetoume ston pinaka */
		files2[i]=produce_name(files[i]);

		/* afksanoume ton metrhth arxeiwn me arthra kata 1 */
		i++;
	}

	/* periexei to filename toy arxeiou pou tha epeksergastoume amesws meta */
	char arxeio[MAX_NUMBER_OF_FILES][MAX_FILENAME];

	/* periexei to filename toy neou arxeiou pou tha dhmiourghsoume amesws meta */
	char neo_arxeio[MAX_NUMBER_OF_FILES][MAX_FILENAME];

	printf("The articles will now be parsed...\n\n");

	bool title_flag=false;

	string title;

	/* gia ola ta arxeia me arthra */
	for(int j=0;j<i-1;j++)
	{
        /*vazoume sthn arxeio[j] to filename pou tha epeksergastoume */
		strcpy_s(arxeio[j],files[j].c_str());

		/*vazoume sth neo_arxeio[j] to filename pou tha dhmiourghsoume */
		strcpy_s(neo_arxeio[j],files2[j].c_str());

		printf("Now parsing %s...    (%d out of %d)\n",arxeio[j],j+1,i-1);

		/* anoigoume to arxeio pros epeksergasia */
		ifstream infile(arxeio[j]);

        ifstream infile2(arxeio[j]);

		/* to anoigma tou arxeiou apetyxe */
		if(!infile)
		{
			cout << "Opening of file \""<<arxeio[j]<<"\" failed.\n";
			_getch();
			exit(1);
		}

		/* leei pote diavazoume seira pou periexei keimeno pou mas endiaferei */
		bool flag=false;

		/* metavlhth pou xrhsimopoieitai sta regular expressions */
		cmatch what;

		/* metavlhth counter pou xrhsimopoieitai gia na katagrafetai to index tou
		   kathe arthrou sto neo arxeio */
		int counter=1;

        /*arxikopoioyme ton metrhth */
		document_counter=0;

		int** RemainingWords = NULL;

		/* mexri to telos toy arxeioy */
		while ( infile )
		{
			infile.getline(line2,150); //diavazoume mia seira tou arxeiou
			line.assign(line2);        //thn pername se string

             /* an exei teleiwsei to meros me to kyriws keimeno pou mas endiaferei*/
			if((regex_match(line2, what, expression1))||(regex_match(line2, what, expression2)))
			{
				/* de tha epeksergasoume keimeno wspou na vroume pali
				   keimeno pou mas endiaferei dhl na ginei to flag true */
				flag=false;

                /*an entopisame thn arxh enos arthrou */
				if(regex_match(line2, what, expression1))

					document_counter++;//afksanoume ton metrhth twn arthrwn kata 1

				/*kanoume ta flags twn leksewn pou exoume sth lista ac true etsi wste
				  an vrethoun kai se afto to arthro na afkshthei o arithmos arthrwn pou
				  emfanizontai kata 1 */
				ac.turn_flags_on();

			  /* pame kateftheian sthn epomenh ektelesh toy loop */
				continue;
			}

			/* entopisame thn arxh keimenou pou mas endiaferei
			  dhladh seira me keimeno .W */
			if(regex_match(line2, what, expression3))
			{
				/*kanoume to flag true etsi wste oi epomenes seires na
				 epeksergastoun */
				flag=true;

				/* pame kateftheian sthn epomenh ektelesh toy loop */
				continue;
			}

			/* an prokeitai gia keimeno pou mas endiaferei */
			if(flag==true)
			{
				string::size_type begIdx, endIdx;

				//search beginning of the first word
				begIdx = line.find_first_not_of(delims);

				//while beginning of a word found
				while (begIdx != string::npos)
				{
					//search end of the actual word
					endIdx = line.find_first_of (delims, begIdx);
					if (endIdx == string::npos)
					{
						//end of word is end of line
						endIdx = line.length();
					}

					//kanoume lower to case ths lekshs etsi wste to The kai to the na metroun ws h idia leksh
					temp=line.substr(begIdx,endIdx-begIdx);
					transform (temp.begin(), temp.end(),    //source
					temp.begin(),             //destination
					tolower);

					if( (! (find_if(temp.begin(),temp.end(), nondigit())==temp.end() ) ) && (swl.IsStopWord(temp)==false) )
						ac.add(temp);  //prosthetoume th leksh sth lista


					//search beginning of the next word
					begIdx = line.find_first_not_of (delims, endIdx);

				}
			}
		}
		ac.print_out(&rw,document_counter);  //vazoume sth lista rw tis lekseis pou theloume

		c.MakeArray(document_counter,rw.RemainingWordsReturnCount());
		c.InitializeArray(document_counter,rw.RemainingWordsReturnCount());
		c.MakeWordsArray(rw);

		ac.EmptyList();         //adeiazoume th lista me tis lekseis gia to epomeno arxeio


		flag=false;

		while ( infile2 )
		{
			/* diavazoume mia seira tou arxeiou */
			infile2.getline(line2,150);

            /* thn pername se string */
			line.assign(line2);



            /* an exei teleiwsei to meros me to kyriws keimeno pou mas endiaferei*/
			if((regex_match(line2, what, expression1))||(regex_match(line2, what, expression2)))
			{
				/* an proerxomaste apo anagnwsh keimenou poy mas endiaferei
				   aftos o elegxos ginetai gia thn prwth fora pou trexei to while
				   tote o elegxos regex einai true alla h lista c einai adeia
				   opote den prepei na grafei tipota sto arxeio
				   */

				if(flag==true)
				{
					/* ftiaxnoume to neo arxeio mono me tis lekseis pou theloume
					   an den yparxei hdh.Alliws to epekteinoume me tis lekseis
					   tou arthrou pou molis epeksergasthkame */

					c.print_out(neo_arxeio[j],counter,title,document_counter);

					/* adeiazoume th lista me tis lekseis gia to epomeno arthro */
					c.EmptyList();

					/* afksanoume to metrhth gia to inde tou arthrou */
					counter++;
				}

				/* kanoume to flag false etsi wste na mhn ginei askoph epeksergasia
				   keimenou pou de mas endiaferei opws p.x. tvn titlwn twn arthrwn
			   */
				flag=false;

				/* pame kateftheian sthn epomenh ektelesh toy loop */
				continue;
			}

			/* entopisame thn arxh keimenou pou mas endiaferei
			  dhladh seira me keimeno .W */
			if(regex_match(line2, what, expression3))
			{
				/*kanoume to flag true etsi wste oi epomenes seires na
				 epeksergastoun */
				flag=true;

				/* pame kateftheian sthn epomenh ektelesh toy loop */
				continue;
			}
			if(regex_match(line2, what, expression4))
			{
				title_flag=true;
				title="";
				continue;
			}
			if(regex_match(line2, what, expression5))
			{
				title_flag=false;
			}
			if(title_flag==true)
			{
				title.append(" ");
				title.append(line2);
				continue;
			}
			/* an prokeitai gia keimeno pou mas endiaferei */
			if(flag==true)
			{
				string::size_type begIdx, endIdx;

				//search beginning of the first word
				begIdx = line.find_first_not_of(delims);

				//while beginning of a word found
				while (begIdx != string::npos)
				{
					//search end of the actual word
					endIdx = line.find_first_of (delims, begIdx);
					if (endIdx == string::npos)
					{
						//end of word is end of line
						endIdx = line.length();
					}

					//kanoume lower to case tis lekshs etsi wste to The kai to the na metroun ws h idia leksh
					temp=line.substr(begIdx,endIdx-begIdx);
					transform (temp.begin(), temp.end(),    //source
					temp.begin(),             //destination
					tolower);

					/* an den prokeitai gia stop word h arithmo */
					if( (! (find_if(temp.begin(),temp.end(), nondigit())==temp.end() ) ) && (rw.IsReamainingWord(temp,&app_count)) )
						c.add(temp,app_count);  //prosthetoume th leksh sth lista

					//search beginning of the next word
					begIdx = line.find_first_not_of (delims, endIdx);
				}
			}
		}

		/* grafoume sto arxeio kai tis lekseis toy teleftaiou arthrou toy
		   kathe arxeiou */
		c.print_out(neo_arxeio[j],counter,title,document_counter);

        c.WriteTable(neo_arxeio[j],rw.RemainingWordsReturnCount(),document_counter);

	     c.DestroyArray(rw.RemainingWordsReturnCount(),document_counter);

		/* adeiazoume th lista me tis lekseis gia to epomeno arxeio */
		c.EmptyList();

		/* adeiazoume th lista me tis lekseis gia to epomeno arxeio */
		rw.EmptyList();

		printf("Finished parsing %s\n\n",arxeio[j]);

		/* kanoume reset ton counter */
		counter=1;
	}
	printf("Parsing of articles completed");
	printf("\n\nPress an key to exit...");
	_getch();
}

string produce_name(string x)
{
	string filename, basename, extname, tmpname;

	/* to filename tou arxikou arxeioy p.x. MED.ALL */
	filename = x;

	//search period in file name
	string::size_type idx = filename.find_last_of('.');

	/* split file name into base name and extension
	* - base name contains all characters before the period
	* - extension contains all characters after the period
	*/
	basename = filename.substr(0, idx);
	extname = filename.substr(idx+1);

	/* produce the new filename */
	basename+="2";
	tmpname=basename+"."+extname;

	//return the new filename
	return tmpname;
}


void run( )
{
    /* trexoume to filelist.exe gia na ftiaksoume mia lista apo ta arthra */
	system("directory_listing");

	using namespace System;
	using namespace System::IO;

    /* periexei to current directory se char[] */
	char DirectoryChar[_MAX_PATH];

	/* periexei to current directory se String* */
	String* DirectoryString;

	/* periexei to subdirectory se String*
	   Ekei tha mpoun ta arthra me tis lekseis pou theloume
	*/
	String* SubDirectoryString;

	/* periexei to subdirectory se char[]
	   Ekei tha mpoun ta arthra me tis lekseis pou theloume
	*/
	char SubDirectoryChar[_MAX_PATH];

	/* pairnoume to current directory */
	returnCurrentDirectory(DirectoryChar);

	/* dhmioyrgoume to subdirectory articles */
	strcpy_s(SubDirectoryChar,DirectoryChar);

	strcat_s(SubDirectoryChar,"\\articles");

	DirectoryString=convertToString(DirectoryChar);

	SubDirectoryString=convertToString(SubDirectoryChar);

	try
	{
		/* An to directory articles den yparxei */
		if (!Directory::Exists(SubDirectoryString))
		{
			/* To dhmiourgoume */
			Directory::CreateDirectory(SubDirectoryString);
		}
		/* An yparxei */
		else
		{
			/* To diagrafoume */
			Directory::Delete(SubDirectoryString, true);

			/* kai to ksanadhmiourgoume */
			Directory::CreateDirectory(SubDirectoryString);

			/* afto ginetai giati alliws se kathe treksimo
			   toy programmatos tha nea dedomena tha prostithento
			   sto telos toy hdh yparxontos arxeiou
			   pragma pou den epithymoume */
		}
	}
	catch (Exception* e)
	{
	}
}