예제 #1
0
std::vector<CollectorPtr> collectorsCreate(ListOf<List> specs,
                                           LocaleInfo* pLocale,
                                           Warnings* pWarning) {
  std::vector<CollectorPtr> collectors;
  for (int j = 0; j < specs.size(); ++j) {
    CollectorPtr col = Collector::create(specs[j], pLocale);
    col->setWarnings(pWarning);
    collectors.push_back(col);
  }

  return collectors;
}
예제 #2
0
파일: AdapterI.cpp 프로젝트: bradenwu/oce
ObjectResultPtr AdapterI::get(Ice::Int category, const MyUtil::LongSeq& ids,
		bool parallel, int timeout) {
	if (_cluster <= 0) {
		try {
			return locate(0, timeout)->locateObjects(category, ids);
		} catch (Ice::Exception& e) {
			MCE_WARN("ServiceAdapter::get -> locateObjects err:" << e);
		}
		return new ObjectResult;
	}

	if (parallel) {
		CollectorPtr action = new ParallelCollector(*this, _cluster, category,
				ids, timeout);
		return action->execute();
	} else {
		return SerialCollector(*this, _cluster, category, ids, timeout).execute();
	}
}
예제 #3
0
bool TermScorer::score(const CollectorPtr& collector, int32_t max, int32_t firstDocID) {
    // firstDocID is ignored since nextDoc() sets 'doc'
    collector->setScorer(shared_from_this());
    while (doc < max) { // for docs in window
        collector->collect(doc);

        if (++pointer >= pointerMax) {
            pointerMax = termDocs->read(docs, freqs); // refill buffers
            if (pointerMax != 0) {
                pointer = 0;
            } else {
                termDocs->close(); // close stream
                doc = INT_MAX; // set to sentinel value
                return false;
            }
        }
        doc = docs[pointer];
        freq = freqs[pointer];
    }
    return true;
}
예제 #4
0
파일: read.cpp 프로젝트: Dulani/readr
// [[Rcpp::export]]
std::vector<std::string> guess_types_(List sourceSpec, List tokenizerSpec,
                                      Rcpp::List locale_, int n = 100) {
  Warnings warnings;
  SourcePtr source = Source::create(sourceSpec);
  TokenizerPtr tokenizer = Tokenizer::create(tokenizerSpec);
  tokenizer->tokenize(source->begin(), source->end());
  tokenizer->setWarnings(&warnings); // silence warnings

  LocaleInfo locale(locale_);

  std::vector<CollectorPtr> collectors;
  for (Token t = tokenizer->nextToken(); t.type() != TOKEN_EOF; t = tokenizer->nextToken()) {
    if (t.row() >= (size_t) n)
      break;

    // Add new collectors, if needed
    if (t.col() >= collectors.size()) {
      int p = collectors.size() - t.col() + 1;
      for (int j = 0; j < p; ++j) {
        CollectorPtr col = CollectorPtr(new CollectorCharacter(&locale.encoder_));
        col->setWarnings(&warnings);
        col->resize(n);
        collectors.push_back(col);
      }
    }

    collectors[t.col()]->setValue(t.row(), t);
  }

  std::vector<std::string> out;
  for (size_t j = 0; j < collectors.size(); ++j) {
    CharacterVector col = as<CharacterVector>(collectors[j]->vector());
    out.push_back(collectorGuess(col, locale_));
  }

  return out;
}
예제 #5
0
// [[Rcpp::export]]
RObject type_convert_col(CharacterVector x, List spec, int col,
                         const std::vector<std::string>& na, bool trim_ws) {
  CollectorPtr collector = Collector::create(spec);
  collector->resize(x.size());

  for (int i = 0; i < x.size(); ++i) {
    SEXP string = x[i];
    Token t;

    if (string == NA_STRING) {
      t = Token(TOKEN_MISSING, i - 1, col - 1);
    } else {
      const char* begin = CHAR(string);
      t = Token(begin, begin + Rf_length(string), i - 1, col - 1);
      if (trim_ws)
        t.trim();
      t.flagNA(na);
    }

    collector->setValue(i, t);
  }

  return collector->vector();
}
예제 #6
0
Str2StrMapSeq SearchDataI::search(const string& query, int begin, int limit)
{
  TimeCost tc = TimeCost::create("SearchDataI::Search",1);
  vector<string> words;
  splitWord(query,words);
  CollectorPtr collector = new Collector(100);
  if(StrUtil::mayPinyin(query,words)){
    MCE_DEBUG("start py search: " << query);
    vector<string> subStr(query.size());
    splitPY(query,0,0,subStr,collector);
    MCE_DEBUG("end py search");
  }
  ScorerPtr sp = hzIndex_.getScorer(words,words.size());
  if(sp == 0){ 
    MCE_DEBUG("zero");
  }else{
    MCE_DEBUG("get "<<sp.get());
    sp->score(collector);
  }
  vector<int> ids = collector->topDocs();
  int size = ids.size();
  if (size <= begin) {
    Str2StrMapSeq res;
    return res;
  }
  int total = begin + limit;
  if (total > size) {
    total = size;
  }

  Str2StrMapSeq res;
  for(int i = begin; i < total; ++i){
    res.push_back(stores_[ids[i]]);
  } 
  return res;
}