meta

package
v0.0.0-...-8476fb0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package arxivgo provides a simple interface to the arXiv metadata API.

ArXiv provides a public API for accessing metadata of scientific papers. Documentation for the API can be found in the ArXiv API User Manual.

Basic usage:

   package main
   import (
         "github.com/mikethicke/arxiv-go"
   )
   func main() {
         params := meta.SearchParams{
                 Query: "all:electron",
         }
         requester := meta.MakeRequester(arxivgo.DefaultConfig)
         response, err := meta.Search(requester, params)
         if err != nil {
                 panic(err)
         }
         for _, entry := range response.Entries {
				  // Do something
         }
         nextPage, err := meta.SearchNext(requester, response)
         // Do something
    }

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	BaseURL:          "http://export.arxiv.org/api/query",
	RequestMethod:    GET,
	Timeout:          10 * time.Second,
	RateLimit:        true,
	RateLimitSeconds: 3,
}

DefaultConfig provides a default configuration for making requests to the arXiv API. Note that ArXiv requires a delay of at least 3 seconds between requests.

Functions

func DoGetRequest

func DoGetRequest(client http.Client, config Config, params SearchParams) (*http.Response, error)

DoGetRequest makes a GET request to the arXiv API. It is normally called by the Requester.

func DoPostRequest

func DoPostRequest(client http.Client, config Config, params SearchParams) (*http.Response, error)

DoPostRequest makes a POST request to the arXiv API. It is normally called by the Requester.

func RawSearch

func RawSearch(requester Requester, params SearchParams) (*http.Response, error)

RawSearch makes a search request to the arXiv API using the provided Requester.

func SearchHasMoreResults

func SearchHasMoreResults(response SearchResponse) bool

SearchHasMoreResults returns true if there are more results available for the search query.

func SearchHasPreviousResults

func SearchHasPreviousResults(response SearchResponse) bool

SearchHasPreviousResults returns true if there are previous results available for the search query.

func SearchIter

func SearchIter(requester Requester, params SearchParams) iter.Seq[EntryMetadata]

Returns an iterator over the search results. The iterator will make multiple requests to the API as needed.

Types

type Author

type Author struct {
	Name        string `xml:"name"`
	Affiliation string `xml:"affiliation"`
}

Author contains information about an author of a paper.

type Category

type Category struct {
	Term string `xml:"term,attr"`
}

Category contains information about a subject category of a paper.

type Config

type Config struct {
	BaseURL          string        // Base URL for the arXiv API
	RequestMethod    RequestMethod // HTTP request method to use
	Timeout          time.Duration // Timeout for the HTTP request
	RateLimit        bool          // Whether to rate limit requests
	RateLimitSeconds int           // Number of seconds to wait between requests
}

Configuration for making requests to the arXiv API.

type EntryMetadata

type EntryMetadata struct {
	Title            string     `xml:"title"`            // Title of the entry.
	ID               string     `xml:"id"`               // ID of the entry, as a URL.
	Published        time.Time  `xml:"published"`        // Time the entry was published.
	Updated          time.Time  `xml:"updated"`          // Time the entry was last updated.
	Summary          string     `xml:"summary"`          // Summary (abstract) of the entry.
	Authors          []Author   `xml:"author"`           // Authors of the entry.
	Categories       []Category `xml:"category"`         // Subject categories of the entry.
	PrimaryCategory  Category   `xml:"primary_category"` // Primary subject category of the entry.
	Links            []Link     `xml:"link"`             // Links included in the entry. Includes link to the PDF.
	Comment          string     `xml:"comment"`          // Comment on the entry. Includes information such as where the paper was submitted or number of pages, figures, etc.
	JournalReference string     `xml:"journal_ref"`      // Journal reference for the entry.
	DOI              string     `xml:"doi"`              // Digital Object Identifier (DOI) for the entry.
}

EntryMetadata contains metadata for a single entry in the search response.

func ParseSingleEntry

func ParseSingleEntry(entryData io.Reader) (EntryMetadata, error)

ParseSingleEntry parses a single entry from the arXiv API.

type Link struct {
	Href  string `xml:"href,attr"`
	Rel   string `xml:"rel,attr"`
	Type  string `xml:"type,attr"`
	Title string `xml:"title,attr"`
}

Link contains information about a link associated with a paper.

type RequestMethod

type RequestMethod int

Request method for making API search requests. ArXiv's API supports GET or POST requests for search queries.

const (
	GET RequestMethod = iota
	POST
)

type Requester

type Requester func(SearchParams) (*http.Response, error)

Requester is a function that makes a search request to the arXiv API.

func MakeRequester

func MakeRequester(config Config) Requester

MakeRequester creates a Requester.

func MakeRequesterWithClient

func MakeRequesterWithClient(client http.Client, config Config) Requester

MakeRequesterWithClient creates a Requester with a custom http.Client.

type SearchParams

type SearchParams struct {
	Query      string
	IdList     []string
	Start      int
	MaxResults int
	SortBy     SortBy
	SortOrder  SortOrder
}

SearchParams contains parameters for making a search request to the arXiv API. See the arXiv API documentation for more information on the available parameters and constructing queries.

Note that MaxResults should be limited to 2000 and Start should be limited to 30000.

type SearchResponse

type SearchResponse struct {
	Links        []Link          `xml:"link"`         // Links included in the response. Includes link for current search.
	Title        string          `xml:"title"`        // Title of the search response, includes search query.
	ID           string          `xml:"id"`           // ID of the search response, as a URL.
	Updated      string          `xml:"updated"`      // Time the search response was updated (generally the time it was made).
	TotalResults int             `xml:"totalResults"` // Total number of results available for the search query.
	StartIndex   int             `xml:"startIndex"`   // Index of the first result returned in the current response.
	ItemsPerPage int             `xml:"itemsPerPage"` // Number of results returned in the current response.
	Entries      []EntryMetadata `xml:"entry"`        // Metadata for each entry in the search response.
	Params       SearchParams    // Parameters used to make the search request.
}

SearchResponse contains metadata for search results returned by the arXiv API. The Params field contains the parameters used to make the search request.

func ParseResponse

func ParseResponse(responseData io.Reader) (SearchResponse, error)

ParseResponse parses a search response from the arXiv API.

func Search(requester Requester, params SearchParams) (SearchResponse, error)

Search makes a search request to the arXiv API using the provided Requester and parses the response.

func SearchNext

func SearchNext(requester Requester, response SearchResponse) (SearchResponse, error)

SearchNext searches for the next page of results using the provided Requester and SearchResponse.

func SearchPrevious

func SearchPrevious(requester Requester, response SearchResponse) (SearchResponse, error)

SearchPrevious searches for the previous page of results using the provided Requester and SearchResponse.

type SortBy

type SortBy string

Possible ways to sort search results.

const (
	SortByRelevance       SortBy = "relevance"
	SortByLastUpdatedDate SortBy = "lastUpdatedDate"
	SortBySubmittedDate   SortBy = "submittedDate"
)

type SortOrder

type SortOrder string

Possible sort orders for search results.

const (
	SortOrderAscending  SortOrder = "ascending"
	SortOrderDescending SortOrder = "descending"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL