Beispiel #1
0
int main(){
    int opt, m;
    int **uu, **ii, **interests, *uid;
    float* eig;
    int i, j;

    while(1){
        printf(MENU);
        scanf("%d", &opt);

        switch(opt){
            case 0: 
                exit(EXIT_SUCCESS);
            case 1: 
                m = from_file(&uu, &ii, &interests, &uid); 
                eig_cent(&eig, uu, m);
                place_ad(eig, uid, m, num_ads());
                break;
            case 2: 
                m = build_graph(&uu, &ii, &interests, &uid); 
                eig_cent(&eig, uu, m);
                place_ad(eig, uid, m, num_ads());
                break;
            default: printf("Invalid Menu Option\n");
        }
    }

    return 0;
}
Beispiel #2
0
int main(int ac, char **av)
{
    if (ac != 3)
    {
        ft_perror("Error:        usage ./grab <word> <file>");
        return (1);
    }
    from_file(av[2], av[1]);
}
Beispiel #3
0
bool load_page (void *upage)
{
	void *vpn = (uint32_t) upage & (uint32_t) SP_ADDR;
	struct spage_entry *se = find_entry (vpn);
	if (se == NULL)
		return false;

	switch (se->type){
		case 0: //lazy load (from file system)
			return from_file (se);
		case 1: //swap
//			return from_swap (se);
		case 2: //mmap
			return from_file (se);
		default :
			return false;
	}

}
Beispiel #4
0
int tan_parseoptionst::doit()
{
  register_languages();

  if(check_and_set_options()) return TAN_UNKNOWN;
  if(from_file(cmdline.args[0])) return TAN_UNKNOWN;  
  if(prepare()) return TAN_UNKNOWN;
  
  return analyze();  
}
Beispiel #5
0
int main()
{
	setlocale(LC_CTYPE, "");

	from_file();
	Dict::build_dict();

	std::cout << "words total:" << Dict::words.size() << std::endl;

	Dict::find_path("муха", "слон");

	//for (auto& r : Dict::result)
	//	Dict::dump(r);

	system("pause");
}
Beispiel #6
0
static int
get_user_file(const ntlm_name target_name,
	      char **username, struct ntlm_buf *key)
{
    const char *fn;

    if (issuid())
	return ENOENT;

    fn = getenv("NTLM_USER_FILE");
    if (fn == NULL)
	return ENOENT;
    if (from_file(fn, target_name->domain, username, key) == 0)
	return 0;

    return ENOENT;
}
//Takes a .db file from DB folder and puts it into Main memory
void Database::open(string table_name) {
	ifstream myFile;
	string filename = FILEPATH +table_name+".db"; 
	myFile.open(filename);
	
	if(!myFile) {
		throw runtime_error("Error: unable to open file!\n");
	}
	else {
		//Get first line containing attributes
		vector<Attribute> attributes1;
		vector<Record> records;
		get_attributes_from_file(myFile, attributes1);
		//Get records
		get_records_from_file(myFile,records,attributes1.size());

		Table from_file(table_name,attributes1,records);
		
		this->tables.push_back(from_file);
	}
}
Beispiel #8
0
bool
FileSystem::rename( string from, string to )
{
    win32::Utf8ToFilename from_file(from);
    win32::Utf8ToFilename to_file(to);

    if (!from_file.IsUTF16Valid() || !to_file.IsUTF16Valid())
    {
        return true;
    }

    if (!::MoveFileExW( from_file, to_file,
                        MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH ) )
    {
        log.errorf("%s: MoveFileExW(%s,%s) failed (%d)",__FUNCTION__,from_file.utf8.c_str(),to_file.utf8.c_str(),
                   GetLastError());
        return true;
    }

    return false;
}
void run_copy(apr_pool_t *pool,
              const char *from_file_path, const char *to_file_path)
{
    volatile double start_time;
    volatile double end_time;
    apr_mmap_t *from_file_map;
    const char *from_file_data;
    apr_size_t write_size;
    apr_size_t remain_size;

    show_test_name("copy");

    File from_file(pool, from_file_path);
    from_file.open(APR_READ|APR_BINARY);
    from_file_map = from_file.mmap();

    File to_file(pool, to_file_path);
    to_file.open(APR_CREATE|APR_TRUNCATE|APR_READ|APR_WRITE|APR_BINARY);
    MmapFileWriter to_file_writer(pool, to_file.get_handle());

    remain_size = static_cast<apr_size_t>(from_file.get_size()); // 4G の壁
    from_file_data = AS_CONST_CHAR(from_file_map->mm);
    start_time = get_usage_sec();
    while (remain_size > 0) {
        write_size = (remain_size > BUFFER_SIZE) ? BUFFER_SIZE : remain_size;

        to_file_writer.write(from_file_data, write_size);

        from_file_data += write_size;
        remain_size -= write_size;
    }
    to_file_writer.close();
    end_time = get_usage_sec();

    if (diff(pool, from_file_path, to_file_path) != 0) {
        THROW(MESSAGE_FILE_DIFFER);
    }

    show_item("copy", (end_time - start_time)*1000, " msec");
}
Beispiel #10
0
static int
get_user_file(const ntlm_name target_name,
	      char **domainp, char **usernamep, struct ntlm_buf *key)
{
    const char *domain;
    const char *fn;

    *domainp = NULL;

    if (issuid())
	return ENOENT;

    domain = target_name != NULL ? target_name->domain : NULL;

    fn = getenv("NTLM_USER_FILE");
    if (fn == NULL)
	return ENOENT;
    if (from_file(fn, domain, domainp, usernamep, key) == 0)
	return 0;

    return ENOENT;
}
Beispiel #11
0
 ///
 /// \return A new instance based on the specified file.
 ///
 /// \throw jade::error Thrown if there is an error parsing the tree.
 ///
 inline static basic_newick_node * from_file(
         const std::string & path) ///< The path to the file to decode.
 {
     return from_file(path.c_str());
 }
Beispiel #12
0
exif_data::exif_data(const std::string& filename)
{
    reset();
    from_file(filename);
}
    /** Runs the precision/recall test.
     * May log errors and even end the application in case of severe error.
     * @param params The program options.
     */
    void eval_precision_recall( const program_options& params) {

        LOG(info) << "Loading class membership mappings...";
        Vec1UInt membership_mappings;
        Vec1str cluster_files;
    
        exit_if_false( from_file( params.membership_mappings_file, membership_mappings), RETURN_CODE::IO_ERROR);
        exit_if_false( from_file( params.cluster_file_paths_file,  cluster_files),       RETURN_CODE::IO_ERROR);

        const uint n_features = static_cast<uint>(membership_mappings.size());
        const uint n_clusters = static_cast<uint>(cluster_files.size());

        LOG(info) << "# features: " << n_features;
        LOG(info) << "# clusters: " << n_clusters;


        LOG( info) << "calculating precision / recall ...";

        // find best class for each cluster
        vector<cluster_info_t> class_mapping;

        for( uint i=0; i<n_clusters; ++i) {

            Vec1str current_cluster_image_paths;
            Vec1str current_cluster_real_image_classes;
            std::map<string, uint> class_votes;
            from_file( cluster_files[i], current_cluster_image_paths);
        

            for( auto it=current_cluster_image_paths.begin(); it!=current_cluster_image_paths.end(); ++it) {
            
                const string class_name = bfs::path(*it).parent_path().filename().string();

                current_cluster_real_image_classes.push_back( class_name); 

                const auto map_it = class_votes.find( class_name);
                if( map_it == class_votes.end())
                    class_votes[class_name] = 1;
                else
                    map_it->second += 1;
            }
            
            const auto max_it = std::max_element( class_votes.begin(), 
                                                  class_votes.end(), 
                                                  []( const std::pair<string, int>& p, const std::pair<string, int>& q) { 
                                                      return p.second < q.second; 
                                                  });
            
            if( max_it == class_votes.end()) {
                // ***cluster empty *** (yes, that can happen!)
                continue;
            }

            const string assigned_class( max_it->first);

            const uint n_retrieved_images( static_cast<uint>(current_cluster_image_paths.size()));
            uint false_positives(0);
            uint true_positives(0);
            uint false_negatives(0);

            // find true positives, false positives
            for( auto it=current_cluster_real_image_classes.begin(); it!=current_cluster_real_image_classes.end(); ++it) {
                const string& real_class = *it;
                if( assigned_class.compare( real_class) == 0) {
                    ++true_positives;
                } else {
                    ++false_positives;
                }
            }
            // false negatives
            std::stringstream folder_name;
            folder_name << params.image_db_directory << '/' << assigned_class;
            bfs::path folder_path( folder_name.str());
            assert( bfs::exists( folder_path) && "the directory must exist.");

        
            uint n_relevant_images(0);
            for( bfs::directory_iterator it(folder_path); it!=bfs::directory_iterator(); ++it) {
                bfs::path p(*it);
                p.make_preferred();
                
                if( !p.has_extension() || !is_image_filetype_supported( p.extension().string()))
                    continue;

                ++n_relevant_images;
            
                Vec1str::iterator pos = std::find( current_cluster_image_paths.begin(), current_cluster_image_paths.end(), p.string());
                if( pos == current_cluster_image_paths.end())
                    ++false_negatives;
            }
            assert( true_positives + false_negatives == n_relevant_images && "number of relevant images must be identical to the number of true positivies and false positives");

            // *** found true positivies, false positives, false negatives for cluster i ***
            // calc precision/recall for each class
            const real precision = static_cast<real>(true_positives) / n_retrieved_images;
            const real recall    = static_cast<real>(true_positives) / n_relevant_images;

            class_mapping.push_back( cluster_info_t( assigned_class, true_positives, false_positives, false_negatives, precision, recall));
        }

        real avg_true_positives(0);
        real avg_false_positives(0);
        real avg_false_negatives(0);
        real avg_precision(0);
        real avg_recall(0);

        LOG( info) << "<class name> <true positives> <false positives> <false negatives> <precision> <recall>";
        for( uint i=0; i<class_mapping.size(); ++i) {
            const cluster_info_t& ci = class_mapping[i];
            const string& cluster_name   = std::get<0>(ci);
            const uint true_positives    = std::get<1>(ci);
            const uint false_positives   = std::get<2>(ci);
            const uint false_negatives   = std::get<3>(ci);
            const real precision         = std::get<4>(ci);
            const real recall            = std::get<5>(ci);

            avg_true_positives  += true_positives;
            avg_false_positives += false_positives;
            avg_false_negatives += false_negatives;
            avg_precision       += precision;
            avg_recall          += recall;

            LOG(info) << cluster_name << " " << true_positives << " " << false_positives << " " << false_negatives << " " << precision << " " << recall;
        }

        avg_true_positives  /= class_mapping.size();
        avg_false_positives /= class_mapping.size();
        avg_false_negatives /= class_mapping.size();
        avg_precision       /= class_mapping.size();
        avg_recall          /= class_mapping.size();

        LOG(info) << "Average: <true positives> <false positives> <false negatives> <precision> <recall>";
        LOG(info) << avg_true_positives << " " << avg_false_positives << " " << avg_false_negatives << " " << avg_precision << " " << avg_recall;


        LOG(info) << "Writing stats to file \"" << params.precision_recall_file << "\"...";
        to_file( params.precision_recall_file, class_mapping);

    }
Beispiel #14
0
int main(int argc, char **argv)
{
	long int N, i, j, count, test, factorial;
	double value;
	int block_length, Lmax, index;


	block_cont block;
	perm_counter permutations;
	perm_Reverse reversed;
	block_cont::iterator beginning;
	std::stringstream perm_string;
	std::string temp, perm;

	std::ifstream from_file("fractures.txt");

	std::getline(from_file, temp);
	N = atoi(temp.c_str());
	std::getline(from_file, temp);
	double * strengths;

	Lmax = 1;
	factorial = 2;
	test = 1000;
	while (test > 10)
	{
		Lmax++;
		factorial = factorial*(Lmax+1);
		test = N/(factorial);
	}
	strengths = new double[N];
	for (i=0; i < N; i++)
	{
		std::getline(from_file, temp, '\t');
		strengths[i] = atof(temp.c_str());
		std::getline(from_file, temp);
	}

	from_file.close();

	std::ofstream toFile("perm_Entropy.txt", std::ios::trunc);
	toFile.close();
	for (block_length=2; block_length<=Lmax; block_length++)
	{
		permutations.clear();
		for(i=0; i<N-block_length+1; i++)
		{
			index =0;
			for(j=i; j<i+block_length; j++)
			{
				value = strengths[j];
				block.insert(std:: make_pair(value, index));
				index++;
			}
			perm_string.str(std::string());
			while (!block.empty())
			{
				beginning = block.begin();
				perm_string << beginning->second << ',';
				block.erase(beginning);
			}

			perm = perm_string.str();
			if (permutations.count(perm) > 0)
			{
				permutations[perm] +=1;
			}
			else
			{
				permutations.insert(std::make_pair(perm, 1));
			};
		}
		std::ofstream toFile("perm_Entropy.txt", std::ios::app);
		while (!permutations.empty())
		{
			perm = permutations.begin()->first;
			count = permutations.begin()->second;
			reversed.insert(std::make_pair(count, perm));
			permutations.erase(perm);
		}
		while (!reversed.empty())
		{
			perm = reversed.begin()->second;
			count = reversed.begin()->first;
			toFile << perm << "\t" << count << "\n";
			reversed.erase(reversed.begin());
		}
		std::cout << block_length << " complete\n";
		toFile.close();
	}

	delete[] strengths;

	return 0;
}
Beispiel #15
0
double* randorg()
{
  return from_file("/home/miha/Prejeto/RandomNumbers");
}
Beispiel #16
0
double* devrandom()
{
  return from_file("/dev/random");
}
void menu_enter(){

    ///\fn void menu_enter()
    ///\brief Selectarea optiunii.
    ///
    ///Implementarea selectarii dorite in cadrul unei optiunilor din menu.


    system("cls");
    // se ia fiecare caz de meniu si fiecare caz de element de meniu in parte.

    switch(current_menu){
        // main menu
        case 0 : {
            switch (highlighted_item){
                case 0 : {//input one word
                    one_word();
                    break;
                }
                case 1 : {//From file
                    from_file();
                    break;
                }
                case 2 : {//Live
                    live_input();
                    break;
                }
                case 3 : {//options-menu
                    current_menu = 1;
                    highlighted_item = 0;
                    break;
                }
                case 4 : {//Exit
                    printf("\n\n\tGood bye!");
                    Sleep(750);
                    exit(0);
                    break;
                }
            }
            break;
        }

        //options-menu
        case 1 : {
            switch (highlighted_item){
                case 0 : {//Update words apparitions
                    update_app_words();
                    break;
                }
                case 1 : {//Insert an word to dictionary
                    insert_word();
                    break;
                }
                case 2 : {//Delete an word from dictionary
                    delete_word();
                    break;
                }
                case 3 : {//Reset dictionary
                    reset_dict();
                    break;
                }
                case 4 : {//Build dictionary from file
                    build_dict();
                    break;
                }
                case 5 : {//Add words to dictionary from file
                    update_words();
                    break;
                }
                case 6 : {//select_suggestions_funcition
                    current_menu = 2;
                    highlighted_item = sugg_funct;
                    break;
                }
                case 7 : {//back
                    current_menu = 0;
                    highlighted_item = 0;
                    break;
                }
            }
            break;
        }

        //select suggestion functions
        case 2 : {
            switch (highlighted_item){
                case 0 : {//leven
                    sugg_funct = 0;
                    break;
                }
                case 1 : {//leven 2.0
                    sugg_funct = 1;
                    break;
                }
                case 2 : {//back
                    current_menu = 1;
                    highlighted_item = 0;
                    break;
                }
            }
        }
    }
    print_menu();
    Sleep(50);
}
Beispiel #18
0
	static shader from_file(shader_type type, std::string const & source) {
		return from_file(type, source.data());
	}