예제 #1
0
int main(int argc, char **argv)
{
    // open the file from which user will query words
	ifstream infile;
	if (argc < 2 || !open_file(infile, argv[1])) {
		cerr << "No input file!" << endl;
		return EXIT_FAILURE;
	}
	TextQuery tq;
	tq.read_file(infile); // builds query map
	// iterate with the user: prompt for a word to find and print results
	// loop indefinitely; the loop exit is inside the while
	while (true) {
		cout << "enter word to look for,or q to quit" << endl;
		string s;
		cin >> s;
		// stop if hit eof on input or a 'q'is entered
		if (!cin || s == "q")
			break;
        	// get the set of line numbers on which this word appears
		set<TextQuery::line_no> locs = tq.run_query(s);
		// print count and all occurrences, if any
		print_results(locs, s, tq);
	}
	return 0;
}
예제 #2
0
int main(int argc, char **argv)
{
  ifstream infile;
  if (argc < 2 || !open_file(infile,argv[1]))
  {
    cerr << "No input file!" << endl;
    return EXIT_FAILURE;
  }

  //textquery_test(infile);
  TextQuery tq;
  tq.read_file(infile);

  cout << "================================================" << endl;
  cout << "Query(\"Daddy\"):" << endl;
  query_word_test(tq,"Daddy");

  cout << "================================================" << endl;
  cout << "~Query(\"Alice\"):" << endl;
  query_not_test(tq,"Alice");

  cout << "================================================" << endl;
  cout << "Query(\"hair\") | Query(\"Alice\"):" << endl;
  query_binary_test(tq,"|");

  cout << "================================================" << endl;
  cout << "Query(\"hair\") & Query(\"Alice\"):" << endl;
  query_binary_test(tq,"&");

  cout << "================================================" << endl;
  cout << "(Query(\"fiery\") & Query(\"bird\")) | Query(\"wind\"):" << endl;
  query_mul_test(tq);
  return 0;
}
예제 #3
0
int main(int argc, char **argv)
{
    std::ifstream infile;

    if (2 > argc || !open_file(infile, argv[1]))
    {
        cerr << "No input file!" << endl;
        return EXIT_FAILURE;
    }

    TextQuery tq;
    tq.read_file(infile);

    while (true)
    {
        cout << "enter word to look for, or q to quit: ";
        string s;
        cin >> s;

        if (!cin || s == "q")
            break;

        set<TextQuery::line_no> locs = tq.run_query(s);
        print_results(locs, s, tq);
    }

    return EXIT_SUCCESS;
}
예제 #4
0
void EchoServer::compute(const std::string &word, const TcpConnectionPtr &conn, const TextQuery &tq)
{	
	if(word == "q")
		exit(0);

	typedef set<TextQuery::line_no> line_nums;
	line_nums locs = tq.run_query(word);
	line_nums::size_type size = locs.size();
	
	char ssize[128] = "";
	sprintf(ssize, "%d", size);

	string s;
	s = s + "\n" + word +  " occurs " + ssize + " "
		 + make_plural(size, "time", "s") + "\n";
	line_nums::const_iterator it = locs.begin();
	for ( ; it != locs.end(); ++it)
	{
		char sit[128] = "";
		sprintf(sit, "%d", (*it) + 1);

		s = s +  "\t(line " + sit + ") "
			 + tq.text_line(*it) + "\r\n";
	}
	s = s + "\nenter word to look for, or q to quit: ";
	conn->send(s);
}
예제 #5
0
int main()
{
        TextQuery tq;

        tq.build_up_text();
        tq.query_text();

        return 0;
}
int main(int argc, char **argv)
{

    if (argc != 2) {cerr << "No input file" << endl; return -2;}

    // get a file to read from which user will query words
    ifstream infile;
    if (!open_file(infile, argv[1])) {
        cerr << "No input file!" << endl;
        return -1;
    }
    TextQuery tq;
    tq.read_file(infile);  // builds query map

    // iterate with the user: prompt for a word to find and print results
    string sought;
    do {
        cout << "enter a word against which to search the text.\n"
             << "to quit, enter a single character ==>  ";
        cin  >> sought;

        // stop if hit eof on input or single character entered
        if (!cin || sought.size() < 2) break;

        // find all the occurrences of the users requested string
        vector<TextQuery::location> locs = tq.run_query(sought);

        // report no matches
        if (locs.empty()) {
            cout << "\nSorry. There are no entries for " 
                 << sought << ".\nTry again." << endl;
            continue;
        }
    
        // if the word was found, then print count and all occurrences
        vector<TextQuery::location>::size_type size = locs.size();
        cout << "\n" << sought << " occurs " << size
             << (size == 1 ? " time:" : " times:")
             << "\n" << endl;
    
        // print each line in which the word appeared
        vector<TextQuery::location>::iterator it = locs.begin();
        while (it != locs.end()) {
            cout << "\t(line: "
                 // don't confound user with text lines starting at 0
                 << it->first + 1 << ", pos: " << it->second + 1 << ") "
                 << tq.text_line(it->first) << endl;
            ++it;
         }
    } while (!sought.empty());

    cout << "Ok, bye!" << endl;

    // debugging aid -- look at the map that was built
    tq.display_map();
    return 0;
}
예제 #7
0
int main()
{
    TextQuery tx;
	string filename="in.txt";
    tx.read_file(filename);
    tx.build_map();
    
	tx.query_word("me");
}
예제 #8
0
void EchoServer::onMessage(const TcpConnectionPtr &conn)
{
	ifstream infile;
	infile.close();
	infile.clear();
	infile.open("test.txt");
	TextQuery tq;
	tq.read_file(infile);
	string s(conn->receive());
	s.erase(s.size() - 2);
	pool_.addTask(bind(&EchoServer::compute, this, s, conn, tq));
}
예제 #9
0
int main()
{
	TextQuery tq;
	tq.read_file("test.txt");
	tq.build_map();
//	tq.debug();
	cout << "Query:" << endl;
	string word;
	while(cin >> word)
	{
		tq.query_word(word);
	}
	return 0;
}
예제 #10
0
void textquery_test(ifstream &infile)
{
  TextQuery tq;
  tq.read_file(infile);
  while (true) 
  {
    cout << "enter word to look for,or q to quit: ";
    string s;
    cin >> s;
    if (!cin || s == "q") 
      break;
    set<TextQuery::line_no> locs = tq.run_query(s);
    print_result(locs,s,tq);
  }
}
예제 #11
0
int main(int argc, char *argv[])
{
    TextQuery tq;
    ifstream is("luo.txt");
    tq.read_file(is);
    string str("luo");
    set<TextQuery::line_no> s_lno = tq.run_query(str);
    cout << str << " occurs " << s_lno.size() << " times" << endl;
    for(set<TextQuery::line_no>::iterator iter = s_lno.begin();
                                          iter != s_lno.end(); ++iter) {
        cout << "(line " << *iter << ") ";
        cout << tq.text_line(*iter) <<endl;
    }

    return 0;
}
예제 #12
0
파일: Query.cpp 프로젝트: yuandaxing/utils
int main(int argc, char *argv[])
{
	std::string s1("the"), s2("Her"), s3("in");
	const std::string file("text.txt");;
	TextQuery tq;
	std::ifstream fin(file.c_str());
	tq.read_file(fin);
	Query q = (Query(s1) & Query(s2)) | Query(s3);
	std::set<TextQuery::line_no> set = q.eval(tq);
	typedef std::set<TextQuery::line_no>::iterator iter_stq;
	for( iter_stq iter= set.begin() ; iter != set.end() ; iter++ )
	{
		std::cout << tq.text_line(*iter) << std::endl;
	}
	return 0;
}
예제 #13
0
int AppMain(int argc, char *argv[]) {

  Index  *ind;

  try {
    ind = IndexManager::openIndex(RetrievalParameter::databaseIndex);
  } 
  catch (Exception &ex) {
    ex.writeMessage();
    throw Exception("QueryClarity", 
                    "Can't open index, check parameter index");
  }

  lemur::retrieval::ArrayAccumulator accumulator(ind->docCount());
  IndexedRealVector res(ind->docCount());
  ofstream os(LocalParameter::expandedQuery.c_str());

  lemur::retrieval::SimpleKLRetMethod *model;
  model =  new lemur::retrieval::SimpleKLRetMethod(*ind, SimpleKLParameter::smoothSupportFile, 
                                 accumulator);
  model->setDocSmoothParam(SimpleKLParameter::docPrm);
  model->setQueryModelParam(SimpleKLParameter::qryPrm);
  DocStream *qryStream;
  try {
    qryStream = new lemur::parse::BasicDocStream(RetrievalParameter::textQuerySet);
  } catch (Exception &ex) {
    ex.writeMessage(cerr);
    throw Exception("QueryClarity", "Can't open query file");
  }
  qryStream->startDocIteration();
  TextQuery *q;
  while (qryStream->hasMore()) {
    Document *d = qryStream->nextDoc();
    q = new TextQuery(*d);
    QueryRep *qr = model->computeQueryRep(*q);
    res.clear();
    QueryClarity(qr, q->id(), &res, model, os);     
    delete qr;
    delete q;
  }
  os.close();
  delete model;
  delete qryStream;
  delete ind;
  return 0;
}
예제 #14
0
void print_results(const set<TextQuery::line_no>& locs, const string& sought, const TextQuery &file) {
    // Print how many times a word shows, and all lines it in.
    typedef set<TextQuery::line_no> line_nums;
    line_nums::size_type size = locs.size();
    cout << "\n" << sought << " occurs " << size << " " << make_plural(size, "time", "s") << endl;
    line_nums::const_iterator it = locs.begin();
    for (; it != locs.end(); ++it) {
        cout << "\t(line " << (*it) + 1 << ") " << file.text_line(*it) << endl;
    }
}
예제 #15
0
void TextQuery::print_result(const std::set<TextQuery::line_no>& locs, const std::string& sought, const TextQuery &file)
{
    typedef std::set<TextQuery::line_no> line_nums;
    line_nums::size_type size = locs.size();
    std::cout << "\n" << sought << " occurs" << size << " " << make_plural(size, "time", "s") << std::endl;
    line_nums::const_iterator it = locs.begin();
    for (; it != locs.end(); ++it) {
        std::cout << "\t(line " << (*it) + 1 << ")" << file.text_line(*it) << std::endl;
    }
}
예제 #16
0
std::set<TextQuery::line_no>
NotQuery::eval( const TextQuery& file ) const
{
  std::set<TextQuery::line_no> has_val = query.eval( file );
  std::set<line_no> ret_lines;

  for( TextQuery::line_no n = 0; n != file.size(); ++n )
    if ( has_val.find( n ) == has_val.end() )
      ret_lines.insert( n );
  return ret_lines;
}
예제 #17
0
int main()
{
ifstream infile("dat");
if(!infile){
cerr << "can't open the file..." << endl;
exit(0);
}
TextQuery tq;
tq.read_file(infile);
while(true){
cout << "Input the word to look for,q to exit:"<< endl;
string s;
cin >> s;
if(!cin || s == "q")
  break;
set<TextQuery::line_no> locs = tq.run_query(s);
  print_results(locs,s,tq);
}
return 0;
}
예제 #18
0
파일: Query.cpp 프로젝트: bondyuan/exercise
std::set<TextQuery::line_no> NotQuery::eval(const TextQuery &obj_TextQuery) const
{
	std::set<TextQuery::line_no> has_val = query.eval(obj_TextQuery);
	std::set<TextQuery::line_no> ret_line;
	for (int i = 0; i != obj_TextQuery.size(); ++i)
	{
		if (has_val.find(i) == has_val.end())
			ret_line.insert(i);
		return ret_line;
	}

}
예제 #19
0
파일: Query.cpp 프로젝트: yuandaxing/utils
std::set<TextQuery::line_no>
NotQuery::eval(const TextQuery& tq) const {
	std::set<TextQuery::line_no> v = query.eval(tq);
	std::set<line_no> ret;
	for( TextQuery::line_no n = 0 ; n != tq.size() ; n++ )
	{
		if( v.find(n) == v.end() )
		{
			ret.insert(n);
		}
	}
	return ret;
}
예제 #20
0
set<TextQuery::line_no>
NotQuery::eval(const TextQuery& file) const
{
	// virtual call through the Query handle to eval
	set<TextQuery::line_no> has_val = query.eval(file);
	set<line_no> ret_lines;
	// for each line in the input file, check whether that line is	in has_val
		// if not, add that line number to ret_lines
		for (TextQuery::line_no n = 0; n != file.size(); ++n)
			if (has_val.find(n) == has_val.end())
				ret_lines.insert(n);
	return ret_lines;
}
예제 #21
0
void search(string x,ostream &t,TextQuery a) {
	print(t, a.query(x));
	t << "---------------------------------------------------------------------------------------" << endl;
	cout << "1 record has been writen in file." << endl;
}
예제 #22
0
	set<line_no> 
		eval(const TextQuery & t) const {return t.run_query(query_word);}
예제 #23
0
파일: Query.hpp 프로젝트: Mlieou/cpp_primer
 QueryResult eval(const TextQuery &t) const override {
     return t.query(query_word);
 }