예제 #1
0
	//在输入vector中找以空白为间隔的单词
	//将单词以及该单词的行的行号一起放入word_map
	void textquery::build_map()
	{
		//处理输入vector中的每一行
		for(line_no line_num = 0;line_num != lines_of_text.size();++line_num)
		{
			//一次读入一个单词
			istringstream line(lines_of_text[line_num]);
			string word;
			while(line>>word)
			{
				//去掉标点
				word = cleanup_str(word);
				//将行号加入到vector容器中
				if(word_map.count(word)==0)//单词不再map容器中
					//小标操作将加入该单词
					word_map[word].push_back(line_num);
				else
				{
					if(line_num != word_map[word].back())
						//行号与vector容器中最后一个元素不相等
						word_map[word].push_back(line_num);
				}
			}
		}
	}
예제 #2
0
std::string redis_getval(std::string file_id, std::string col) {
  reply = (redisReply*)redisCommand(c,"hget %s %s",file_id.c_str(),col.c_str());

  std::string output = "null";
    
  if(reply->len!=0) {
    output = reply->str;
  }

  freeReplyObject(reply);
  return cleanup_str(output);
}
예제 #3
0
//在输入vector中找以空白为间隔的单词
//将单词以及出现该单词的行的行号一起放入word_map
void TextQuery::build_map()
{
	//处理输入vector中的每一行
	for(line_no line_num=0;
		line_num!=lines_of_text.size();
		++line_num)
	{
        //一次读一个单词
		istringstream line(lines_of_text[line_num]);
		string word;
		while(line>>word)
			//将行号加入到set容器中:
		    //若单词不在map容器中,下标操作将加入该单词
		word_map[cleanup_str(word)].insert(line_num);
	}
}
예제 #4
0
파일: fileQuery.cpp 프로젝트: sairre/ITEMS
void input_text(std::ifstream &is)            
{
	std::string text;
	while(getline(is,text))           //fetch each line once until 'is' gets ended
	{
		file.push_back(text);
		int no=file.size()-1;

		//break down  a line into words
		std::istringstream line(text);
		std::string word;
		while(line>>word)
		{
			wordMapNo[cleanup_str(word)].insert(no);
		}

	}
}
예제 #5
0
void TextQuery::build_map()
{
    for(line_no line_num = 0;line_num != lines_of_text.size();line_num++)
    {
        istringstream line(lines_of_text[line_num]);
        string word;
        while(line >> word)
        {
            word=cleanup_str(word);
            if(word_map.count(word)==0)
                word_map[word].push_back(line_num);
            else
            {
                if(line_num != word_map[word].back())
                    word_map[word].push_back(line_num);
            }
        }
    }
}
예제 #6
0
std::string redis_getkey_cols(std::string col) {
  //cout << "fetching col " << col << endl;
  reply = (redisReply*)redisCommand(c,"hkeys %s",col.c_str());
  std::string output = "null";

  if(reply->elements!=0) {
    //cout << "nonzero" << endl << flush;
    output = "";
    for(unsigned i=0; i<reply->elements; i++) {
      if(reply->element[i]) {
        //cout << i << endl << flush;
        output = output + reply->element[i]->str + ":";
      }
    }
  }
  freeReplyObject(reply);
  //cout << "returned " << output << endl;
  return cleanup_str(output);
}
예제 #7
0
        // *TN* have to make empty vector here and otherwise access nullptr in
        // ctor.
        TextQuery(std::istream &input)
            : input_file_(std::make_shared<std::vector<std::string>>())
        {
            std::string line{};

            while (getline(input, line))
            {
                std::stringstream ssline{line};
                std::string word;
                    
                input_file_->push_back(line);

                // can use a varialbe and increase it in the loop
                lineno current_line = input_file_->size()-1;

                // *cxx-stringstream* parse up a line
                while (ssline >> word)
                {
                    // not covered in the book -- cleanup_str removes
                    // punctuation and converts all text to lowercase so that
                    // the queries operate in a case insensitive manner
                    word = cleanup_str(word);

                    auto &lines = word_map_[word];

                    // if a word is not in the map, that is to be seen in the
                    // first time, the second is default inicialized shared_ptt,
                    // which is null. Have to create a empty set.

                    if (!lines)
                        lines = std::make_shared<std::set<lineno>>();

                    lines->insert(current_line);
                }
            }
        }