AyushP123

ranker_test

Jul 4th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.95 KB | None | 0 0
  1. static void
  2. gen_uniqterms_gt_doclen_db(Xapian::WritableDatabase& db, const string&)
  3. {
  4.     Xapian::Document doc;
  5.     Xapian::TermGenerator termgenerator;
  6.     termgenerator.set_document(doc);
  7.     termgenerator.set_stemmer(Xapian::Stem("en"));
  8.     termgenerator.index_text("What is AI (Artificial Intelligence) - "
  9.                  "Definition from WhatIs", 1, "S");
  10.     termgenerator.index_text("AI (pronounced AYE-EYE) or artificial "
  11.                  "intelligence is the simulation of human "
  12.                  "intelligence processes by machines, especially "
  13.                  "computer systems. These processes include "
  14.                  "learning (the acquisition of information and "
  15.                  "rules for using the information), reasoning "
  16.                  "(using the rules to reach approximate or "
  17.                  "definite conclusions), and self-correction. "
  18.                  "Particular applications of AI include expert "
  19.                  "systems, speech recognition and machine vision.",
  20.                  1, "XD");
  21.     termgenerator.index_text("What is AI (Artificial Intelligence) - "
  22.                  "Definition from WhatIs");
  23.     termgenerator.increase_termpos();
  24.     termgenerator.index_text("AI (pronounced AYE-EYE) or artificial "
  25.                  "intelligence is the simulation of human "
  26.                  "intelligence processes by machines, especially "
  27.                  "computer systems. These processes include "
  28.                  "learning (the acquisition of information and "
  29.                  "rules for using the information), reasoning "
  30.                  "(using the rules to reach approximate or "
  31.                  "definite conclusions), and self-correction. "
  32.                  "Particular applications of AI include expert "
  33.                  "systems, speech recognition and machine vision");
  34.     db.add_document(doc);
  35.     doc.clear_terms();
  36.     termgenerator.index_text("Artificial Intelligence-Wikipedia", 1, "S");
  37.     termgenerator.index_text("Artificial intelligence (AI) is intelligence "
  38.                  "exhibited by machines. In computer science, the "
  39.                  "field of AI research defines itself as the study "
  40.                  "of intelligent agents: any device that perceives "
  41.                  "its environment and takes actions that maximize "
  42.                  "its chance of success at some goal. "
  43.                  "Colloquially, the term artificial intelligence "
  44.                  "is applied when a machine mimics cognitive "
  45.                  "functions that humans associate with other human "
  46.                  "minds, such as learning and problem solving.", 1,
  47.                  "XD");
  48.     termgenerator.index_text("Artificial Intelligence-Wikipedia");
  49.     termgenerator.increase_termpos();
  50.     termgenerator.index_text("Artificial intelligence (AI) is intelligence "
  51.                  "exhibited by machines. In computer science, the "
  52.                  "field of AI research defines itself as the study "
  53.                  "of intelligent agents: any device that perceives "
  54.                  "its environment and takes actions that maximize "
  55.                  "its chance of success at some goal. "
  56.                  "Colloquially, the term artificial intelligence "
  57.                  "is applied when a machine mimics cognitive "
  58.                  "functions that humans associate with other human "
  59.                  "minds, such as learning and problem solving.");
  60.     db.add_document(doc);
  61. }
  62.  
  63. DEFINE_TESTCASE(ranker1, generated) {
  64.     Xapian::Ranker *ranker = new Xapian::ListNETRanker();
  65.     Xapian::Database db = get_database("apitest_ranker1",
  66.                        gen_uniqterms_gt_doclen_db);
  67.     Xapian::Enquire enquire(db);
  68.     enquire.set_query(Xapian::Query("artificial"));
  69.     Xapian::MSet mymset = enquire.get_mset(0, 10);
  70.     string query ="20001 'artificial'";
  71.     string qrel = "20001 Q0 1 1\n20001 Q0 2 2";
  72.     std::ofstream myfile;
  73.     myfile.open("query.txt");
  74.     myfile << query;
  75.     myfile.close();
  76.     myfile.open("qrel.txt");
  77.     myfile << qrel;
  78.     myfile.close();
  79.     Xapian::prepare_training_file(get_database_path("apitest_ranker1").c_str(),
  80.                   "query.txt","qrel.txt",10);
  81.     //ranker->set_database_path(get_database_path("apitest_ranker"));
  82.     //ranker->set_query(Xapian::Query("and"));
  83.  
  84.     delete ranker;
  85.  
  86.     return true;
  87. }
Add Comment
Please, Sign In to add comment