コード例 #1
0
ファイル: JobFactory.cpp プロジェクト: airguider/OpenStudio
  Job JobFactory::createEnergyPlusJob(
      ToolInfo t_energyPlusTool,
      const openstudio::path &t_idd,
      const openstudio::path &t_idf,
      const openstudio::path &t_epw,
      const openstudio::path &t_outdir,
      const boost::optional<openstudio::UUID> &t_uuid)
  {
    JobParams params;
    params.append("outdir", toString(t_outdir));

    Tools tools;
    t_energyPlusTool.name = "energyplus";
    tools.append(t_energyPlusTool);

    Files files;
    FileInfo idf(t_idf, "idf");

    if (!t_idd.empty())
    {
      idf.addRequiredFile(t_idd,toPath("Energy+.idd"));
    }

    idf.addRequiredFile(t_epw, toPath("in.epw"));
    files.append(idf);

    return createEnergyPlusJob(tools, params, files, std::vector<openstudio::URLSearchPath>(), t_uuid);
  }
コード例 #2
0
ファイル: tfidf.cpp プロジェクト: takayuk/basset
float Tfidf::eval(const string& word, const string& dockey) {

  const float tfval = tf(word, dockey);
  const float idfval = idf(word);

  return tfval * idfval;
}
コード例 #3
0
ファイル: JobFactory.cpp プロジェクト: airguider/OpenStudio
  Job JobFactory::createEnergyPlusJob(
      const openstudio::runmanager::Tools &t_tools,
      const openstudio::path &t_idd,
      const openstudio::path &t_idf,
      const openstudio::path &t_epw,
      const openstudio::path &t_outdir,
      const boost::optional<openstudio::UUID> &t_uuid)
  {
    JobParams params;
    params.append("outdir", toString(t_outdir));

    Files files;
    FileInfo idf(t_idf, "idf");

    if (!t_idd.empty())
    {
      idf.addRequiredFile(t_idd,toPath("Energy+.idd"));
    }

    if (boost::filesystem::is_directory(t_epw))
    {
      params.append("epwdir", toString(t_epw));
    } else {
      idf.addRequiredFile(t_epw, toPath("in.epw"));
    }

    files.append(idf);

    return createEnergyPlusJob(t_tools, params, files, std::vector<openstudio::URLSearchPath>(), t_uuid);
  }
コード例 #4
0
ファイル: test-next.c プロジェクト: JabirTech/Source
int
main(int argc, char *argv[])
{
	static const int ex_under = FE_UNDERFLOW | FE_INEXACT;	/* shorthand */
	static const int ex_over = FE_OVERFLOW | FE_INEXACT;
	long double ldbl_small, ldbl_eps, ldbl_max;

	printf("1..5\n");

#ifdef	__i386__
	fpsetprec(FP_PE);
#endif
	/*
	 * We can't use a compile-time constant here because gcc on
	 * FreeBSD/i386 assumes long doubles are truncated to the
	 * double format.
	 */
	ldbl_small = ldexpl(1.0, LDBL_MIN_EXP - LDBL_MANT_DIG);
	ldbl_eps = LDBL_EPSILON;
	ldbl_max = ldexpl(1.0 - ldbl_eps / 2, LDBL_MAX_EXP);

	/*
	 * Special cases involving zeroes.
	 */
#define	ztest(prec)							      \
	test##prec(copysign##prec(1.0, nextafter##prec(0.0, -0.0)), -1.0, 0); \
	test##prec(copysign##prec(1.0, nextafter##prec(-0.0, 0.0)), 1.0, 0);  \
	test##prec(copysign##prec(1.0, nexttoward##prec(0.0, -0.0)), -1.0, 0);\
	test##prec(copysign##prec(1.0, nexttoward##prec(-0.0, 0.0)), 1.0, 0)

	ztest();
	ztest(f);
	ztest(l);
#undef	ztest

#define	stest(next, eps, prec)					\
	test##prec(next(-0.0, 42.0), eps, ex_under);		\
	test##prec(next(0.0, -42.0), -eps, ex_under);		\
	test##prec(next(0.0, INFINITY), eps, ex_under);		\
	test##prec(next(-0.0, -INFINITY), -eps, ex_under)

	stest(nextafter, 0x1p-1074, );
	stest(nextafterf, 0x1p-149f, f);
	stest(nextafterl, ldbl_small, l);
	stest(nexttoward, 0x1p-1074, );
	stest(nexttowardf, 0x1p-149f, f);
	stest(nexttowardl, ldbl_small, l);
#undef	stest

	printf("ok 1 - next\n");

	/*
	 * `x == y' and NaN tests
	 */
	testall(42.0, 42.0, 42.0, 0);
	testall(-42.0, -42.0, -42.0, 0);
	testall(INFINITY, INFINITY, INFINITY, 0);
	testall(-INFINITY, -INFINITY, -INFINITY, 0);
	testall(NAN, 42.0, NAN, 0);
	testall(42.0, NAN, NAN, 0);
	testall(NAN, NAN, NAN, 0);

	printf("ok 2 - next\n");

	/*
	 * Tests where x is an ordinary normalized number
	 */
	testboth(1.0, 2.0, 1.0 + DBL_EPSILON, 0, );
	testboth(1.0, -INFINITY, 1.0 - DBL_EPSILON/2, 0, );
	testboth(1.0, 2.0, 1.0 + FLT_EPSILON, 0, f);
	testboth(1.0, -INFINITY, 1.0 - FLT_EPSILON/2, 0, f);
	testboth(1.0, 2.0, 1.0 + ldbl_eps, 0, l);
	testboth(1.0, -INFINITY, 1.0 - ldbl_eps/2, 0, l);

	testboth(-1.0, 2.0, -1.0 + DBL_EPSILON/2, 0, );
	testboth(-1.0, -INFINITY, -1.0 - DBL_EPSILON, 0, );
	testboth(-1.0, 2.0, -1.0 + FLT_EPSILON/2, 0, f);
	testboth(-1.0, -INFINITY, -1.0 - FLT_EPSILON, 0, f);
	testboth(-1.0, 2.0, -1.0 + ldbl_eps/2, 0, l);
	testboth(-1.0, -INFINITY, -1.0 - ldbl_eps, 0, l);

	/* Cases where nextafter(...) != nexttoward(...) */
	test(nexttoward(1.0, 1.0 + ldbl_eps), 1.0 + DBL_EPSILON, 0);
	testf(nexttowardf(1.0, 1.0 + ldbl_eps), 1.0 + FLT_EPSILON, 0);
	testl(nexttowardl(1.0, 1.0 + ldbl_eps), 1.0 + ldbl_eps, 0);

	printf("ok 3 - next\n");

	/*
	 * Tests at word boundaries, normalization boundaries, etc.
	 */
	testboth(0x1.87654ffffffffp+0, INFINITY, 0x1.87655p+0, 0, );
	testboth(0x1.87655p+0, -INFINITY, 0x1.87654ffffffffp+0, 0, );
	testboth(0x1.fffffffffffffp+0, INFINITY, 0x1p1, 0, );
	testboth(0x1p1, -INFINITY, 0x1.fffffffffffffp+0, 0, );
	testboth(0x0.fffffffffffffp-1022, INFINITY, 0x1p-1022, 0, );
	testboth(0x1p-1022, -INFINITY, 0x0.fffffffffffffp-1022, ex_under, );

	testboth(0x1.fffffep0f, INFINITY, 0x1p1, 0, f);
	testboth(0x1p1, -INFINITY, 0x1.fffffep0f, 0, f);
	testboth(0x0.fffffep-126f, INFINITY, 0x1p-126f, 0, f);
	testboth(0x1p-126f, -INFINITY, 0x0.fffffep-126f, ex_under, f);

#if LDBL_MANT_DIG == 53
	testboth(0x1.87654ffffffffp+0L, INFINITY, 0x1.87655p+0L, 0, l);
	testboth(0x1.87655p+0L, -INFINITY, 0x1.87654ffffffffp+0L, 0, l);
	testboth(0x1.fffffffffffffp+0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffp+0L, 0, l);
	testboth(0x0.fffffffffffffp-1022L, INFINITY, 0x1p-1022L, 0, l);
	testboth(0x1p-1022L, -INFINITY, 0x0.fffffffffffffp-1022L, ex_under, l);
#elif LDBL_MANT_DIG == 64 && !defined(__i386)
	testboth(0x1.87654321fffffffep+0L, INFINITY, 0x1.87654322p+0L, 0, l);
	testboth(0x1.87654322p+0L, -INFINITY, 0x1.87654321fffffffep+0L, 0, l);
	testboth(0x1.fffffffffffffffep0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffffep0L, 0, l);
	testboth(0x0.fffffffffffffffep-16382L, INFINITY, 0x1p-16382L, 0, l);
	testboth(0x1p-16382L, -INFINITY,
	    0x0.fffffffffffffffep-16382L, ex_under, l);
#elif LDBL_MANT_DIG == 113
	testboth(0x1.876543210987ffffffffffffffffp+0L, INFINITY,
	    0x1.876543210988p+0, 0, l);
	testboth(0x1.876543210988p+0L, -INFINITY,
	    0x1.876543210987ffffffffffffffffp+0L, 0, l);
	testboth(0x1.ffffffffffffffffffffffffffffp0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.ffffffffffffffffffffffffffffp0L, 0, l);
	testboth(0x0.ffffffffffffffffffffffffffffp-16382L, INFINITY,
	    0x1p-16382L, 0, l);
	testboth(0x1p-16382L, -INFINITY,
	    0x0.ffffffffffffffffffffffffffffp-16382L, ex_under, l);
#endif

	printf("ok 4 - next\n");

	/*
	 * Overflow tests
	 */
	test(idd(nextafter(DBL_MAX, INFINITY)), INFINITY, ex_over);
	test(idd(nextafter(INFINITY, 0.0)), DBL_MAX, 0);
	test(idd(nexttoward(DBL_MAX, DBL_MAX * 2.0L)), INFINITY, ex_over);
#if LDBL_MANT_DIG > 53
	test(idd(nexttoward(INFINITY, DBL_MAX * 2.0L)), DBL_MAX, 0);
#endif

	testf(idf(nextafterf(FLT_MAX, INFINITY)), INFINITY, ex_over);
	testf(idf(nextafterf(INFINITY, 0.0)), FLT_MAX, 0);
	testf(idf(nexttowardf(FLT_MAX, FLT_MAX * 2.0)), INFINITY, ex_over);
	testf(idf(nexttowardf(INFINITY, FLT_MAX * 2.0)), FLT_MAX, 0);

	testboth(ldbl_max, INFINITY, INFINITY, ex_over, l);
	testboth(INFINITY, 0.0, ldbl_max, 0, l);

	printf("ok 5 - next\n");

	return (0);
}
コード例 #5
0
ファイル: ns.hpp プロジェクト: LANTZT/feelpp
void
NavierStokes::run()
{
    this->init();

    auto U = Xh->element( "(u,p)" );
    auto V = Xh->element( "(u,q)" );
    auto u = U.element<0>( "u" );
    auto v = V.element<0>( "u" );
    auto p = U.element<1>( "p" );
    auto q = V.element<1>( "p" );
#if defined( FEELPP_USE_LM )
    auto lambda = U.element<2>();
    auto nu = V.element<2>();
#endif
    //# endmarker4 #

    LOG(INFO) << "[dof]         number of dof: " << Xh->nDof() << "\n";
    LOG(INFO) << "[dof]    number of dof/proc: " << Xh->nLocalDof() << "\n";
    LOG(INFO) << "[dof]      number of dof(U): " << Xh->functionSpace<0>()->nDof()  << "\n";
    LOG(INFO) << "[dof] number of dof/proc(U): " << Xh->functionSpace<0>()->nLocalDof()  << "\n";
    LOG(INFO) << "[dof]      number of dof(P): " << Xh->functionSpace<1>()->nDof()  << "\n";
    LOG(INFO) << "[dof] number of dof/proc(P): " << Xh->functionSpace<1>()->nLocalDof()  << "\n";

    LOG(INFO) << "Data Summary:\n";
    LOG(INFO) << "   hsize = " << meshSize << "\n";
    LOG(INFO) << "  export = " << this->vm().count( "export" ) << "\n";
    LOG(INFO) << "      mu = " << mu << "\n";
    LOG(INFO) << " bccoeff = " << penalbc << "\n";




    //# marker5 #
    auto deft = gradt( u )+trans(gradt(u));
    auto def = grad( v )+trans(grad(v));
    //# endmarker5 #

    //# marker6 #
    // total stress tensor (trial)
    auto SigmaNt = -idt( p )*N()+mu*deft*N();

    // total stress tensor (test)
    auto SigmaN = -id( p )*N()+mu*def*N();
    //# endmarker6 #

    auto F = M_backend->newVector( Xh );
    auto D =  M_backend->newMatrix( Xh, Xh );

    // right hand side
    auto ns_rhs = form1( _test=Xh, _vector=F );


    LOG(INFO) << "[navier-stokes] vector local assembly done\n";

    // construction of the BDF
    auto bdfns=bdf(_space=Xh);

    /*
     * Construction of the left hand side
     */

    auto navierstokes = form2( _test=Xh, _trial=Xh, _matrix=D );
    mpi::timer chrono;
    navierstokes += integrate( elements( mesh ), mu*inner( deft,def )+ trans(idt( u ))*id( v )*bdfns->polyDerivCoefficient( 0 ) );
    LOG(INFO) << "mu*inner(deft,def)+(bdf(u),v): " << chrono.elapsed() << "\n";
    chrono.restart();
    navierstokes +=integrate( elements( mesh ), - div( v )*idt( p ) + divt( u )*id( q ) );
    LOG(INFO) << "(u,p): " << chrono.elapsed() << "\n";
    chrono.restart();
#if defined( FEELPP_USE_LM )
    navierstokes +=integrate( elements( mesh ), id( q )*idt( lambda ) + idt( p )*id( nu ) );
    LOG(INFO) << "(lambda,p): " << chrono.elapsed() << "\n";
    chrono.restart();
#endif

    std::for_each( inflow_conditions.begin(), inflow_conditions.end(),
                   [&]( BoundaryCondition const&  bc )
                   {
                       // right hand side
                       ns_rhs += integrate( markedfaces( mesh, bc.marker() ), inner( idf(&bc,BoundaryCondition::operator()),-SigmaN+penalbc*id( v )/hFace() ) );

                       navierstokes +=integrate( boundaryfaces( mesh ), -inner( SigmaNt,id( v ) ) );
                       navierstokes +=integrate( boundaryfaces( mesh ), -inner( SigmaN,idt( u ) ) );
                       navierstokes +=integrate( boundaryfaces( mesh ), +penalbc*inner( idt( u ),id( v ) )/hFace() );
                   });
    std::for_each( wall_conditions.begin(), wall_conditions.end(),
                   [&]( BoundaryCondition const&  bc )
                   {
                       navierstokes +=integrate( boundaryfaces( mesh ), -inner( SigmaNt,id( v ) ) );
                       navierstokes +=integrate( boundaryfaces( mesh ), -inner( SigmaN,idt( u ) ) );
                       navierstokes +=integrate( boundaryfaces( mesh ), +penalbc*inner( idt( u ),id( v ) )/hFace() );
                   });
    std::for_each( outflow_conditions.begin(), outflow_conditions.end(),
                   [&]( BoundaryCondition const&  bc )
                   {
                       ns_rhs += integrate( markedfaces( mesh, bc.marker() ), inner( idf(&bc,BoundaryCondition::operator()),N() ) );
                   });

    LOG(INFO) << "bc: " << chrono.elapsed() << "\n";
    chrono.restart();

    u = vf::project( _space=Xh->functionSpace<0>(), _expr=cst(0.) );
    p = vf::project( _space=Xh->functionSpace<1>(), _expr=cst(0.) );

    M_bdf->initialize( U );

    for( bdfns->start(); bdfns->isFinished(); bdfns->next() )
    {
        // add time dependent terms
        auto bdf_poly = bdfns->polyDeriv();
        form1( _test=Xh, _vector=Ft ) =
            integrate( _range=elements(mesh), _expr=trans(idv( bdf_poly ))*id( v ) );
        // add convective terms
        form1( _test=Xh, _vector=Ft ) +=
            integrate( _range=elements(mesh), _expr=trans(gradv(u)*idv( u ))*id(v) );
        // add contrib from time independent terms
        Ft->add( 1., F );

        // add time stepping terms from BDF to right hand side
        backend()->solve( _matrix=D, _solution=U, _rhs=Ft );

        this->exportResults( bdfns->time(), U );
    }





} // NavierNavierstokes::run
コード例 #6
0
int main(int argc, char **argv){
	std::vector<float> train_local_descriptors;
	std::vector<std::string> train_local_descriptor_files(3);
	train_local_descriptor_files[0] = "imagenes/descriptores_locales/train_car";
	train_local_descriptor_files[1] = "imagenes/descriptores_locales/train_cat";
	train_local_descriptor_files[2] = "imagenes/descriptores_locales/train_bird";

	int count = 0;
	int dimension = 128;
	int max_files = 160;
	int file_counter;

	for (int i = 0; i < 3; ++i){
		/* code */
		std::ifstream infile(train_local_descriptor_files[i]);
		file_counter = 0;
		std::string line;
		std::vector<std::string> vectorAsString;
		while (std::getline(infile, line)){
			if (Utils::stringEndsWith(line, "jpg")){
				file_counter++;
				std::getline(infile, line);
				if(file_counter >= max_files){
					break;
				}
				continue;		
			}
			vectorAsString.clear();
			vectorAsString = Utils::split(line, ',');
			for(int j = 0; j < dimension; j++){
				train_local_descriptors.push_back(std::stof(vectorAsString[j]));
			}
			count++;
		    // process pair (a,b)
		}
		infile.close();
	}

	std::cout << "Read " << train_local_descriptors.size() << " local descriptors from file" << std::endl;

	cv::Mat descriptor_matrix = cv::Mat(count, dimension, CV_32FC1);
	memcpy(descriptor_matrix.data, train_local_descriptors.data(), train_local_descriptors.size()*sizeof(float));

	std::cout << "Starting k-means clustering" << std::endl;

	int nClusters = std::stoi(argv[1]);
	ClusterComputer clusterComputer(nClusters);
	cv::Mat labels;
	cv::Mat centers;
	clusterComputer.compute(descriptor_matrix, labels, centers);
	std::cout << "Cumputed clusters" << std::endl;
	std::cout << "Number of centers: " << centers.rows << std::endl;
	std::cout << "Centers dimension: " << centers.cols << std::endl;



	std::vector<std::string> local_descriptor_files (9);
	// Inicializar
	local_descriptor_files[0] = "imagenes/descriptores_locales/train_car";
	local_descriptor_files[1] = "imagenes/descriptores_locales/train_cat";
	local_descriptor_files[2] = "imagenes/descriptores_locales/train_bird";
	local_descriptor_files[3] = "imagenes/descriptores_locales/test_car";
	local_descriptor_files[4] = "imagenes/descriptores_locales/test_cat";
	local_descriptor_files[5] = "imagenes/descriptores_locales/test_bird";
	local_descriptor_files[7] = "imagenes/descriptores_locales/val_cat";
	local_descriptor_files[6] = "imagenes/descriptores_locales/val_car";
	local_descriptor_files[8] = "imagenes/descriptores_locales/val_bird";


	std::unordered_map<std::string, std::vector<int>> document_word_frequency;
	std::unordered_map<std::string, std::vector<float>> tf;

	std::unordered_map<std::string, int> document_word_counter;
	std::vector<int> word_frequency(nClusters, 0);
	int word_total = 0;
	std::vector<std::vector<std::string>> filenames(9);


	for (int i = 0; i < 9; ++i){
		std::cout << "Aproximating words for  " << local_descriptor_files[i] << std::endl;

		std::ifstream infile(local_descriptor_files[i]);
		
		std::string line;
		std::vector<std::string> vectorAsString;
		std::string currentFile = "";
		// std::cout << "File opened" << std::endl;
		
		while (std::getline(infile, line)){

			// std::cout << "Read line: " << line << std::endl;
			if (Utils::stringEndsWith(line, "jpg")){

				// std::cout << "Line ended with jpg" << std::endl;

				if(currentFile != ""){
				// Finished last file
					// std::cout << "Finished a file" << std::endl;
					for (int j = 0; j < nClusters; ++j){
						if(document_word_frequency[currentFile][j] > 0){
							word_frequency[j]++;
						}
						word_total += document_word_frequency[currentFile][j];
						tf[currentFile][j] = document_word_frequency[currentFile][j] / (float) document_word_counter[currentFile];
						// std::cout << "Updated frequency for last file" << std::endl;
					}
				}
				currentFile = line;
				filenames[i].push_back(currentFile);

				// std::cout << "Pushed filename into vector" << std::endl;
				document_word_frequency[currentFile] = *(new std::vector<int> (nClusters, 0));
				// std::cout << "Created vector for frequency" << std::endl;
				tf[currentFile] = *(new std::vector<float> (nClusters, 0.0));
				// std::cout << "Created vector for tf" << std::endl;
				std::getline(infile, line);
				document_word_counter[currentFile] = std::stoi(line);
				continue;		
			}

			int word = nearestCluster(line, centers);
			document_word_frequency[currentFile][word] = document_word_frequency[currentFile][word]+1;
		}
		for (int j = 0; j < nClusters; ++j){
			if(document_word_frequency[currentFile][j] > 0){
				word_frequency[j]++;
			}
			word_total += document_word_frequency[currentFile][j];
			tf[currentFile][j] = document_word_frequency[currentFile][j] / (float) document_word_counter[currentFile];
		}

	}

	std::cout << "Computing idf values"  << std::endl;

	std::vector<float> idf(nClusters, 0);
	for (int i = 0; i < nClusters; ++i){
		idf[i] = log(word_total / (float) word_frequency[i]);
	}

	std::string output_directory = "imagenes/BOVW_descriptors_" + std::to_string(nClusters) + "/";
	std::vector<std::string> output_filenames(9);
	output_filenames[0] = output_directory + "train_car";
	output_filenames[1] = output_directory + "train_cat";
	output_filenames[2] = output_directory + "train_bird";
	output_filenames[3] = output_directory + "test_car";
	output_filenames[4] = output_directory + "test_cat";
	output_filenames[5] = output_directory + "test_bird";
	output_filenames[6] = output_directory + "val_car";
	output_filenames[7] = output_directory + "val_cat";
	output_filenames[8] = output_directory + "val_bird";

	std::ofstream outputFile;
	std::vector<float> BOVW_descriptor(nClusters, 0.0);
	for (int i = 0; i < 9; ++i){
		std::cout << "Computing BOVW descriptors for " << output_filenames[i] << std::endl;

		outputFile.open(output_filenames[i]);
		int file_size = filenames[i].size();
		for (int j = 0; j < file_size; ++j){
			outputFile << filenames[i][j] << std::endl;
			for (int k = 0; k < nClusters; ++k){
				BOVW_descriptor[k] = tf[filenames[i][j]][k] * idf[k];
			}
			outputFile << Utils::vectorToString(BOVW_descriptor) << std::endl;
		}
		outputFile.close();
	}

}
コード例 #7
0
ファイル: BM25Scorer.cpp プロジェクト: RedSunCMX/izenelib
 float bm25(uint32_t tf, uint32_t df, uint32_t numDocs, uint32_t docLen, float avgDocLen, float K1, float B)
 {
     return bm25tf(tf, docLen, avgDocLen, K1, B) * idf(numDocs, df);
 }
コード例 #8
0
ファイル: project.c プロジェクト: mpouyakh75/finalprojecttest
void main() {
    FILE *cprogram;
    FILE *hfile;
    FILE *prepc;
    char c=1;
    char cfile_name[20];
    char hfile_name[20];
    char prepfile_name[20];
    int  i=0;
    int  k=0;

    char type[20], attr[20];

    token *mT,*firstT;

    firstS = NULL;
    firstT = NULL;
    line= (int *) malloc(sizeof(int));
    *line=1;

    printf("\n\nStarting The Preprocessor \n");

    printf("\nPlease enter the C program file name (full path): ");
    scanf("%s",cfile_name);

    if((cprogram=fopen(cfile_name,"r"))==NULL) return 1;

    while ( (c = fgetc(cprogram)) != EOF )
        {
            if(c =='"')
            {
               break;
            }
        }

        fscanf(cprogram,"%s",hfile_name);

        for(i=0;hfile_name[i]!='\0';i++)
        {
            if(hfile_name[i]=='"')
            {
               hfile_name[i]='\0';
               break;
            }
        }


    for(i=0; cfile_name[i]!='.';i++)
        prepfile_name[i]=cfile_name[i];

    prepfile_name[i]='.'; prepfile_name[i+1]='d'; prepfile_name[i+2]='a'; prepfile_name[i+3]='t';
    prepfile_name[i+4]='\0';

    printf("\nhfilename=%s , prepfilename=%s \n", hfile_name, prepfile_name);

    prepc=fopen(prepfile_name,"w");
     if( prepc == NULL)
        printf("\nWriting to file. The file, pouya.dat, can not be opened");
    else{

       printf("\nThe program after preprocessing: \n");

       if((hfile=fopen(hfile_name,"r"))!= NULL)
       while( !feof(hfile) )
       {
           c=fgetc(hfile);
           printf("%c",c);
           if (c!=-1)
           fputc(c,prepc);
       }

       while( !feof(cprogram) )
       {
           c=fgetc(cprogram);
           printf("%c",c);
           if (c!=-1)
           fputc(c,prepc);
       }

    }
    fclose(cprogram);
    fclose(hfile);
    fclose(prepc);

    printf("\n\nStarting Lexical Analysis: Tokens are written into a linked list and the symbol table is simultaneously created. \n");

    f1=fopen(prepfile_name,"r");
    if (f1==NULL) return 1;

    while ( !getToken(type, attr, line)){
      // printf("\n %s is a %s",attr, type);
       if(firstT==NULL)
       {
            tmpT= (token *) malloc( sizeof(token));
            firstT=tmpT;
            firstT->next=NULL;
            strcpy(firstT->attT,attr);
            strcpy(firstT->typeT,type);
            firstT->lineT= *line;
            printf("-> %s is a %s at line  %d\n",firstT->attT,firstT->typeT,firstT->lineT);
       }
       else
       {
            tmpT= (token *) malloc( sizeof(token));
            mT=firstT;
            while(mT->next!=NULL) mT=mT->next;

            mT->next=tmpT;
            tmpT->next=NULL;
            strcpy(tmpT->attT,attr);
            strcpy(tmpT->typeT,type);
            tmpT->lineT= *line;
            printf("-> %s is a %s at line %d\n",tmpT->attT,tmpT->typeT,tmpT->lineT);
       }

    }

    printf("\n\nStarting Syntax Analysis\n");
    tmpT=firstT;

    while( tmpT )
    {
       if (strcmp("main",tmpT->attT)==0 ) ;
       else if (strcmp("if",tmpT->attT)==0 )   ;
       else if (strcmp("else",tmpT->attT)==0 )  ;
       else if (strcmp("while",tmpT->attT)==0 ) ;
       else if (strcmp("int",tmpT->attT)==0 )   ;
       else if (strcmp("bool",tmpT->attT)==0 )  ;
       else if (strcmp("float",tmpT->attT)==0 ) ;
       else if (strcmp("char",tmpT->attT)==0 )  ;
       else if (strcmp("identifier",tmpT->typeT)==0 ) idf();
       tmpT=tmpT->next;
    }
    printf(" \n symbol table  :   \n");

    symbolT *test;
    test=firstS;
    while(test!=NULL)
    {
           printf(" %d      %s     %s     %f\n ", test->index, test->attrS, test->typeS,test->value);
           test=test->next;

    }

    printf("\n\nStarting Intermediate Representation (IR) Generation\n");
    tmpT=firstT;

    while( tmpT )
    {
 /*      if (strcmp("main",tmpT->attT)==0 ) mainf();
       else if (strcmp("if",tmpT->attT)==0 )   iff();
       else if (strcmp("else",tmpT->attT)==0 )  elsef();
       else if (strcmp("while",tmpT->attT)==0 ) whilef();
       else if (strcmp("int",tmpT->attT)==0 )   intf();
       else if (strcmp("bool",tmpT->attT)==0 )  boolf();
       else if (strcmp("float",tmpT->attT)==0 ) floatf();
       else if (strcmp("char",tmpT->attT)==0 )  charf();
       else*/ if (strcmp("identifier",tmpT->typeT)==0 ) idfIR();
       tmpT=tmpT->next;
    }


   // printf("\nKeywords: %d\nIdentifiers: %d\nOperators: %d\nNumbers: %d\n",kw,id,op,num);
}
コード例 #9
0
double StemmedFileInMemoryParser::tfidf(size_t word, unsigned int docIndex)
{
    return tf(word, docIndex) * idf(word);
}