Module step_2

Module step_2 

Source
Expand description

§Step 2 - Paper & Author Structs

This tutorial covers the main data structures used in ss-tools.

§Paper Struct

The Paper struct represents a scientific paper from Semantic Scholar. All fields are optional since the API returns only requested fields.

use ss_tools::structs::Paper;

// Paper struct has many optional fields
let paper = Paper::default();
assert!(paper.paper_id.is_none());
assert!(paper.title.is_none());

§Key Paper Fields

FieldTypeDescription
paper_idOption<String>Unique paper ID
titleOption<String>Paper title
abstract_textOption<String>Paper abstract
yearOption<u32>Publication year
citation_countOption<u32>Number of citations
reference_countOption<u32>Number of references
authorsOption<Vec<Author>>List of authors

§Author Struct

The Author struct represents an author from Semantic Scholar.

use ss_tools::structs::Author;

let author = Author::default();
assert!(author.author_id.is_none());
assert!(author.name.is_none());

§Key Author Fields

FieldTypeDescription
author_idOption<String>Unique author ID
nameOption<String>Author name
affiliationsOption<Vec<String>>Author affiliations
paper_countOption<u32>Number of papers
citation_countOption<u32>Total citations
hindexOption<u32>H-index

§Field Enums

§PaperField

Use PaperField to specify which paper fields to request.

use ss_tools::structs::PaperField;

let fields = vec![
    PaperField::Title,
    PaperField::Abstract,
    PaperField::Year,
    PaperField::CitationCount,
];

§AuthorField

Use AuthorField to specify which author fields to request.

use ss_tools::structs::AuthorField;

let fields = vec![
    AuthorField::Name,
    AuthorField::PaperCount,
    AuthorField::CitationCount,
    AuthorField::HIndex,
];

§Response Structs

§AuthorSearchResponse

Response from searching authors by name.

use ss_tools::structs::AuthorSearchResponse;

// Contains offset, next, total, and data (Vec<Author>)
let response = AuthorSearchResponse::default();
assert!(response.data.is_empty());

§AuthorPapersResponse

Response from querying an author’s papers.

use ss_tools::structs::AuthorPapersResponse;

// Contains offset, next, and data (Vec<Paper>)
let response = AuthorPapersResponse::default();
assert!(response.data.is_empty());

§PaperAuthorsResponse

Response from querying a paper’s authors.

use ss_tools::structs::PaperAuthorsResponse;

// Contains offset, next, and data (Vec<Author>)
let response = PaperAuthorsResponse::default();
assert!(response.data.is_empty());