void NeuralPatternArray::read(TextFileReader const& _file) throw()
{
	TextFileReader file = _file;
	
	Text text = file.readLine();
	
	if(text.contains("NeuralPatternArray:v1"))
	{
		//printf("is valid NeuralPatternArray file\n");
		
		while(file.isEof() == false)
		{
			NeuralPattern pat;
			pat.read(file);
			
			if((pat.getNumInputs() > 0) && (pat.getNumOutputs() > 0))
			{
				//printf("..adding a pattern..\n");
				
				this->add(pat);
			}
		}
	}

}
Beispiel #2
0
void App::RenderOwner()
{
    static char s_message[1024];
    static bool s_dealtWith = false;

    if( !s_dealtWith )
    {
        // First try to read data/world-encode.dat
        // If it is present open it, encode it into world.dat, then delete it
        TextFileReader *encode = new TextFileReader( "data/world-encode.txt" );
        if( encode->IsOpen() )
        {
            encode->ReadLine();
            char *encodeMe = encode->GetRestOfLine();
            TextFileWriter encodeTo( "data/world.dat", true );
            encodeTo.printf( "%s\n", encodeMe );
        }
        delete encode;
        DeleteThisFile( "data/world-encode.txt" );


        // Now open the encoded world.dat file
        // Decrypt the contents for printing onto the screen
        TextFileReader reader( "data/world.dat" );
        AppAssert( reader.IsOpen() );
        reader.ReadLine();
        char *line = reader.GetRestOfLine();
        sprintf( s_message, "%s", line );
        char *nextLine = strchr( s_message, '\n' );
        if( nextLine ) *nextLine = '\x0';
        //strupr( s_message );

        s_dealtWith = true;
    }

    g_renderer->Text( 10, g_windowManager->WindowH() - 20, Colour(255,50,50,255), 20, s_message );
}
int main(int argc, char* argv[]) {

	string s = argv[0];
	cout << s << endl;
	int removeIndex = s.rfind("/");
	s = s.erase(removeIndex);
	s = s + "../src/dictionary";

	Project3CommandParser cp(argc, argv);

	// Begin loading the Dictionary.
	cout << "Loading Dictionary..." << endl;
	TextFileReader fileReader;
	string dictionaryFilePath = cp.getSingleValueByName(
			Project3CommandParser::FLAG_DICTIONARY);
	if (dictionaryFilePath.compare("") != 0) {
		fileReader.addFile(dictionaryFilePath);
	} else {
	  cout << "Please load a dictoinary file" << endl;
	  // fileReader.addFile(s);
	}
	vector<string> splitWords;
	fileReader.getSplitBySpace(splitWords);
	Global_Web_Data::addWordsToDictionary(splitWords);
	cout << "Dictionary loaded." << endl;
	// End loading the Dictionary.

	//domain to start crawling
	domain = cp.getSingleValueByName(Project3CommandParser::FLAG_DOMAIN);

	// start page/url.
	startPage = argv[1];

	//thread count
	threadCount =
			atoi(
					cp.getSingleValueByName(Project3CommandParser::FLAG_THREADS).c_str());
	if (threadCount > 8) {
		threadCount = 8;
	}
	if (threadCount < 1) {
		threadCount = 1;
	}

	//count of top misspelled words
	missSpelled = atoi(cp.getSingleValueByName(Project3CommandParser::FLAG_MISS).c_str());
	//	if (missSpelled > 100) {
	//	missSpelled = 100;
	//	}
	if (missSpelled < 1) {
		missSpelled = 100;
	}

	//histogram word count
	topWords = atoi(cp.getSingleValueByName(Project3CommandParser::FLAG_COUNT).c_str());
	//	if (topWords > 100) {
	//		topWords = 100;
	//	}
	if (topWords < 1) {
		topWords = 100;
	}

	//Begin load Robots.txt
	stringstream domainConcat;

	if (domain.size() == 0) {
		//if no domain is provided we only crawl the given page
		Global_Web_Data::setMaxDepth(1);
		domainConcat << startPage;
	} else {
		URL *tempU = new URL(startPage);
		domainConcat << tempU->getDomain();
		delete tempU;
	}

	domainConcat << "/robots.txt";
	cout << "Loading [" << domainConcat.str() << "]..." << endl;
	URL *robotsURL = new URL(domainConcat.str());
	webpage *robotsPage = new webpage(robotsURL, 1);
	Robots_txt *robots = new Robots_txt(robotsURL->getDomain(),
			robotsPage->openPage(*robotsURL));
	Global_Web_Data::addRobots_txt(robots);
	delete robotsPage;
	cout << "[" << domainConcat.str() << "] loaded." << endl;
	//End load Robots.txt

	//Begin initialize the webpage queue.
	URL *firstURL = new URL(startPage);
	webpage *firstPage = new webpage(firstURL, 1);
	Global_Web_Data::enqueueWebPage(firstPage);
	//End initialize the webpage queue.

	//Start worker threads.
	cout << "Starting worker threads..." << endl;
	WebCrawler crawler(threadCount);
	crawler.crawl();
	cout << "Crawling  " + startPage + "..." << endl;
	//End worker threads.

	//Register exit function(s):
	atexit(produceOutput);

	cout
			<< "Enter 0 (zero) then press Enter key to exit program early, "
			<< "or wait for program to exit automatically after finishing crawling."
			<< "\n";
	int i = 1;
	while (i != 0) {
		cin >> i;
	}

	return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	Configuration *configuration = new Configuration(CONFIG_FILE_NAME);

	GameEngine gameEngine(
		new WindowsConsoleLogger(), 
		new CoreSystem(
			new TextFileReader()), 
		new OGLGraphicsSystem(
			new OGLShaderManager(), 
			new GameWorld(
				new GameObjectManager(),
				new OGLFirstPersonCamera()),
			new OGLViewingFrustum(),
			new LocalLightSource()
			),
		new GameWindow(
			configuration->getTitle(),
			configuration->getWidth(), 
			configuration->getHeight()),
		new PCInputSystem(),
		new WindowsTimer()
		);

	OGLGraphicsSystem *graphics = (OGLGraphicsSystem*)gameEngine.getGraphicsSystem();
	TextFileReader *reader = gameEngine.getCoreSystem()->getTextFileReader();

	graphics->addVertexShader(
		"SimpleVertexShader", 
		new OGLVertexShader());
	graphics->addVertexShader(
		"VertexShader3d", 
		new OGLVertexShader(), 
		reader->readContents("VertexShader3DPerspective.glsl"));
	graphics->addVertexShader(
		"VertexShaderIllumination",
		new OGLVertexShader(),
		reader->readContents("VertexShader3DIllumination.glsl"));
	graphics->addFragmentShader(
		"SimpleFragmentShader", 
		new OGLFragmentShader());
	graphics->addFragmentShader(
		"FragmentShaderIllumination",
		new OGLFragmentShader(),
		reader->readContents("FragmentShader3DIllumination.glsl"));

	graphics->addShaderProgram(
		"SimpleShader", 
		new OGLShaderProgram(), 
		"SimpleVertexShader", "SimpleFragmentShader");
	graphics->addShaderProgram(
		"ShaderProgram3d", 
		new OGLShaderProgram(), 
		"VertexShader3d", "SimpleFragmentShader");
	graphics->addShaderProgram(
		"ShaderProgramIllumination",
		new OGLShaderProgram(),
		"VertexShaderIllumination", "FragmentShaderIllumination");

	gameEngine.initializeWindowAndGraphics();

	StockObjectLoader loader;
	loader.loadObjects(graphics->getGameWorld()->getObjectManager());

	graphics->setActiveShaderProgram("ShaderProgramIllumination");
	graphics->setObjectsShaderProgram("ShaderProgramIllumination");
	

	//OGLSphericalCamera *camera = (OGLSphericalCamera *)graphics->getGameWorld()->getCamera();
	//camera->setPosition(25.0f, -30.0f, 30.0f);
	OGLFirstPersonCamera *camera = (OGLFirstPersonCamera *)graphics->getGameWorld()->getCamera();
	camera->setPosition(0.0f, 5.0f, 10.0f);
	


	graphics->setUpViewingEnvironment();

	gameEngine.setupGame();
	gameEngine.run();

	return 0;
}
void NeuralPattern::read(TextFileReader const& _file) throw()
{
	TextFileReader file = _file;
	
	Text text;
	int line = 0;
	int numInputs = -1, numOutputs = -1;
		
	NumericalArray<float> inputVector;
	NumericalArray<float> outputVector;
	
	while((text = file.readLine()).size() != 0)
	{
		if(line == 0)
		{
			// should be the format/version string
			if(text.contains("NeuralPatternSimple:v1") == false)
			{
				printf("NeuralPattern::read wrong version type\n");
				return;
			}
		}
		else if(numInputs < 0)
		{
			// should be the number of inputs			
			sscanf(text.getArray(), "Inputs:%d", &numInputs);
			
			if(numInputs < 1) 
			{
				printf("NeuralPattern::read invalid number of inputs\n");
				return;
			}
			
			//printf("ins: %d\n", numInputs);
			
			inputVector = NumericalArray<float>::withSize(numInputs);
		}
		else if(numInputs > 0)
		{
			int index;
			float value;
			sscanf(text.getArray(), "%d %f", &index, &value);
			numInputs--;
			
			//printf("in[%3d] = %f\n", index, value);
			
			inputVector[index] = value;
		}
		else if(numOutputs < 0)
		{
			// should be the number of outputs			
			sscanf(text.getArray(), "Outputs:%d", &numOutputs);
			
			if(numOutputs < 1) 
			{
				printf("NeuralPattern::read invalid number of numOutputs\n");
				return;
			}
			
			//printf("outs: %d\n", numOutputs);
			
			outputVector = NumericalArray<float>::withSize(numOutputs);
		}
		else if(numOutputs > 0)
		{
			int index;
			float value;
			sscanf(text.getArray(), "%d %f", &index, &value);
			numOutputs--;
			
			//printf("out[%3d] = %f\n", index, value);
			
			outputVector[index] = value;
		}
		
		if((numInputs == 0) && (numOutputs == 0))
		{
			//printf("CREATING PATTERN\n");
			setInternal(new NeuralPatternSimpleInternal(inputVector, outputVector));
			return;
		}
		
		line++;
	}		
}
void NeuralNetwork::read(TextFileReader const& _file) throw()
{
	TextFileReader file = _file;
	
	Text text;
	int line = 0;
	int numLayers = -1;
	float learnRate, actFuncOffset;
	
	IntArray nodes;
	
	while(file.isEof() == false)
	{
		text = file.readLine();
		
		if(line == 0)
		{
			// should be the format/version string
			if(text.contains("NeuralNetworkSimple:v1") == false)
			{
				printf("NeuralNetwork::read wrong version type\n");
				return;
			}
		}
		else if(line == 1)
		{
			// should be learn rate and act func offset			
			sscanf(text.getArray(), "learnRate: %f actFuncOffset: %f", &learnRate, &actFuncOffset);
		}
		else if(line == 2)
		{
			// should be the number of layers			
			sscanf(text.getArray(), "Layers:%d", &numLayers);
			
			if(numLayers < 2) 
			{
				printf("NeuralNetwork::read invalid number of layers\n");
				return;
			}
			
			nodes = IntArray::withSize(numLayers, false);
		}
		else if(numLayers > 0)
		{
			int layer, numNodes;
			sscanf(text.getArray(), "Layer %d:%d", &layer, &numNodes);
			numLayers--;
			
			nodes[layer] = numNodes;
			
			if(numLayers == 0)
			{				
				if(nodes == getStructure())
				{
					setLearnRate(learnRate);
					setActFuncOffset(actFuncOffset);
				}
				else
				{
					setInternal(new NeuralNetworkSimpleInternal(nodes, learnRate, actFuncOffset));
				}
			}
		}
		else
		{
			// it's a weight or a threshold
			int layer, node, index;
			float value;
			sscanf(text.getArray(), "%d %d %d %f", &layer, &node, &index, &value);
			
			if(index < 0)
				setThreshold(layer, node, value);
			else
				setWeight(layer, node, index, value);
		}
		
		line++;
	}		
}