Skip to content

Commit

Permalink
add ability to handle multiple suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Keyes committed Aug 26, 2015
1 parent a1405a6 commit 813e650
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Version 0.1.0 [WIP]
-------------------------------------------------------------------------

FEATURES
* parse_names can now handle names with multiple suffixes accurately

BUG FIXES
* Fixed a segfault reported by Pavel Kirjanas, with the assistance of Bob Rudis

Version 0.0.1
-------------------------------------------------------------------------

* Initial (prototype) release
22 changes: 15 additions & 7 deletions src/human_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,26 @@ std::vector < std::string > human_parse::parse_single(std::string name){
split_name.pop_front();
}

// If there is still > 1 element and we find a suffix, pop those two elements. Otherwise just one.
if(split_name.size() > 1 && match_component(split_name[split_name.size() - 1], suffixes)){
output[4] = split_name[split_name.size() - 1];
split_name.pop_back();
output[3] = split_name[split_name.size() - 1];
split_name.pop_back();
} else if(split_name.size() > 0){
// If there's still > 1 elemenent, what about suffixes?
if(split_name.size() > 1){
while(split_name.size() > 1 && match_component(split_name[split_name.size() - 1], suffixes)){
if(output[4] == ""){
output[4] = split_name[split_name.size() - 1];
} else {
output[4] = split_name[split_name.size() - 1] + " " + output[4];
}
split_name.pop_back();
}
}

// If there's only >1 element, surnames
if(split_name.size() > 0){
output[3] = split_name[split_name.size() - 1];
split_name.pop_back();
} else {
return output;
}


// If there is still 1 or more elements we test for compounds
while(split_name.size() > 0 && match_component(split_name[split_name.size() - 1], compounds)){
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ test_that("Names with all elements can be parsed", {
expect_true(result["suffix"] == "PhD")

})

test_that("Names with no spaces do not break everything", {
result <- unlist(parse_names("G.R.Dobbs"))
expect_true(result["first_name"] == "G.R.Dobbs")
})

test_that("Names with multiple suffixes can be parsed", {
result <- unlist(parse_names("Jim Jeffries Jr PhD"))
expect_true(result["first_name"] == "Jim")
expect_true(result["last_name"] == "Jeffries")
expect_true(result["suffix"] == "Jr PhD")
})

0 comments on commit 813e650

Please sign in to comment.