Crossref publication data

from alexandria3k.data_sources import crossref
class data_sources.crossref.Crossref(crossref_directory, sample=<function Crossref.<lambda>>, attach_databases=None)

Create an object containing Crossref meta-data that supports queries over its (virtual) tables and the population of an SQLite database with its data.

Parameters
  • crossref_directory (str) – The directory path where the Crossref data files are located

  • sample (callable, optional) – A callable to control container sampling, defaults to lambda n: True. The population or query method will call this argument for each Crossref container file with each container’s file name as its argument. When the callable returns True the container file will get processed, when it returns False the container will get skipped.

  • attach_databases (list, optional) – A list of colon-joined tuples specifying a database name and its path, defaults to None. The specified databases are attached and made available to the query and the population condition through the specified database name.

populate(database_path, columns=None, condition=None)

Populate the specified SQLite database using the data specified in the object constructor’s call. The database is created if it does not exist. If it exists, the tables to be populated are dropped (if they exist) and recreated anew as specified.

Parameters
  • database_path (str) – The path specifying the SQLite database to populate.

  • columns (list, optional) – A list of strings specifying the columns to populate, defaults to None. The strings are of the form table_name.column_name or table_name.*.

  • condition (str, optional) – SQL expression specifying the rows to include in the database’s population, defaults to None. The expression can contain references to the table’s columns, to tables in attached databases prefixed by their name, and tables in the database being populated prefixed by populated. Implicitly, if a main table is populated, its details tables will only get populated with the records associated with the corresponding main table’s record.

query(query, partition=False)

Run the specified query on the virtual database using the data specified in the object constructor’s call.

Parameters
  • query (str) – An SQL SELECT query specifying the required data.

  • partition (bool, optional) – When true the query will run separately in each container, defaults to False. Queries involving table joins will run substantially faster if access to each table’s records is restricted with an expression table_name.container_id = CONTAINER_ID, and the partition argument is set to true. In such a case the query is repeatedly run over each database partition (compressed JSON file) with CONTAINER_ID iterating sequentially to cover all partitions. The query’s result is the concatenation of the individual partition results. Running queries with joins without partitioning will often result in quadratic (or worse) algorithmic complexity.

Returns

An iterable over the query’s results.

Return type

iterable

Generated schema

CREATE TABLE works(
  id,
  container_id,
  doi,
  title,
  published_year,
  published_month,
  published_day,
  short_container_title,
  container_title,
  publisher,
  abstract,
  type,
  subtype,
  page,
  volume,
  article_number,
  journal_issue,
  issn_print,
  issn_electronic,
  update_count,
  references_count,
  is_referenced_by_count
);

CREATE TABLE work_authors(
  id,
  container_id,
  work_id,
  orcid,
  suffix,
  given,
  family,
  name,
  authenticated_orcid,
  prefix,
  sequence
);

CREATE TABLE author_affiliations(
  author_id,
  container_id,
  name
);

CREATE TABLE work_references(
  work_id,
  container_id,
  issn,
  standards_body,
  issue,
  key,
  series_title,
  isbn_type,
  doi_asserted_by,
  first_page,
  isbn,
  doi,
  component,
  article_title,
  volume_title,
  volume,
  author,
  standard_designator,
  year,
  unstructured,
  edition,
  journal_title,
  issn_type
);

CREATE TABLE work_updates(
  work_id,
  container_id,
  label,
  doi,
  timestamp
);

CREATE TABLE work_subjects(
  work_id,
  container_id,
  name
);

CREATE TABLE work_licenses(
  work_id,
  container_id,
  url,
  start_timestamp,
  delay_in_days
);

CREATE TABLE work_links(
  work_id,
  container_id,
  url,
  content_type
);

CREATE TABLE work_funders(
  id,
  container_id,
  work_id,
  doi,
  name
);

CREATE TABLE funder_awards(
  funder_id,
  container_id,
  name
);