Ejemplo n.º 1
0
DataFrame human_parse::parse_vector(std::vector < std::string > names){
  
  // Measure and construct output
  unsigned int input_size = names.size();
  std::vector < std::string > salutation(input_size);
  std::vector < std::string > first_name(input_size);
  std::vector < std::string > middle_name(input_size);
  std::vector < std::string > last_name(input_size);
  std::vector < std::string > suffix(input_size);
  std::vector < std::string > holding(5);
  
  // For each element, go nuts
  for(unsigned int i = 0; i < input_size; i++){
    if((i % 10000) == 0){
      Rcpp::checkUserInterrupt();
    }
    
    holding = parse_single(names[i]);
    salutation[i] = holding[0];
    first_name[i] = holding[1];
    middle_name[i] = holding[2];
    last_name[i] = holding[3];
    suffix[i] = holding[4];

  }
  
  return DataFrame::create(_["salutation"] = salutation,
                           _["first_name"] = first_name,
                           _["middle_name"] = middle_name,
                           _["last_name"] = last_name,
                           _["suffix"] = suffix,
                           _["full_name"] = names,
                           _["stringsAsFactors"] = false);
}
Ejemplo n.º 2
0
DataFrame human_parse::parse_vector(CharacterVector names){
  
  // Measure and construct output
  unsigned int input_size = names.size();
  CharacterVector salutation(input_size);
  CharacterVector first_name(input_size);
  CharacterVector middle_name(input_size);
  CharacterVector last_name(input_size);
  CharacterVector suffix(input_size);
  CharacterVector holding(5);
  
  // For each element, go nuts
  for(unsigned int i = 0; i < input_size; i++){
    if((i % 10000) == 0){
      Rcpp::checkUserInterrupt();
    }
    
    if(names[i] == NA_STRING){
      salutation[i] = NA_STRING;
      first_name[i] = NA_STRING;
      middle_name[i] = NA_STRING;
      last_name[i] = NA_STRING;
      suffix[i] = NA_STRING;
    } else {
      holding = parse_single(Rcpp::as<std::string>(names[i]));
      salutation[i] = holding[0];
      first_name[i] = holding[1];
      middle_name[i] = holding[2];
      last_name[i] = holding[3];
      suffix[i] = holding[4];
    }


  }
  
  return DataFrame::create(_["salutation"] = salutation,
                           _["first_name"] = first_name,
                           _["middle_name"] = middle_name,
                           _["last_name"] = last_name,
                           _["suffix"] = suffix,
                           _["full_name"] = names,
                           _["stringsAsFactors"] = false);
}