Ejemplo n.º 1
0
void model::read(const string &filename, vector<string> &input_words, vector<string> &output_words)
{
    ifstream file(filename.c_str());
    if (!file) throw runtime_error("Could not open file " + filename);
    
    param myParam;
    string line;
    
    while (getline(file, line))
    {
	if (line == "\\config")
	{
	    readConfig(file);
	}

	else if (line == "\\vocab")
	{
	    input_words.clear();
	    readWordsFile(file, input_words);
	    output_words = input_words;
	}

	else if (line == "\\input_vocab")
	{
	    input_words.clear();
	    readWordsFile(file, input_words);
	}

	else if (line == "\\output_vocab")
	{
	    output_words.clear();
	    readWordsFile(file, output_words);
	}

	else if (line == "\\input_embeddings")
	    input_layer.read(file);
	else if (line == "\\hidden_weights 1")
	    first_hidden_linear.read(file);
	else if (line == "\\hidden_weights 2")
	    second_hidden_linear.read(file);
	else if (line == "\\output_weights")
	    output_layer.read_weights(file);
	else if (line == "\\output_biases")
	    output_layer.read_biases(file);
	else if (line == "\\end")
	    break;
	else if (line == "")
	    continue;
	else
	{
	    cerr << "warning: unrecognized section: " << line << endl;
	    // skip over section
	    while (getline(file, line) && line != "") { }
	}
    }
    file.close();
}
Ejemplo n.º 2
0
  void readWordsFile(const string &file, vector<string> &word_list)
  {
    cerr << "Reading word list from: " << file<< endl;

    ifstream TRAININ;
    TRAININ.open(file.c_str());
    if (! TRAININ)
      {
	cerr << "Error: can't read word list from file " << file<< endl;
	exit(-1);
      }

    readWordsFile(TRAININ, word_list);
    TRAININ.close();
  }
/*it takes main arguments */
int main(int argc, char **argv)
{
	/* 1. 2. argumanalr duzgun ve bos olmamali */
	/* calistirilabilir dosya ile file name arasinda . */
	if ((argv[1] == NULL) || argc!=2)
	{
		printf("Yanlis Kullanim\n");
		printf("Dogru yazim sekli\n");
		printf(" ./hw05 directory\n");
	    	return(-1);
	}
	totalReadFile = mmap(NULL, sizeof *totalReadFile, PROT_READ | PROT_WRITE, 
                    MAP_SHARED | MAP_ANONYMOUS, -1, 0);

	unlink("tempLog.txt");
	unlink(FILENAMEFILE);
	
	clock_t start;
    double duration;

    start = clock();
	/* Printing Console al information about program*/
	countWords(argv[1]);/**/
	readFileNamesTempFile();
	//printf("total read file %d\n",*totalReadFile);
	
	int i=0,temp=0,status=0,fdx;
	int err;
	if (sem_init(&sem, 0,1) != 0)/*semapohew init */
    {
        printf("\n semaphore failed\n");
        return 1;
    }

	for(i=0;i<*totalReadFile;i++){
            intThread_count++;/* Thread sayisini tutar. */
			if (pthread_create(&thread_id[i],NULL, threadOperation, &fileNames[i])!=0)
				fprintf(stderr, "Failed to create thread: %s\n", strerror(err));

			
	}
	for(i=0;i<*totalReadFile;i++)
	{
		
		if (err = pthread_join(thread_id[i], NULL))
		    {
				fprintf(stderr, "Failed to join thread: %s\n", strerror(err));
				return 1;
			}
			

			
	}
	/*semaphore destroyed*/
	sem_destroy(&sem);

	
			
	printf("Total  words                          = %d\n",totalWords);
	printf("Total Threads       	              = %d\n",intThread_count+1);
	printf("Total File which is search            = %d\n",totalFile);
	printf("Total Directory  in given directory   = %d\n",totalDirectory);
	
	char **words;
	int *wordsCount;
	words = Make2DintArray(totalWords,BUFSIZE);
	wordsCount=(int *) malloc(sizeof(int)*(totalWords));
	int size = readWordsFile(words,wordsCount);
	addLogFile(words,wordsCount,size);

	unlink("tempLog.txt");
	unlink(FILENAMEFILE);

	printf("\nTotal Union Words Num                = %d\n",size);
	freeArray(words,totalWords);
	free(wordsCount);
	duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
	printf("Total Duration time is                = %f\n",duration);
	
	return 0;
}