示例#1
0
void test_doc() {
    const string fn {"sample_text.txt"};
    ifstream ifs {fn};
    if (!ifs)
        throw runtime_error("cannot open file " + fn);
    // reading and displaying test
    Document d {}; ifs >> d;
    cout << d;

    // find text test
    auto p = d.find_text(d.begin(), d.end(), "here it");
    if (p == d.end()) {
        cout << "not found\n";
    } else {
        cout << "found\n";
        print_doc(d, p);
    }
    d.find_and_replace(d.begin(), d.end(), "here it", "It it not here");
    cout << d;
    d.erase_line(1); d.erase_line(1); d.erase_line(1); d.erase_line(1);
    cout << d;
    cout << "number of characters: " << d.count_char() << '\n';
    cout << "number of words: " << d.count_words() << '\n';
    const string wspace {"."};
    cout << "number of words: with white-space characters " + wspace + " = "<<
        d.count_words(wspace) << '\n';
}
示例#2
0
void mapper(char* model_root, char* prefix, char* infofile, char* settingfile){
    setbuf(stdout,NULL);
    fprintf(stderr, "load init model..\n");
    twtm_model* model = new twtm_model(model_root, prefix, infofile);
    fprintf(stderr,"num_labels:%d\nnum_words:%d\nnum_topics:%d\n", model->num_labels, model->num_words, model->num_topics);
    int num_topics = model->num_topics;
    Config* config = new Config(settingfile);
    int doc_num_labels;
    int doc_num_words;
    int docid;
    char str[100];
    while (scanf("%d", &docid) != EOF) {
        scanf("%d", &doc_num_labels);
        int* labels_ptr = new int [doc_num_labels];
        for (int i = 0; i < doc_num_labels; i++) scanf("%d", &labels_ptr[i]);
        scanf("%s", str);
        scanf("%d", &doc_num_words);
        int* words_ptr = new int[doc_num_words];
        int* words_cnt_ptr = new int [doc_num_words];
        for (int i =0; i < doc_num_words; i++) {
            scanf("%d:%d", &words_ptr[i],&words_cnt_ptr[i]);
        }
        //printf("doc_num_labels:%d\ndoc_num_words:%d\n", doc_num_labels, doc_num_words);
        Document* doc = new Document(labels_ptr, words_ptr, words_cnt_ptr, doc_num_labels, doc_num_words, num_topics, docid);
        //printf("inference...\n");
        do_inference(doc, model, config);
        //printf("inference done\n");
        print_doc(doc);
        delete doc;
    }
}
示例#3
0
文件: drukuj.cpp 项目: MKalat/BFQt
void Drukuj::on_pushButton_Print_clicked()
{
	if (QFile::exists(QString::fromWCharArray(L"wydruk.html")))
	{
		QFile::remove(QString::fromWCharArray(L"wydruk.html"));
	}
	if (ui->radioButton_Akt->isChecked() == true)
	{
		Film* flm_p = &flm_d.film_tbl;
		bool head_wrttn = false;
		bool close_html = true;
		GetFLM_HTML(flm_p, head_wrttn, close_html);
		
		print_doc();

	}
	else if (ui->radioButton_All->isChecked() == true)
	{
		struct Film m_buff;
		QFile fn_m(QString::fromWCharArray(flm_d.pths.BF_PDB));
		fn_m.open(QFile::ReadOnly);
		unsigned int stop_m = fn_m.size();
		bool head_wrttn = false;
		bool close_html = false;
		for (unsigned int y = 0; y < stop_m; )
		{
				fn_m.seek(y);
				fn_m.read(reinterpret_cast<char *>(&m_buff),sizeof(m_buff));
				if (y == (fn_m.size() - sizeof(m_buff)))
				{
					close_html = true;
				}
				GetFLM_HTML(&m_buff, head_wrttn, close_html);
				head_wrttn = true;
				y = y + sizeof(m_buff);
		}
		
		print_doc();
	}
}
示例#4
0
void
edit_main_rep::print_buffer (string first, string last) {
  url target;
#ifdef OS_MINGW
  target= use_pdf ()? url_temp (".pdf"): url_temp (".ps");
#else
  target= url_temp (".ps");
#endif
  print_doc (target, false, as_int (first), as_int (last));
  system (get_printing_cmd (), target);  // Send the document to the printer
  set_message ("Done printing", "print buffer");
  ::remove (target);
}
示例#5
0
int main (int argc, char *argv[]) {
    if (argc < 2) {
        print_doc(argv[0]);
        return EINVAL;
    }

    if (strncmp(argv[1],"put",3) == 0) {
        if (argc < 4) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        const char *src = argv[3];
        return do_put(key, src);
    } else if (strncmp(argv[1], "get", 3) == 0) {
        if (argc < 4) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        const char *outpath = argv[3];
        return do_get(key, outpath);
    } else if (strncmp(argv[1], "remove", 6) == 0) {
        if (argc < 3) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        return do_remove(key);
    } else if (strncmp(argv[1], "search", 6) == 0) {
        if (argc < 4) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        const char *outpath = argv[3];
        return do_search(key, outpath);
    } else if (strncmp(argv[1], "stat", 4) == 0) {
        if (argc < 3) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        return do_stat(key);
    } else {
        print_doc(argv[0]);
        return EINVAL;
    }

    return 0;
}
示例#6
0
static void
fetch (mongoc_collection_t *col,
       const bson_t        *spec)
{
   mongoc_cursor_t *cursor;
   const bson_t *b;
   bson_error_t error;

   cursor = mongoc_collection_find(col, MONGOC_QUERY_NONE, 0, 0, spec, NULL, NULL);
   while (mongoc_cursor_next(cursor, &b)) {
      BSON_ASSERT(b);
      print_doc(b);
   }
   if (mongoc_cursor_error(cursor, &error)) {
      MONGOC_WARNING("Cursor error: %s", error.message);
   }
   mongoc_cursor_destroy(cursor);
}
示例#7
0
static void
ping (mongoc_database_t *db,
      const bson_t      *cmd)
{
   mongoc_cursor_t *cursor;
   const bson_t *b;
   bson_error_t error;

   cursor = mongoc_database_command(db, MONGOC_QUERY_NONE, 0, 1, cmd, NULL, NULL);
   while (mongoc_cursor_next(cursor, &b)) {
      BSON_ASSERT(b);
      print_doc(b);
   }
   if (mongoc_cursor_error(cursor, &error)) {
      MONGOC_WARNING("Cursor error: %s", error.message);
   }
   mongoc_cursor_destroy(cursor);
}
示例#8
0
void
edit_main_rep::print_buffer (string first, string last) {
  // in Qt this is the main entry point to the printing subsystem.
  // the other routines (print_to_file, ...) are overriden since all fine tuning 
  // is made here via the Qt print dialog
  bool to_file, landscape;
  url name = url_none();
  string printer;
  string paper_type;
  if (qt_print (to_file, landscape, printer, name, first, last, paper_type)) {
      if (!to_file) name = url_temp (".ps");
      print_doc (name, false, as_int (first), as_int (last));
      if (!to_file) {
        string cmd = printing_cmd * " -P" * printer;
        system (cmd, name);  
        ::remove (name);
      }
  }
}
示例#9
0
void usage() {
    print_doc((char **)usage_doc,N_USAGE_LINES); 
}
示例#10
0
void
edit_main_rep::export_ps (url name, string first, string last) {
  print_doc (name, true, as_int (first), as_int (last));
}
示例#11
0
void
edit_main_rep::print_to_file (url name, string first, string last) {
  print_doc (name, false, as_int (first), as_int (last));
  set_message ("Done printing", "print to file");
}