Skip to content

updated endpoint list #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
endpoints are now singular
  • Loading branch information
mustberuss committed Nov 30, 2024
commit 35ef43dd076b7b16d1619a007619bf51c2d3b6ef
6 changes: 3 additions & 3 deletions R/search-pv.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @noRd
get_base <- function(endpoint) {
sprintf("https://search.patentsview.org/api/v1/%s/", to_singular(endpoint))
sprintf("https://search.patentsview.org/api/v1/%s/", endpoint)
}

#' @noRd
@@ -224,15 +224,15 @@ request_apply <- function(ex_res, method, query, base_url, arg_list, api_key, ..
#'
#' search_pv(
#' query = qry_funs$contains(inventors_at_grant.name_last = "smith"),
#' endpoint = "patents",
#' endpoint = "patent",
#' config = httr::timeout(40)
#' )
#' }
#'
#' @export
search_pv <- function(query,
fields = NULL,
endpoint = "patents",
endpoint = "patent",
subent_cnts = FALSE,
mtchd_subent_only = lifecycle::deprecated(),
page = 1,
37 changes: 24 additions & 13 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -14,26 +14,37 @@ format_num <- function(x) {

#' @noRd
to_singular <- function(plural) {
if (endsWith(plural, "ees")) {
sub("ees$", "ee", plural)
} else if (endsWith(plural, "ies")) {
sub("ies$", "y", plural)
} else if (endsWith(plural, "es")) {
sub("es$", "", plural)
} else if (endsWith(plural, "s")) {
sub("s$", "", plural)
# ipcr and wipo are funky exceptions. On assignees and other_references
# we only want to remove the "s", not the "es"

if (plural == "ipcr") {
singular <- "ipc"
} else if (plural == "wipo") {
singular <- plural
} else if (endsWith(plural, "classes")) {
singular <- sub("es$", "", plural)
} else {
plural
singular <- sub("s$", "", plural)
}
singular
}


#' @noRd
to_plural <- function(singular) {
if (endsWith(singular, "y")) {
sub("y$", "ies", singular)
# wipo endpoint returns singular wipo as the entity

# remove the patent/ and publication/ from nested endpoints when present
singular <- sub("^(patent|publication)/", "", singular)

if (singular == "ipc") {
plural <- "ipcr"
} else if (singular == "wipo") {
plural <- singular
} else if (endsWith(singular, "s")) {
paste0(singular, "es")
plural <- paste0(singular, "es")
} else {
paste0(singular, "s")
plural <- paste0(singular, "s")
}
plural
}
41 changes: 28 additions & 13 deletions tests/testthat/helpers.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
# Vector of queries (one for each endpoint) that are used during testing. We
# need this b/c in the new version of the api, only three of the endpoints are
# searchable by patent number (i.e., we can't use a generic patent number
# search query).
# search query). further, now patent_number has been patent_id

TEST_QUERIES <- c(
"application_citations" = '{"patent_number": "10966293"}',
"assignees" = '{"_text_phrase":{"name_last": "Clinton"}}',
"cpc_groups" = '{"cpc_group_id": "A01B"}',
"cpc_subgroups" = '{"cpc_subgroup_id": "A01B1/00"}',
"cpc_subsections" = '{"cpc_subsection_id": "A01"}',
"inventors" = '{"_text_phrase":{"name_last":"Clinton"}}',
"nber_categories" = '{"nber_category_id": "1"}',
"nber_subcategories" = '{"nber_subcategory_id": "11"}',
"patents" = '{"patent_number":"5116621"}',
"patent_citations" = '{"patent_number":"5116621"}',
"uspc_mainclasses" = '{"uspc_mainclass_id":"30"}',
"uspc_subclasses" = '{"uspc_subclass_id": "100/1"}'
"assignee" = '{"_text_phrase":{"assignee_individual_name_last": "Clinton"}}',
"cpc_class" = '{"cpc_class_id": "A01"}',
"cpc_group" = '{"cpc_group_id": "A01B1/00"}',
"cpc_subclass" = '{"cpc_subclass_id": "A01B"}',
"g_brf_sum_text" = '{"patent_id": "11540434"}',
"g_claim" = '{"patent_id": "11540434"}',
"g_detail_desc_text" = '{"patent_id": "11540434"}',
"g_draw_desc_text" = '{"patent_id": "11540434"}',
"inventor" = '{"_text_phrase":{"inventor_name_last":"Clinton"}}',
"ipc" = '{"ipc_id": "1"}',
"location" = '{"location_name":"Chicago"}',
"patent" = '{"patent_id":"5116621"}',
"patent/attorney" = '{"attorney_id":"005dd718f3b829bab9e7e7714b3804a5"}',
"patent/foreign_citation" = '{"patent_id": "10000001"}',
"patent/other_reference" = '{"patent_id": "3930306"}',
"patent/rel_app_text" = '{"patent_id": "10000007"}',
"patent/us_application_citation" = '{"patent_id": "10966293"}',
"patent/us_patent_citation" = '{"patent_id":"5116621"}',
"pg_brf_sum_text" = '{"document_number": 20240324479}',
"pg_claim" = '{"document_number": 20230000001}',
"pg_detail_desc_text" = '{"document_number": 20230000001}',
"pg_draw_desc_text" = '{"document_number": 20230000001}',
"publication" = '{"document_number": 20010000002}',
"publication/rel_app_text" = '{"document_number": 20010000001}',
"uspc_mainclass" = '{"uspc_mainclass_id":"30"}',
"uspc_subclass" = '{"uspc_subclass_id": "100/1"}',
"wipo" = '{"wipo_id": "1"}'
)
12 changes: 9 additions & 3 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
context("utils")

test_that("we can convert endpoints to their singular form and back", {
test_that("we can convert endpoints to their plural form and back", {
skip_on_cran()

eps <- get_endpoints()
z <- vapply(eps, function(x) {
to_plural(to_singular(x))
to_singular(to_plural(x))
}, FUN.VALUE = character(1), USE.NAMES = FALSE)
expect_equal(eps, z)

# we now need to unnest the endpoints for the comparison to work
unnested_eps <- gsub("^(patent|publication)/", "", eps)

expect_equal(unnested_eps, z)
})