ropensci / openalexR

Getting bibliographic records from OpenAlex
https://docs.ropensci.org/openalexR/
Other
101 stars 21 forks source link

How to query by Topic? #273

Open krisgulati opened 1 month ago

krisgulati commented 1 month ago

I understand that "concepts" are being deprecated and "topics" are coming in. But, I'm struggling to query to get topics.

What I'm trying to do is construct an oa_fetch to get the authors with certain topics.

However, when I try something like the following query I get the response, "no records found"

try = oa_fetch( topics.id = "T13075", entity = "authors", verbose = TRUE, options = list(sample = 20, seed = 1) )

The same is true when I replace "topics.id" with "topic_share.id"

However, when I change the query above from "entity="authors"" to "entity = "works"" the query does indeed work -- but I don't want the works I want the authors.

yjunechoe commented 1 month ago

I can replicate this and my impression is that OpenAlex is still rolling out Topics as a filter.

So for Works objects, I see that you can now filter by Topics (vs. Concepts):

https://docs.openalex.org/api-entities/works/filter-works

  • topics.id
  • topics.domain.id
  • topics.field.id
  • topics.subfield.id

But for Authors, there's only a filter by Concepts and it's still marked as to-be deprecated:

https://docs.openalex.org/api-entities/authors/filter-authors

  • x_concepts.id (alias: concepts.id or concept.id) -- will be deprecated soon

I suspect this will resolve itself with time

krisgulati commented 1 month ago

Thank you for responding so quickly and on the weekend! Sorry, I was going crazy trying to find a solution.

yjunechoe commented 1 month ago

No worries! This was good to check. For what it's worth I see the x_concepts.id filter still working fine - maybe that can get you started on something without waiting on the Topics filter to become available:

library(dplyr)

concepts_CS <- oa_fetch(
  entity = "concepts",
  search = "Computer Science"
) %>% 
  filter(level == 0) %>% 
  pull(id)
concepts_CS
#> [1] "https://openalex.org/C41008148"

oa_fetch(
  x_concepts.id = concepts_CS,
  entity = "authors",
  verbose = TRUE,
  options = list(sample = 1, seed = 1)
)
#> Requesting url: https://api.openalex.org/authors?filter=x_concepts.id%3Ahttps%3A%2F%2Fopenalex.org%2FC41008148&sample=1&seed=1
#> Getting 1 page of results with a total of 1 records...
#> # A tibble: 1 × 18
#>   id                  display_name display_name_alterna…¹ relevance_score ids   orcid works_count
#>   <chr>               <chr>        <list>                           <dbl> <lis> <lgl>       <int>
#> 1 https://openalex.o… K.S. McFall  <chr [3]>                         1.00 <chr> NA             10
#> # ℹ abbreviated name: ¹​display_name_alternatives
#> # ℹ 11 more variables: cited_by_count <int>, counts_by_year <list>,
#> #   affiliation_display_name <chr>, affiliation_id <chr>, affiliation_ror <chr>,
#> #   affiliation_country_code <chr>, affiliation_type <chr>, affiliation_lineage <chr>,
#> #   affiliations_other <list>, topics <list>, works_api_url <chr>