WIP
[evolve-layout.git] / C / ngrams.cpp
blob53a6bd96bb35526ac6b2654fc327e8f70ea6078b
1 #pragma once
3 #include <iostream>
4 #include <fstream>
5 #include <sstream>
7 #include <map>
8 #include <string>
10 struct NGram: public std::map<std::string, long> {
11 NGram(const std::string &file) {
12 std::ifstream f(file.c_str());
14 long frequency;
15 for(std::string gram; f >> frequency;) {
16 f.get(); // drop one space
17 getline(f, gram); // get rest of line
19 this->insert(make_pair(gram, frequency));
22 f.close();
27 /*int main(int argc, char **argv) {
28 // check options
29 if(argc < 2) {
30 cerr << "Usage: " << argv[0] << " <filename>" << endl;
31 return 1;
34 NGram ngrams(argv[1]);
36 for(NGram::const_iterator it = ngrams.begin();
37 it != ngrams.end(); ++it) {
38 cout << it->first << " " << it->second << endl;
41 return 0;
42 }*/