Esempio n. 1
0
static void processDir(HttpQueue *q)
{
    HttpConn        *conn;
    HttpTx          *tx;
    HttpRx          *rx;
    MprList         *list;
    MprDirEntry     *dp;
    Dir             *dir;
    uint            nameSize;
    int             next;

    conn = q->conn;
    rx = conn->rx;
    tx = conn->tx;
    dir = conn->data;

    mprLog(5, "processDir");
    mprAssert(tx->filename);

    httpSetHeaderString(conn, "Cache-Control", "no-cache");
    httpSetHeaderString(conn, "Last-Modified", conn->http->currentDate);
    parseQuery(conn);

    list = mprGetPathFiles(tx->filename, 1);
    if (list == 0) {
        httpWrite(q, "<h2>Can't get file list</h2>\r\n");
        outputFooter(q);
        return;
    }
    if (dir->pattern) {
        filterDirList(conn, list);
    }
    sortList(conn, list);

    /*
        Get max filename
     */
    nameSize = 0;
    for (next = 0; (dp = mprGetNextItem(list, &next)) != 0; ) {
        nameSize = max((int) strlen(dp->name), nameSize);
    }
    nameSize = max(nameSize, 22);

    outputHeader(q, rx->pathInfo, nameSize);
    for (next = 0; (dp = mprGetNextItem(list, &next)) != 0; ) {
        outputLine(q, dp, tx->filename, nameSize);
    }
    outputFooter(q);
    httpFinalize(conn);
}
Esempio n. 2
0
// Output the set to a file as a .ppm, if none is listed output to default file name
void MandelSet::outputFilePPM(std::string file){
  if (file == "NO_FILE_NAME"){
    f.open(fileName + ".ppm");
  }
  else {
    f.open(file + ".ppm");
  }

  if (f.is_open()){
    outputHeader();

    for (RGBColor temp : pixelData){
      f << temp.red << " " << temp.blue << " " << temp.green << "  ";
    }
    f.close();
  }
  else {
    std::cout << "WARNING : file write failure for MandelSet object:" << this << std::endl;
  } 
}
Esempio n. 3
0
void WekaClassifier::saveAsOutput(const std::string &filename) const {
  // convert to DT
  std::string tempfile = tempFilename();
  outputDescriptionToFile(tempfile);
  int numInitialLinesToRemove = 3;
  std::ifstream in(tempfile.c_str());
  std::ofstream out(filename.c_str());
  std::string line;
  std::getline(in,line);
  outputHeader(out);
  out << std::endl;
  while (in.good()) {
    if (numInitialLinesToRemove > 0)
      numInitialLinesToRemove--;
    else
      out << line << std::endl;
    std::getline(in,line);
  }
  in.close();
  out.close();
  remove(tempfile.c_str());
}
void
GenerateForm
	(
	istream&			input,
	const JString&		formName,
	const JString&		tagName,
	const JString&		enclName,
	const JString&		codePath,
	const JString&		stringPath,
	const JString&		codeSuffix,
	const JString&		headerSuffix,
	JPtrArray<JString>*	backupList
	)
{
	const JString codeFileName    = codePath + formName + codeSuffix;
	const JString codeFileBakName = codeFileName + kBackupSuffix;

	const JString headerFileName    = codePath + formName + headerSuffix;
	const JString headerFileBakName = headerFileName + kBackupSuffix;

	if (!JFileExists(codeFileName))
		{
		cerr << codeFileName << " not found" << endl;
		return;
		}
	if (!JFileExists(headerFileName))
		{
		cerr << headerFileName << " not found" << endl;
		return;
		}

	cout << "Generating: " << formName << ", " << tagName << endl;

	const JBoolean shouldBackup = ShouldBackupForm(formName, backupList);

	// copy code file contents before start delimiter

	JString tempCodeFileName;
	JError err = JCreateTempFile(codePath, NULL, &tempCodeFileName);
	if (!err.OK())
		{
		cerr << "Unable to create temporary file in " << codePath << endl;
		cerr << "  (" << err.GetMessage() << ')' << endl;
		return;
		}

	ifstream origCode(codeFileName);
	ofstream outputCode(tempCodeFileName);
	if (!outputCode.good())
		{
		cerr << "Unable to open temporary file in " << codePath << endl;
		remove(tempCodeFileName);
		return;
		}
	if (!CopyBeforeCodeDelimiter(tagName, origCode, outputCode))
		{
		cerr << "No starting delimiter in " << codeFileName << endl;
		outputCode.close();
		remove(tempCodeFileName);
		return;
		}

	// generate code for each object in the form

	JPtrArray<JString> objTypes(JPtrArrayT::kDeleteAll),
					   objNames(JPtrArrayT::kDeleteAll);
	GenerateCode(input, outputCode, stringPath, formName, tagName, enclName,
				 &objTypes, &objNames);

	// copy code file contents after end delimiter

	JBoolean done = CopyAfterCodeDelimiter(tagName, origCode, outputCode);
	origCode.close();
	outputCode.close();

	if (!done)
		{
		cerr << "No ending delimiter in " << codeFileName << endl;
		remove(tempCodeFileName);
		return;
		}
	else if (shouldBackup && rename(codeFileName, codeFileBakName) != 0)
		{
		cerr << "Unable to rename original " << codeFileName << endl;
		remove(tempCodeFileName);
		return;
		}
	JEditVCS(codeFileName);
	rename(tempCodeFileName, codeFileName);

	// copy header file contents before start delimiter

	JString tempHeaderFileName;
	err = JCreateTempFile(codePath, NULL, &tempHeaderFileName);
	if (!err.OK())
		{
		cerr << "Unable to create temporary file in " << codePath << endl;
		cerr << "  (" << err.GetMessage() << ')' << endl;
		return;
		}

	ifstream origHeader(headerFileName);
	ofstream outputHeader(tempHeaderFileName);
	if (!outputHeader.good())
		{
		cerr << "Unable to open temporary file in " << codePath << endl;
		remove(tempHeaderFileName);
		return;
		}
	if (!CopyBeforeCodeDelimiter(tagName, origHeader, outputHeader))
		{
		cerr << "No starting delimiter in " << headerFileName << endl;
		outputHeader.close();
		remove(tempHeaderFileName);
		return;
		}

	// generate instance variable for each object in the form

	GenerateHeader(outputHeader, objTypes, objNames);

	// copy header file contents after end delimiter

	done = CopyAfterCodeDelimiter(tagName, origHeader, outputHeader);
	origHeader.close();
	outputHeader.close();

	if (!done)
		{
		cerr << "No ending delimiter in " << headerFileName << endl;
		remove(tempHeaderFileName);
		return;
		}

	// check if header file actually changed

	JString origHeaderText, newHeaderText;
	JReadFile(headerFileName, &origHeaderText);
	JReadFile(tempHeaderFileName, &newHeaderText);
	if (newHeaderText != origHeaderText)
		{
		if (shouldBackup && rename(headerFileName, headerFileBakName) != 0)
			{
			cerr << "Unable to rename original " << headerFileName << endl;
			remove(tempHeaderFileName);
			return;
			}
		JEditVCS(headerFileName);
		rename(tempHeaderFileName, headerFileName);
		}
	else
		{
		remove(tempHeaderFileName);
		}
}
Esempio n. 5
0
	void VJCascadeClassifier::run(const string& dataFileName, const string& shypFileName, 
								   int numIterations, const string& outResFileName )
	{
		// loading data
		InputData* pData = loadInputData(dataFileName, shypFileName);
		const int numOfExamples = pData->getNumExamples();
				
		//get the index of positive label		
		const NameMap& namemap = pData->getClassMap();
		_positiveLabelIndex = namemap.getIdxFromName( _positiveLabelName );				
		
		if (_verbose > 0)
			cout << "Loading strong hypothesis..." << flush;
		
		
		
		// The class that loads the weak hypotheses
		UnSerialization us;
		
		// Where to put the weak hypotheses
		vector<vector<BaseLearner*> > weakHypotheses;
		
		// For stagewise thresholds 
		vector<AlphaReal> thresholds(0);
        
		// loads them
		//us.loadHypotheses(shypFileName, weakHypotheses, pData);
		us.loadCascadeHypotheses(shypFileName, weakHypotheses, thresholds, pData);
		

		// store result
		vector<CascadeOutputInformation> cascadeData(0);
		vector<CascadeOutputInformation>::iterator it;
		
		cascadeData.resize(numOfExamples);		
		for( it=cascadeData.begin(); it != cascadeData.end(); ++it )
		{
			it->active=true;
		}										
		
		if (!_outputInfoFile.empty())
		{
			outputHeader();
		}
		
		for(int stagei=0; stagei < weakHypotheses.size(); ++stagei )
		{
			// for posteriors
			vector<AlphaReal> posteriors(0);		
			
			// calculate the posteriors after stage
			VJCascadeLearner::calculatePosteriors( pData, weakHypotheses[stagei], posteriors, _positiveLabelIndex );			
			
			// update the data (posteriors, active element index etc.)
			updateCascadeData(pData, weakHypotheses, stagei, posteriors, thresholds, _positiveLabelIndex, cascadeData);
			
			if (!_outputInfoFile.empty())
			{
				_output << stagei + 1 << "\t";
				_output << weakHypotheses[stagei].size() << "\t";
				outputCascadeResult( pData, cascadeData );
			}
			
			int numberOfActiveInstance = 0;
			for( int i = 0; i < numOfExamples; ++i )
				if (cascadeData[i].active) numberOfActiveInstance++;
			
			if (_verbose > 0 )
				cout << "Number of active instances: " << numberOfActiveInstance << "(" << numOfExamples << ")" << endl;									
		}
				
		vector<vector<int> > confMatrix(2);
		confMatrix[0].resize(2);
		fill( confMatrix[0].begin(), confMatrix[0].end(), 0 );
		confMatrix[1].resize(2);
		fill( confMatrix[1].begin(), confMatrix[1].end(), 0 );
		
	    // print accuracy
		for(int i=0; i<numOfExamples; ++i )
		{		
			vector<Label>& labels = pData->getLabels(i);
			if (labels[_positiveLabelIndex].y>0) // pos label				
				if (cascadeData[i].forecast==1)
					confMatrix[1][1]++;
				else
					confMatrix[1][0]++;
			else // negative label
				if (cascadeData[i].forecast==0)
					confMatrix[0][0]++;
				else
					confMatrix[0][1]++;
		}			
		
		double acc = 100.0 * (confMatrix[0][0] + confMatrix[1][1]) / ((double) numOfExamples);
		// output it
		cout << endl;
		cout << "Error Summary" << endl;
		cout << "=============" << endl;
		
		cout << "Accuracy: " << setprecision(4) << acc << endl;
		cout << setw(10) << "\t" << setw(10) << namemap.getNameFromIdx(1-_positiveLabelIndex) << setw(10) << namemap.getNameFromIdx(_positiveLabelIndex) << endl;
		cout << setw(10) << namemap.getNameFromIdx(1-_positiveLabelIndex) << setw(10) << confMatrix[0][0] << setw(10) << confMatrix[0][1] << endl;
		cout << setw(10) << namemap.getNameFromIdx(_positiveLabelIndex) << setw(10) << confMatrix[1][0] << setw(10) << confMatrix[1][1] << endl;		
		
		// output forecast 
		if (!outResFileName.empty() ) outputForecast(pData, outResFileName, cascadeData );
						
		// free memory allocation
		vector<vector<BaseLearner*> >::iterator bvIt;
		for( bvIt = weakHypotheses.begin(); bvIt != weakHypotheses.end(); ++bvIt )
		{
			vector<BaseLearner* >::iterator bIt;
			for( bIt = (*bvIt).begin(); bIt != (*bvIt).end(); ++bIt )
				delete *bIt;
		}
	}
Esempio n. 6
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QCommandLineParser cmdline;
    cmdline.setApplicationDescription("C++ type placeholder generator.");
    cmdline.addHelpOption();

    QCommandLineOption inputHeader("i",
        QCoreApplication::translate("main", "Input header file name."),
        QCoreApplication::translate("main", "file name"));
    cmdline.addOption(inputHeader);

    QCommandLineOption dependencyInclude("d",
        QCoreApplication::translate("main", "Header included for depencencies."),
        QCoreApplication::translate("main", "file name"));
    cmdline.addOption(dependencyInclude);

    QCommandLineOption buildInclude("b",
        QCoreApplication::translate("main", "Header included for build."),
        QCoreApplication::translate("main", "file name[,file,...]"));
    cmdline.addOption(buildInclude);

    QCommandLineOption className("c",
        QCoreApplication::translate("main", "Input class name."),
        QCoreApplication::translate("main", "class name"));
    cmdline.addOption(className);

    QCommandLineOption outputSource("source",
        QCoreApplication::translate("main", "Output source file name."),
        QCoreApplication::translate("main", "file name"));
    cmdline.addOption(outputSource);

    QCommandLineOption outputHeader("header",
        QCoreApplication::translate("main", "Output header file name."),
        QCoreApplication::translate("main", "file name"));
    cmdline.addOption(outputHeader);

    QCommandLineOption outputClass("class",
        QCoreApplication::translate("main", "Output class name."),
        QCoreApplication::translate("main", "class name"));
    cmdline.addOption(outputClass);

    cmdline.process(a.arguments());

    bool requiredGiven = true;
    if (!cmdline.isSet(inputHeader)) {
        requiredGiven = false;
        qWarning() << "Input header name must be given.";
    }
    if (!cmdline.isSet(className)) {
        requiredGiven = false;
        qWarning() << "Input class name must be given.";
    }
    if (!cmdline.isSet(outputSource)) {
        requiredGiven = false;
        qWarning() << "Output source file name must be given.";
    }
    if (!cmdline.isSet(outputHeader)) {
        requiredGiven = false;
        qWarning() << "Output header file name must be given.";
    }
    if (!cmdline.isSet(outputClass)) {
        requiredGiven = false;
        qWarning() << "Output class name must be given.";
    }
    if (!requiredGiven)
        return 5;

    QStringList listIn;
    QStringList listOut;

    listIn << "Q_OBJECT";
    listOut << "Q_OBJECT;";
    listIn << "Q_SLOTS";
    listOut << "slots";
    listIn << "Q_SIGNALS";
    listOut << "signals";

    ClassParser parser;
    parser.setPreDefines(listIn, listOut);

    SClassParserMacroBeginForMember sMacroBegin;
    sMacroBegin.m_bRequiresBrackets = true;
    sMacroBegin.m_strMacroBegin = "Q_REVISION";
    parser.add(sMacroBegin);

    QString input = cmdline.value(inputHeader);
    QString inputClassName(cmdline.value(className));
    ClassParserInformation *info = getClassInfo(input, inputClassName, parser);
    if (!info) {
        qWarning() << "No" << inputClassName << "info found in" << input;
        return 3;
    }
    QStringList buildIncludeList, dependencyIncludeList;
    if (cmdline.isSet(buildInclude))
        buildIncludeList = cmdline.value(buildInclude).split(",", QString::SkipEmptyParts);
    if (cmdline.isSet(dependencyInclude))
        dependencyIncludeList = cmdline.value(dependencyInclude).split(",", QString::SkipEmptyParts);
    QStringList header, source;
    QString headerName = cmdline.value(outputHeader);
    QString sourceName = cmdline.value(outputSource);
    QString outputClassName = cmdline.value(outputClass);
    if (!generateFileContents(header, source, inputClassName, outputClassName,
        dependencyIncludeList, buildIncludeList, headerName, *info))
    {
        qWarning() << "Output files not generated.";
        return 4;
    }
    writeToFile(sourceName, source);
    writeToFile(headerName, header);
    return 0;
}
Esempio n. 7
0
// encode用のmain関数
int main(int argc, char *argv[])
{
  char *target_filename = NULL;
  //char output_filename[1024];
  char *output_filename = NULL;
  char *dict_filename = NULL;
  unsigned int codewordlength = 0;
  unsigned int shared_dictsize = 0;
  unsigned int chunk_size = 0;
  unsigned long int block_length = 0;
  unsigned int length;
  char *rest;
  FILE *input, *output, *dictfile;
  DICT *dict;
  EDICT *edict;
  USEDCHARTABLE ut;
  int result;
  unsigned int b;
  unsigned char *buf;
  unsigned int  *buf2 = NULL;
  OBITFS seqout, dicout;
  int header_output = 0;
  uint i;

   /* オプションの解析 */
  while ((result = getopt(argc, argv, "r:w:b:l:d:s:c:")) != -1) {
    switch (result) {
    case 'r':
      target_filename = optarg;
      break;
      
    case 'w':
      output_filename = optarg;
      break;
      
    case 'd':
      dict_filename = optarg;
      break;
      
    case 'b':
      block_length = strtoul(optarg, &rest, 10);
      if (*rest != '\0') {
	help(argv);
      }
      break;

    case 'c':
      chunk_size = strtol(optarg, &rest, 10);
      if (*rest != '\0') {
	help(argv);
      }
      break;

    case 'l':
      codewordlength = strtoul(optarg, &rest, 10);
      if (*rest != '\0') {
	help(argv);
      }
      break;
      
    case 's':
      shared_dictsize = strtoul(optarg, &rest, 10);
      if (*rest != '\0') {
	help(argv);
      }
      break;
      
    case '?':
      help(argv);
      break;
    }
  }

  // 必要なオプションがそろっているかを確認する
  if (!(target_filename && output_filename && dict_filename && block_length && codewordlength && chunk_size)) {
    help(argv);
  }

  if (chunk_size > block_length) {
    fprintf(stderr, "chunk length should not exceed block length.\n");
    exit(1);
  }
  
  // 入力ファイルをオープンする
  input  = fopen(target_filename, "r");
  if (input == NULL) {
    puts("Input file open error at the beginning.");
    exit(1);
  }
  
  // 圧縮データファイルをオープンする
  output = fopen(output_filename, "wb");
  if (output == NULL) {
    puts("Output file open error at the beginning.");
    exit(1);
  }
  
  // 辞書ファイルをオープンする
  dictfile = fopen(dict_filename, "wb");
  if (!dictfile) {
    puts("Dictionary file open error at the beginning.");
    exit(EXIT_FAILURE);
  }

  //  if (NULL == (buf = (unsigned char*)malloc(sizeof(unsigned char) * block_length))) { // || NULL == (buf2 = (unsigned int*)malloc(sizeof(unsigned int) * block_length))) {
  //    puts("malloc fault.");
    //    exit(EXIT_FAILURE);
  //  }

  chartable_init(&ut);
  fill_chartable(input, &ut);
  fseeko(input, 0, SEEK_END);
  dict = createDict(ftello(input));
  fseeko(input, 0, SEEK_SET);
  b = 0;
  obitfs_init(&seqout, output);
  obitfs_init(&dicout, dictfile);
  if (shared_dictsize < ut.size) shared_dictsize = ut.size;
  printf("Generating CFG..."); fflush(stdout);
  outputHeader(&dicout, dict, (unsigned int) codewordlength, (unsigned int) block_length, &ut);

  dict = RunRepair(dict, input, block_length, shared_dictsize, codewordlength, &ut, chunk_size, 1);
  if (!dict) exit(1);
  edict = convertDict(dict, &ut);
  outputSharedDictionary(&dicout, edict, &ut, codewordlength, shared_dictsize, b);
  CleanEDict(edict);
  if (dict->num_rules < shared_dictsize + CHAR_SIZE - ut.size) shared_dictsize = dict->num_rules + ut.size - CHAR_SIZE;

  fseeko(input, 0, SEEK_SET);
  while (!feof(input)) {
    //    printf("************ Block #%d ************\n", b);
    //    length = fread(buf, sizeof(unsigned char), block_length, input);
    //    if (!length) break;
    //    for (i = 0; i < length; i++) {
    //      buf2[i] = buf[i];
    //    }
    /* for (unsigned int i = 0; i < length; i++) { */
    /*   printf("%u ", buf2[i]); */
    /* } */
    /* puts(""); */
    dict = RunRepair(dict, input, block_length, shared_dictsize, codewordlength, &ut, chunk_size, 0);
    edict = convertDict(dict, &ut);
    outputLocalDictionary(&dicout, edict, &ut, codewordlength, shared_dictsize, b);
    EncodeCFG(edict, &seqout, codewordlength);
    CleanEDict(edict);
    b++;
  }

  printf("Finished!\n"); fflush(stdout);
  if (dict) {
    free(dict->rule);
    free(dict->comp_seq);
    free(dict);
  }
  obitfs_finalize(&seqout);
  obitfs_finalize(&dicout);
  fclose(input);
  fclose(output);
  fclose(dictfile);
  exit(0);
}
Esempio n. 8
0
void WekaClassifier::outputDescription(std::ostream &out) const {
  outputHeader(out);
  out << std::endl;
  comm->sendWait('p');
}