예제 #1
0
void query_binary_test(TextQuery &tq, string oper)
{

  Query q1 = Query("hair");
  string s1 = "hair";
  //set<TextQuery::line_no> result1 = q1.eval(tq);
  //print_result(result1, s1, tq);

  Query q2 = Query("Alice");
  string s2 = "Alice";
  //set<TextQuery::line_no> result2 = q2.eval(tq);
  //print_result(result2, s2, tq);

  if( oper == "&")
  {
    Query andq = q1 & q2;
    string ands = "hair & Alice";
    set<TextQuery::line_no> result = andq.eval(tq);
    print_result(result, ands, tq);
    cout << "Query for: " << andq << endl;
  }
  if( oper == "|")
  {
    Query orq = q1 | q2;
    string ors = "hair | Alice";
    set<TextQuery::line_no> result = orq.eval(tq);
    print_result(result, ors, tq);
    cout << "Query for: " << orq << endl;
  }
}
예제 #2
0
int main() {
	std::ifstream is("./text");	
	TextQuery tq(is);
	Query q = Query("fiery") & Query("bird") | Query("wind");
	print(std::cout, q.eval(tq));
	return 0;
}
예제 #3
0
파일: main.cpp 프로젝트: blueyi/cpp_study
int main()
{
    std::ifstream file("test.txt");

    TextQuery tQuery(file);

    Query q = Query("fieryzzz")  | Query("wind");

    std::cout << q.eval(tQuery);

    return 0;
}
예제 #4
0
파일: main.cpp 프로젝트: kukys/primer
int main()
{
    std::ifstream file("E:/mingw/project/15_39/test.txt");

    TextQuery tQuery(file);

	  Query q = Query("hair")|Query("Alice");

    std::cout << q.eval(tQuery);

	std::cin.get();
    return 0;
}
예제 #5
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;
}
예제 #6
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;
}
예제 #7
0
int main(int, char **argv)
{
    // gets file to read and builds map to support queries
    TextQuery file = build_textfile(argv[1]);

    // iterate with the user: prompt for a word to find and print results
    do {
        string sought1, sought2;
        if (!get_words(sought1, sought2)) break;
        // find all the occurrences of the requested string
        Query orq = Query(sought1) | Query(sought2);
        cout << "\nExecuting Query for: " << orq << endl;
        const set<TextQuery::line_no> locs = orq.eval(file);

        // report matches
        print_results(locs, file);
    } while (true);  // loop indefinitely; the exit is inside the loop
    return 0;
}
예제 #8
0
int main(int argc, char **argv)
{
  // gets file to read and builds map to support queries
  TextQuery file = get_file(argc, argv);

  // iterate with the user: prompt for a word to find and print results
  while (true) {
    string sought1, sought2, sought3;
    if (!get_words(sought1, sought2)) break;
    cout << "\nenter third word: ";
    cin >> sought3;
    // find all the occurrences of the requested string
    Query q = Query(sought1) & Query(sought2) | Query(sought3);
    cout << "\nExecuting Query for: " << q << endl;
    const auto results = q.eval(file);
    // report matches
    print(cout, results);
  }
  return 0;
}
예제 #9
0
void query_mul_test(TextQuery &tq)
{
  Query q1 = Query("fiery");
  string s1 = "hair";
  //set<TextQuery::line_no> result1 = q1.eval(tq);
  //print_result(result1, s1, tq);

  Query q2 = Query("bird");
  string s2 = "bird";
  //set<TextQuery::line_no> result2 = q2.eval(tq);
  //print_result(result2, s2, tq);
  
  Query q3 = Query("wind");
  string s3 = "wind";
  //set<TextQuery::line_no> result3 = q3.eval(tq);
  //print_result(result3, s3, tq);

  Query mulq = (q1 & q2) | q3;
  string muls = "(fiery & bird) | wind";
  set<TextQuery::line_no> result = mulq.eval(tq);
  print_result(result, muls, tq);
  cout << "Query for: " << mulq << endl;
}