Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A rust client for the Crossref-API

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

mattsse/crossref-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusCrates.ioDocumentation

Crossref API docs

This client is inspired bysckott/habanero.

Crossref - Crossref search API. TheCrossref crate provides methods matching Crossref API routes:

  • works -/works route
  • members -/members route
  • prefixes -/prefixes route
  • funders -/funders route
  • journals -/journals route
  • types -/types route
  • agency -/works/{doi}/agency get DOI minting agency

Usage

Create aCrossref client:

let client =Crossref::builder().build()?;

If you have anAuthorization token for Crossref's Plus service:

let client =Crossref::builder().token("token").build()?;

Encouraged to use theThe Polite Pool:

Good manners = more reliable service

To get into Crossref's polite pool include a email address

let client =Crossref::builder().polite("polite@example.com").token("your token").build()?;

Constructing Queries

Not all components support queries and there are custom available parameters for each route that supports querying.For each resource components that supports querying there exist a Query struct:WorksQuery,MembersQuery,FundersQuery. TheWorksQuery also differs from the others by supportingdeep paging with cursors andfield queries.

otherwise creating queries works the same for all resource components:

let query =WorksQuery::new("Machine Learning")// field queries supported for `Works`.field_query(FieldQuery::author("Some Author"))// filters are specific for each resource component.filter(WorksFilter::HasOrcid).order(Order::Asc).sort(Sort::Score);

Get Records

Seethis table for a detailed overview of the major components.

There are 3 different targets:

  • standalone resource components:/works,/members,funders,prefixes,types that return a list list of the corresponding items and can be specified with queries
  • Resource component with identifiers:/works/{doi}?<query>,/members/{member_id}?<query>, etc. that returns a single item if found.
  • combined with theworks route: The works component can be appended to other resources:/members/{member_id}/works?<query> etc. that returns a list of matchingWork items asWorkList.

This resembles in the enums of the resource components, eg. forMembers:

pubenumMembers{/// target a specific member at `/members/{id}`Identifier(String),/// target all members that match the query at `/members?query...`Query(MembersQuery),/// target a `Work` for a specific member at `/members/{id}/works?query..`Works(WorksIdentQuery),}

Examples

All options are supported by the client:

Query Single Item by DOI or ID

Analogous methods exist for all resource components

let work = client.work("10.1037/0003-066X.59.1.29")?;let agency = client.work_agency("10.1037/0003-066X.59.1.29")?;let funder = client.funder("funder_id")?;let member = client.member("member_id")?;

Query

let query =WorksQuery::new("Machine Learning");// one page of the matching resultslet works = client.works(query)?;

Alternatively insert a free form query term directly

let works = client.works("Machine Learning")?;

Combining Routes with theWorks route

For each resource component other thanWorks there exist methods to append aWorksQuery with the ID option/members/{member_id}/works?<query>?

use crossref::*;fn run() -> Result<()> {    let client = Crossref::builder().build()?;    let works = client.member_works(WorksQuery::new("machine learning")    .sort(Sort::Score).into_ident("member_id"))?;    Ok(())}

This would be the same as using the [Crossref::works] method by supplying the combined type

use crossref::*;fnrun() ->Result<()>{let client =Crossref::builder().build()?;let works = client.works(WorksQuery::new("machine learning").sort(Sort::Score).into_combined_query::<Members>("member_id"))?;Ok(())}

** Deep paging forWorks **Deep paging resultsDeep paging is supported for all queries, that return a list ofWork,WorkList.This function returns a new iterator over pages ofWork, which is returned as bulk of items as aWorkList by crossref.Usually a single pageWorkList contains 20 items.

Example

Iterate over allWorks linked to search termMachine Learning

use crossref::{Crossref,WorksQuery,Work};fnrun() ->Result<(), crossref::Error>{let client =Crossref::builder().build()?;let all_works:Vec<Work> = client.deep_page(WorksQuery::new("Machine Learning")).flat_map(|x|x.items).collect();Ok(())}

Which can be simplified to

use crossref::{Crossref,WorksQuery,Work};fnrun() ->Result<(), crossref::Error>{let client =Crossref::builder().build()?;let all_works:Vec<Work> = client.deep_page("Machine Learning").into_work_iter().collect();Ok(())}

Iterate over all the pages (WorkList) of the funder with idfunder id by using a combined query.A singleWorkList usually holds 20Work items.

use crossref::{Crossref,Funders,WorksQuery,Work,WorkList};fnrun() ->Result<(), crossref::Error>{let client =Crossref::builder().build()?;let all_funder_work_list:Vec<WorkList> = client.deep_page(WorksQuery::default().into_combined_query::<Funders>("funder id")).collect();Ok(())}

Iterate over allWork items of a specfic funder directly.

use crossref::{Crossref,Funders,WorksQuery,Work,WorkList};fnrun() ->Result<(), crossref::Error>{let client =Crossref::builder().build()?;let all_works:Vec<Work> = client.deep_page(WorksQuery::default().into_combined_query::<Funders>("funder id")).into_work_iter().collect();Ok(())}

Command Line Application

Installation

cargo install crossref --features cli

Usage

Top level subcommands

USAGE:    crossref <SUBCOMMAND>FLAGS:    -h, --help       Prints help information    -V, --version    Prints version informationSUBCOMMANDS:    funders     Query crossref funders    help        Prints this message or the help of the given subcommand(s)    journals    Query crossref journals    members     Query crossref members    prefixes    Query crossref prefixes    types       Query crossref types    works       Query crossref works

Additional options for the component subcommands (querying, sorting, ordering and limiting is only supported for subcommands <works|funders|members> and is overridden by a present--id options)

USAGE:    crossref works [FLAGS] [OPTIONS] [SUBCOMMAND]FLAGS:    -a, --append       if the output file already exists, append instead of overwriting the file    -d, --deep-page    Enable deep paging. If a limit is set, then the limit takes priority.    -h, --help         Prints help information    -s, --silent       do not print anything    -V, --version      Prints version informationOPTIONS:    -i, --id <id>                    The id of component.    -l, --limit <limit>              limit the amount of results        --offset <offset>            Sets an offset where crossref begins to retrieve items.        --order <order>              How to order the results: asc or desc    -o <output>                      output path where the results shall be stored        --polite <polite>            The email to use to get into crossref's polite pool    -q, --query <query_terms>...     The free form terms for the query        --sample <sample>            Request randoms Elements. Overrides all other options.        --sort <sort>                How to sort the results, such as updated, indexed, published, issued        --token <token>              The token to use for the crossref client        --user-agent <user_agent>    The user agent to use for the crossref client

Examples

Retrieve a specific work by a doi

 crossref works --id"10.1037/0003-066X.59.1.29"

Save the results as json

 crossref works --id"10.1037/0003-066X.59.1.29" -o output.json

Retrieve any other components by their ids

 crossref<works|journals|members|prefixes|types> --id"10.1037/0003-066X.59.1.29" -o output.json

Some components support additional filtering

crossref <works|funders|members> --query "A search term such as `Machine learning` for works" --limit 10 --offset 200 --order asc

GetWorks of a specific component, such as a member with the id98:

crossref works member 98

<prefix|funder|prefix|type are also supported in the same way.

By default deep paging is disabled, hence the max amount of results ofWorks will be 20 (a single crossref page).By enabling the--deep-page flag, all available results will be gathered.

To get in to the polite pool supply your email to the request headers with--polite "polite@example.com"

License

Licensed under either of these:

About

A rust client for the Crossref-API

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp